2021-02-10 16:40:15 +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;
|
|
|
|
|
2022-02-07 17:40:27 +01:00
|
|
|
const activeUserIdKey = "activeUserId";
|
|
|
|
let activeUserId: string;
|
|
|
|
|
|
|
|
chrome.storage.local.get(activeUserIdKey, (obj: any) => {
|
|
|
|
if (obj == null || obj[activeUserIdKey] == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
activeUserId = obj[activeUserIdKey];
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.storage.local.get(activeUserId, (obj: any) => {
|
2022-02-15 16:11:44 +01:00
|
|
|
if (obj?.[activeUserId]?.settings?.enableAutoFillOnPageLoad === true) {
|
2021-02-03 20:36:05 +01:00
|
|
|
setInterval(() => doFillIfNeeded(), 500);
|
2020-12-11 16:13:50 +01:00
|
|
|
}
|
2021-02-03 20:36:05 +01:00
|
|
|
});
|
2022-02-24 18:14:04 +01:00
|
|
|
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
2021-02-03 20:36:05 +01:00
|
|
|
if (msg.command === "fillForm" && pageHref === msg.url) {
|
|
|
|
filledThisHref = true;
|
|
|
|
}
|
|
|
|
});
|
2017-08-28 19:00:46 +02:00
|
|
|
|
2022-02-24 18:14:04 +01:00
|
|
|
function doFillIfNeeded(force = false) {
|
2018-05-18 23:05:46 +02:00
|
|
|
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
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2017-08-28 19:00:46 +02:00
|
|
|
});
|