From 88cde6bfdc0f59c5b72ef20d900d939b94a2a449 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 13 Apr 2018 22:54:28 -0400 Subject: [PATCH] formatting js files. remove old u2f --- src/content/autofiller.js | 8 ++-- src/content/notificationBar.js | 43 ++++++++------------ src/notification/bar.js | 22 +++++----- src/scripts/u2f.ts | 73 ---------------------------------- 4 files changed, 29 insertions(+), 117 deletions(-) delete mode 100644 src/scripts/u2f.ts diff --git a/src/content/autofiller.js b/src/content/autofiller.js index d7711b5d37..1d160ad30d 100644 --- a/src/content/autofiller.js +++ b/src/content/autofiller.js @@ -8,15 +8,14 @@ document.addEventListener('DOMContentLoaded', (event) => { command: 'bgGetDataForTab', responseCommand: responseCommand }); - safari.self.addEventListener('message', function (msgEvent) { + safari.self.addEventListener('message', (msgEvent) => { const msg = msgEvent.message; if (msg.command === responseCommand && msg.data.autofillEnabled === true) { setInterval(doFillIfNeeded, 500); } }, false); return; - } - else { + } else { const enabledKey = 'enableAutoFillOnPageLoad'; chrome.storage.local.get(enabledKey, (obj) => { if (obj && obj[enabledKey] === true) { @@ -35,8 +34,7 @@ document.addEventListener('DOMContentLoaded', (event) => { if ((typeof safari !== 'undefined')) { safari.self.tab.dispatchMessage('bitwarden', msg); - } - else { + } else { chrome.runtime.sendMessage(msg); } } diff --git a/src/content/notificationBar.js b/src/content/notificationBar.js index 8785b06028..9badba08a4 100644 --- a/src/content/notificationBar.js +++ b/src/content/notificationBar.js @@ -1,4 +1,4 @@ -document.addEventListener('DOMContentLoaded', function (event) { +document.addEventListener('DOMContentLoaded', (event) => { if (window.location.hostname.indexOf('vault.bitwarden.com') > -1) { return; } @@ -23,7 +23,7 @@ document.addEventListener('DOMContentLoaded', function (event) { command: 'bgGetDataForTab', responseCommand: responseCommand }); - safari.self.addEventListener('message', function (msgEvent) { + safari.self.addEventListener('message', (msgEvent) => { const msg = msgEvent.message; if (msg.command === responseCommand && msg.data) { notificationBarData = msg.data; @@ -40,25 +40,24 @@ document.addEventListener('DOMContentLoaded', function (event) { return; } - processMessages(msg, function () { /* do nothing on send response for Safari */ }); + processMessages(msg, () => { /* do nothing on send response for Safari */ }); }, false); return; - } - else { - chrome.storage.local.get('neverDomains', function (obj) { + } else { + chrome.storage.local.get('neverDomains', (obj) => { var domains = obj.neverDomains; if (domains && domains.hasOwnProperty(window.location.hostname)) { return; } - chrome.storage.local.get('disableAddLoginNotification', function (obj) { + chrome.storage.local.get('disableAddLoginNotification', (obj) => { if (!obj || !obj.disableAddLoginNotification) { collectIfNeededWithTimeout(); } }); }); - chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { + chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { processMessages(msg, sendResponse); }); } @@ -71,24 +70,21 @@ document.addEventListener('DOMContentLoaded', function (event) { closeExistingAndOpenBar(msg.data.type, msg.data.typeData); sendResponse(); return true; - } - else if (msg.command === 'closeNotificationBar') { + } else if (msg.command === 'closeNotificationBar') { if (iframed) { return; } closeBar(true); sendResponse(); return true; - } - else if (msg.command === 'adjustNotificationBar') { + } else if (msg.command === 'adjustNotificationBar') { if (iframed) { return; } adjustBar(msg.data); sendResponse(); return true; - } - else if (msg.command === 'notificationBarPageDetails') { + } else if (msg.command === 'notificationBarPageDetails') { pageDetails.push(msg.data.details); watchForms(msg.data.forms); sendResponse(); @@ -99,8 +95,7 @@ document.addEventListener('DOMContentLoaded', function (event) { function isIframed() { try { return window.self !== window.top; - } - catch (e) { + } catch (e) { return true; } } @@ -108,7 +103,7 @@ document.addEventListener('DOMContentLoaded', function (event) { function observeDom() { var bodies = document.querySelectorAll('body'); if (bodies && bodies.length > 0) { - observer = new window.MutationObserver(function (mutations) { + observer = new window.MutationObserver((mutations) => { if (!mutations || !mutations.length || pageHref !== window.location.href) { return; } @@ -237,8 +232,7 @@ document.addEventListener('DOMContentLoaded', function (event) { if (submitButton) { submitButton.removeEventListener('click', formSubmitted, false); submitButton.addEventListener('click', formSubmitted, false); - } - else { + } else { var possibleSubmitButtons = form.querySelectorAll('a, span, button[type="button"], input[type="button"]'); for (var i = 0; i < possibleSubmitButtons.length; i++) { var button = possibleSubmitButtons[i]; @@ -249,8 +243,7 @@ document.addEventListener('DOMContentLoaded', function (event) { var buttonText; if (button.tagName.toLowerCase() === 'input') { buttonText = button.value; - } - else { + } else { buttonText = button.innerText; } @@ -311,8 +304,7 @@ document.addEventListener('DOMContentLoaded', function (event) { var form = null; if (e.type === 'click') { form = e.target.closest('form'); - } - else { + } else { form = e.target; } @@ -334,7 +326,7 @@ document.addEventListener('DOMContentLoaded', function (event) { if (login.username && login.username !== '' && login.password && login.password !== '') { form.dataset.bitwardenProcessed = '1'; - setTimeout(function () { + setTimeout(() => { form.dataset.bitwardenProcessed = '0'; }, 500); @@ -451,8 +443,7 @@ document.addEventListener('DOMContentLoaded', function (event) { function sendPlatformMessage(msg) { if (isSafari) { safari.self.tab.dispatchMessage('bitwarden', msg); - } - else { + } else { chrome.runtime.sendMessage(msg); } } diff --git a/src/notification/bar.js b/src/notification/bar.js index 086aefe4e1..4dfca0a66f 100644 --- a/src/notification/bar.js +++ b/src/notification/bar.js @@ -1,6 +1,6 @@ require('./bar.scss'); -document.addEventListener('DOMContentLoaded', function () { +document.addEventListener('DOMContentLoaded', () => { var i18n = {}; if (typeof safari !== 'undefined') { const responseCommand = 'notificationBarFrameDataResponse'; @@ -8,15 +8,14 @@ document.addEventListener('DOMContentLoaded', function () { command: 'bgGetDataForTab', responseCommand: responseCommand }); - safari.self.addEventListener('message', function (msgEvent) { + safari.self.addEventListener('message', (msgEvent) => { const msg = msgEvent.message; if (msg.command === responseCommand && msg.data) { i18n = msg.data.i18n; load(); } }, false); - } - else { + } else { i18n.appName = chrome.i18n.getMessage('appName'); i18n.close = chrome.i18n.getMessage('close'); i18n.yes = chrome.i18n.getMessage('yes'); @@ -43,8 +42,7 @@ document.addEventListener('DOMContentLoaded', function () { if (bodyRect.width < 768) { document.querySelector('#template-add .add-save').textContent = i18n.yes; document.querySelector('#template-add .never-save').textContent = i18n.never; - } - else { + } else { document.querySelector('#template-add .add-save').textContent = i18n.notificationAddSave; document.querySelector('#template-add .never-save').textContent = i18n.notificationNeverSave; } @@ -57,26 +55,25 @@ document.addEventListener('DOMContentLoaded', function () { var addButton = document.querySelector('#template-add-clone .add-save'), neverButton = document.querySelector('#template-add-clone .never-save'); - addButton.addEventListener('click', function (e) { + addButton.addEventListener('click', (e) => { e.preventDefault(); sendPlatformMessage({ command: 'bgAddSave' }); }); - neverButton.addEventListener('click', function (e) { + neverButton.addEventListener('click', (e) => { e.preventDefault(); sendPlatformMessage({ command: 'bgNeverSave' }); }); - } - else if (getQueryVariable('info')) { + } else if (getQueryVariable('info')) { setContent(document.getElementById('template-alert')); document.getElementById('template-alert-clone').textContent = getQueryVariable('info'); } - closeButton.addEventListener('click', function (e) { + closeButton.addEventListener('click', (e) => { e.preventDefault(); sendPlatformMessage({ command: 'bgCloseNotificationBar' @@ -119,8 +116,7 @@ document.addEventListener('DOMContentLoaded', function () { function sendPlatformMessage(msg) { if (typeof safari !== 'undefined') { safari.self.tab.dispatchMessage('bitwarden', msg); - } - else { + } else { chrome.runtime.sendMessage(msg); } } diff --git a/src/scripts/u2f.ts b/src/scripts/u2f.ts deleted file mode 100644 index cb1696c62f..0000000000 --- a/src/scripts/u2f.ts +++ /dev/null @@ -1,73 +0,0 @@ -export class U2f { - private iframe: HTMLIFrameElement = null; - private connectorLink: HTMLAnchorElement; - - constructor(private win: Window, private webVaultUrl: string, private successCallback: Function, - private errorCallback: Function, private infoCallback: Function) { - this.connectorLink = win.document.createElement('a'); - this.webVaultUrl = webVaultUrl != null && webVaultUrl !== '' ? webVaultUrl : 'https://vault.bitwarden.com'; - } - - init(data: any): void { - this.connectorLink.href = this.webVaultUrl + '/u2f-connector.html' + - '?data=' + this.base64Encode(JSON.stringify(data)) + - '&parent=' + encodeURIComponent(this.win.document.location.href) + - '&v=1'; - - this.iframe = this.win.document.getElementById('u2f_iframe') as HTMLIFrameElement; - this.iframe.src = this.connectorLink.href; - - this.win.addEventListener('message', (e) => this.parseMessage(e), false); - } - - stop() { - this.sendMessage('stop'); - } - - start() { - this.sendMessage('start'); - } - - sendMessage(message: any) { - if (!this.iframe || !this.iframe.src || !this.iframe.contentWindow) { - return; - } - - this.iframe.contentWindow.postMessage(message, this.iframe.src); - } - - base64Encode(str: string): string { - return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, (match, p1) => { - return String.fromCharCode(('0x' + p1) as any); - })); - } - - cleanup() { - this.win.removeEventListener('message', (e) => this.parseMessage(e), false); - } - - private parseMessage(event: any) { - if (!this.validMessage(event)) { - this.errorCallback('Invalid message.'); - return; - } - - const parts: string[] = event.data.split('|'); - if (parts[0] === 'success' && this.successCallback) { - this.successCallback(parts[1]); - } else if (parts[0] === 'error' && this.errorCallback) { - this.errorCallback(parts[1]); - } else if (parts[0] === 'info' && this.infoCallback) { - this.infoCallback(parts[1]); - } - } - - private validMessage(event: any) { - if (!event.origin || event.origin === '' || event.origin !== (this.connectorLink as any).origin) { - return false; - } - - return event.data.indexOf('success|') === 0 || event.data.indexOf('error|') === 0 || - event.data.indexOf('info|') === 0; - } -}