2017-11-11 05:52:29 +01:00
|
|
|
document.addEventListener('DOMContentLoaded', (event) => {
|
2018-05-09 20:00:13 +02:00
|
|
|
let pageHref: string = null;
|
2018-05-18 23:05:46 +02:00
|
|
|
let filledThisHref = false;
|
|
|
|
let delayFillTimeout: number;
|
|
|
|
|
2021-02-03 20:36:05 +01:00
|
|
|
const enabledKey = 'enableAutoFillOnPageLoad';
|
|
|
|
chrome.storage.local.get(enabledKey, (obj: any) => {
|
|
|
|
if (obj != null && obj[enabledKey] === true) {
|
|
|
|
setInterval(() => doFillIfNeeded(), 500);
|
2020-12-11 16:13:50 +01:00
|
|
|
}
|
2021-02-03 20:36:05 +01:00
|
|
|
});
|
|
|
|
chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: Function) => {
|
|
|
|
if (msg.command === 'fillForm' && pageHref === msg.url) {
|
|
|
|
filledThisHref = true;
|
|
|
|
}
|
|
|
|
});
|
2017-08-28 19:00:46 +02:00
|
|
|
|
2018-05-18 23:05:46 +02:00
|
|
|
function doFillIfNeeded(force: boolean = false) {
|
|
|
|
if (force || pageHref !== window.location.href) {
|
|
|
|
if (!force) {
|
|
|
|
// Some websites are slow and rendering all page content. Try to fill again later
|
|
|
|
// if we haven't already.
|
|
|
|
filledThisHref = false;
|
|
|
|
if (delayFillTimeout != null) {
|
|
|
|
window.clearTimeout(delayFillTimeout);
|
|
|
|
}
|
|
|
|
delayFillTimeout = window.setTimeout(() => {
|
|
|
|
if (!filledThisHref) {
|
|
|
|
doFillIfNeeded(true);
|
|
|
|
}
|
|
|
|
}, 1500);
|
|
|
|
}
|
|
|
|
|
2017-10-06 04:30:46 +02:00
|
|
|
pageHref = window.location.href;
|
2018-09-27 17:07:17 +02:00
|
|
|
const msg: any = {
|
2017-11-11 05:52:29 +01:00
|
|
|
command: 'bgCollectPageDetails',
|
2018-05-09 20:00:13 +02:00
|
|
|
sender: 'autofiller',
|
2018-01-13 04:11:18 +01:00
|
|
|
};
|
|
|
|
|
2021-02-03 20:36:05 +01:00
|
|
|
chrome.runtime.sendMessage(msg);
|
2017-10-06 04:30:46 +02:00
|
|
|
}
|
|
|
|
}
|
2017-08-28 19:00:46 +02:00
|
|
|
});
|