formatting js files. remove old u2f
This commit is contained in:
parent
5c9618b0a8
commit
88cde6bfdc
|
@ -8,15 +8,14 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
command: 'bgGetDataForTab',
|
command: 'bgGetDataForTab',
|
||||||
responseCommand: responseCommand
|
responseCommand: responseCommand
|
||||||
});
|
});
|
||||||
safari.self.addEventListener('message', function (msgEvent) {
|
safari.self.addEventListener('message', (msgEvent) => {
|
||||||
const msg = msgEvent.message;
|
const msg = msgEvent.message;
|
||||||
if (msg.command === responseCommand && msg.data.autofillEnabled === true) {
|
if (msg.command === responseCommand && msg.data.autofillEnabled === true) {
|
||||||
setInterval(doFillIfNeeded, 500);
|
setInterval(doFillIfNeeded, 500);
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
const enabledKey = 'enableAutoFillOnPageLoad';
|
const enabledKey = 'enableAutoFillOnPageLoad';
|
||||||
chrome.storage.local.get(enabledKey, (obj) => {
|
chrome.storage.local.get(enabledKey, (obj) => {
|
||||||
if (obj && obj[enabledKey] === true) {
|
if (obj && obj[enabledKey] === true) {
|
||||||
|
@ -35,8 +34,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
|
|
||||||
if ((typeof safari !== 'undefined')) {
|
if ((typeof safari !== 'undefined')) {
|
||||||
safari.self.tab.dispatchMessage('bitwarden', msg);
|
safari.self.tab.dispatchMessage('bitwarden', msg);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
chrome.runtime.sendMessage(msg);
|
chrome.runtime.sendMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
document.addEventListener('DOMContentLoaded', function (event) {
|
document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
if (window.location.hostname.indexOf('vault.bitwarden.com') > -1) {
|
if (window.location.hostname.indexOf('vault.bitwarden.com') > -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
command: 'bgGetDataForTab',
|
command: 'bgGetDataForTab',
|
||||||
responseCommand: responseCommand
|
responseCommand: responseCommand
|
||||||
});
|
});
|
||||||
safari.self.addEventListener('message', function (msgEvent) {
|
safari.self.addEventListener('message', (msgEvent) => {
|
||||||
const msg = msgEvent.message;
|
const msg = msgEvent.message;
|
||||||
if (msg.command === responseCommand && msg.data) {
|
if (msg.command === responseCommand && msg.data) {
|
||||||
notificationBarData = msg.data;
|
notificationBarData = msg.data;
|
||||||
|
@ -40,25 +40,24 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessages(msg, function () { /* do nothing on send response for Safari */ });
|
processMessages(msg, () => { /* do nothing on send response for Safari */ });
|
||||||
}, false);
|
}, false);
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else {
|
chrome.storage.local.get('neverDomains', (obj) => {
|
||||||
chrome.storage.local.get('neverDomains', function (obj) {
|
|
||||||
var domains = obj.neverDomains;
|
var domains = obj.neverDomains;
|
||||||
if (domains && domains.hasOwnProperty(window.location.hostname)) {
|
if (domains && domains.hasOwnProperty(window.location.hostname)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.storage.local.get('disableAddLoginNotification', function (obj) {
|
chrome.storage.local.get('disableAddLoginNotification', (obj) => {
|
||||||
if (!obj || !obj.disableAddLoginNotification) {
|
if (!obj || !obj.disableAddLoginNotification) {
|
||||||
collectIfNeededWithTimeout();
|
collectIfNeededWithTimeout();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
||||||
processMessages(msg, sendResponse);
|
processMessages(msg, sendResponse);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -71,24 +70,21 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
closeExistingAndOpenBar(msg.data.type, msg.data.typeData);
|
closeExistingAndOpenBar(msg.data.type, msg.data.typeData);
|
||||||
sendResponse();
|
sendResponse();
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (msg.command === 'closeNotificationBar') {
|
||||||
else if (msg.command === 'closeNotificationBar') {
|
|
||||||
if (iframed) {
|
if (iframed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
closeBar(true);
|
closeBar(true);
|
||||||
sendResponse();
|
sendResponse();
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (msg.command === 'adjustNotificationBar') {
|
||||||
else if (msg.command === 'adjustNotificationBar') {
|
|
||||||
if (iframed) {
|
if (iframed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
adjustBar(msg.data);
|
adjustBar(msg.data);
|
||||||
sendResponse();
|
sendResponse();
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (msg.command === 'notificationBarPageDetails') {
|
||||||
else if (msg.command === 'notificationBarPageDetails') {
|
|
||||||
pageDetails.push(msg.data.details);
|
pageDetails.push(msg.data.details);
|
||||||
watchForms(msg.data.forms);
|
watchForms(msg.data.forms);
|
||||||
sendResponse();
|
sendResponse();
|
||||||
|
@ -99,8 +95,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
function isIframed() {
|
function isIframed() {
|
||||||
try {
|
try {
|
||||||
return window.self !== window.top;
|
return window.self !== window.top;
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +103,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
function observeDom() {
|
function observeDom() {
|
||||||
var bodies = document.querySelectorAll('body');
|
var bodies = document.querySelectorAll('body');
|
||||||
if (bodies && bodies.length > 0) {
|
if (bodies && bodies.length > 0) {
|
||||||
observer = new window.MutationObserver(function (mutations) {
|
observer = new window.MutationObserver((mutations) => {
|
||||||
if (!mutations || !mutations.length || pageHref !== window.location.href) {
|
if (!mutations || !mutations.length || pageHref !== window.location.href) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -237,8 +232,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
if (submitButton) {
|
if (submitButton) {
|
||||||
submitButton.removeEventListener('click', formSubmitted, false);
|
submitButton.removeEventListener('click', formSubmitted, false);
|
||||||
submitButton.addEventListener('click', formSubmitted, false);
|
submitButton.addEventListener('click', formSubmitted, false);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
var possibleSubmitButtons = form.querySelectorAll('a, span, button[type="button"], input[type="button"]');
|
var possibleSubmitButtons = form.querySelectorAll('a, span, button[type="button"], input[type="button"]');
|
||||||
for (var i = 0; i < possibleSubmitButtons.length; i++) {
|
for (var i = 0; i < possibleSubmitButtons.length; i++) {
|
||||||
var button = possibleSubmitButtons[i];
|
var button = possibleSubmitButtons[i];
|
||||||
|
@ -249,8 +243,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
var buttonText;
|
var buttonText;
|
||||||
if (button.tagName.toLowerCase() === 'input') {
|
if (button.tagName.toLowerCase() === 'input') {
|
||||||
buttonText = button.value;
|
buttonText = button.value;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
buttonText = button.innerText;
|
buttonText = button.innerText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,8 +304,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
var form = null;
|
var form = null;
|
||||||
if (e.type === 'click') {
|
if (e.type === 'click') {
|
||||||
form = e.target.closest('form');
|
form = e.target.closest('form');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
form = e.target;
|
form = e.target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +326,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
|
|
||||||
if (login.username && login.username !== '' && login.password && login.password !== '') {
|
if (login.username && login.username !== '' && login.password && login.password !== '') {
|
||||||
form.dataset.bitwardenProcessed = '1';
|
form.dataset.bitwardenProcessed = '1';
|
||||||
setTimeout(function () {
|
setTimeout(() => {
|
||||||
form.dataset.bitwardenProcessed = '0';
|
form.dataset.bitwardenProcessed = '0';
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
@ -451,8 +443,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
function sendPlatformMessage(msg) {
|
function sendPlatformMessage(msg) {
|
||||||
if (isSafari) {
|
if (isSafari) {
|
||||||
safari.self.tab.dispatchMessage('bitwarden', msg);
|
safari.self.tab.dispatchMessage('bitwarden', msg);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
chrome.runtime.sendMessage(msg);
|
chrome.runtime.sendMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
require('./bar.scss');
|
require('./bar.scss');
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
var i18n = {};
|
var i18n = {};
|
||||||
if (typeof safari !== 'undefined') {
|
if (typeof safari !== 'undefined') {
|
||||||
const responseCommand = 'notificationBarFrameDataResponse';
|
const responseCommand = 'notificationBarFrameDataResponse';
|
||||||
|
@ -8,15 +8,14 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||||
command: 'bgGetDataForTab',
|
command: 'bgGetDataForTab',
|
||||||
responseCommand: responseCommand
|
responseCommand: responseCommand
|
||||||
});
|
});
|
||||||
safari.self.addEventListener('message', function (msgEvent) {
|
safari.self.addEventListener('message', (msgEvent) => {
|
||||||
const msg = msgEvent.message;
|
const msg = msgEvent.message;
|
||||||
if (msg.command === responseCommand && msg.data) {
|
if (msg.command === responseCommand && msg.data) {
|
||||||
i18n = msg.data.i18n;
|
i18n = msg.data.i18n;
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i18n.appName = chrome.i18n.getMessage('appName');
|
i18n.appName = chrome.i18n.getMessage('appName');
|
||||||
i18n.close = chrome.i18n.getMessage('close');
|
i18n.close = chrome.i18n.getMessage('close');
|
||||||
i18n.yes = chrome.i18n.getMessage('yes');
|
i18n.yes = chrome.i18n.getMessage('yes');
|
||||||
|
@ -43,8 +42,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||||
if (bodyRect.width < 768) {
|
if (bodyRect.width < 768) {
|
||||||
document.querySelector('#template-add .add-save').textContent = i18n.yes;
|
document.querySelector('#template-add .add-save').textContent = i18n.yes;
|
||||||
document.querySelector('#template-add .never-save').textContent = i18n.never;
|
document.querySelector('#template-add .never-save').textContent = i18n.never;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
document.querySelector('#template-add .add-save').textContent = i18n.notificationAddSave;
|
document.querySelector('#template-add .add-save').textContent = i18n.notificationAddSave;
|
||||||
document.querySelector('#template-add .never-save').textContent = i18n.notificationNeverSave;
|
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'),
|
var addButton = document.querySelector('#template-add-clone .add-save'),
|
||||||
neverButton = document.querySelector('#template-add-clone .never-save');
|
neverButton = document.querySelector('#template-add-clone .never-save');
|
||||||
|
|
||||||
addButton.addEventListener('click', function (e) {
|
addButton.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
sendPlatformMessage({
|
sendPlatformMessage({
|
||||||
command: 'bgAddSave'
|
command: 'bgAddSave'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
neverButton.addEventListener('click', function (e) {
|
neverButton.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
sendPlatformMessage({
|
sendPlatformMessage({
|
||||||
command: 'bgNeverSave'
|
command: 'bgNeverSave'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
} else if (getQueryVariable('info')) {
|
||||||
else if (getQueryVariable('info')) {
|
|
||||||
setContent(document.getElementById('template-alert'));
|
setContent(document.getElementById('template-alert'));
|
||||||
document.getElementById('template-alert-clone').textContent = getQueryVariable('info');
|
document.getElementById('template-alert-clone').textContent = getQueryVariable('info');
|
||||||
}
|
}
|
||||||
|
|
||||||
closeButton.addEventListener('click', function (e) {
|
closeButton.addEventListener('click', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
sendPlatformMessage({
|
sendPlatformMessage({
|
||||||
command: 'bgCloseNotificationBar'
|
command: 'bgCloseNotificationBar'
|
||||||
|
@ -119,8 +116,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||||
function sendPlatformMessage(msg) {
|
function sendPlatformMessage(msg) {
|
||||||
if (typeof safari !== 'undefined') {
|
if (typeof safari !== 'undefined') {
|
||||||
safari.self.tab.dispatchMessage('bitwarden', msg);
|
safari.self.tab.dispatchMessage('bitwarden', msg);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
chrome.runtime.sendMessage(msg);
|
chrome.runtime.sendMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue