1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00

convert some content scripts to ts

This commit is contained in:
Kyle Spearrin
2018-05-09 14:00:13 -04:00
parent 4fe710f8e7
commit 898fa7a095
4 changed files with 458 additions and 458 deletions

43
src/content/autofiller.ts Normal file
View File

@@ -0,0 +1,43 @@
document.addEventListener('DOMContentLoaded', (event) => {
let pageHref: string = null;
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1;
if (isSafari) {
const responseCommand = 'autofillerAutofillOnPageLoadEnabledResponse';
safari.self.tab.dispatchMessage('bitwarden', {
command: 'bgGetDataForTab',
responseCommand: responseCommand,
});
safari.self.addEventListener('message', (msgEvent: any) => {
const msg = msgEvent.message;
if (msg.command === responseCommand && msg.data.autofillEnabled === true) {
setInterval(doFillIfNeeded, 500);
}
}, false);
return;
} else {
const enabledKey = 'enableAutoFillOnPageLoad';
chrome.storage.local.get(enabledKey, (obj: any) => {
if (obj != null && obj[enabledKey] === true) {
setInterval(doFillIfNeeded, 500);
}
});
}
function doFillIfNeeded() {
if (pageHref !== window.location.href) {
pageHref = window.location.href;
const msg = {
command: 'bgCollectPageDetails',
sender: 'autofiller',
};
if (isSafari) {
safari.self.tab.dispatchMessage('bitwarden', msg);
} else {
chrome.runtime.sendMessage(msg);
}
}
}
});