bitwarden-estensione-browser/apps/browser/src/content/autofiller.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.5 KiB
TypeScript
Raw Normal View History

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;
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) => {
if (obj?.[activeUserId]?.settings?.enableAutoFillOnPageLoad === true) {
setInterval(() => doFillIfNeeded(), 500);
2020-12-11 16:13:50 +01:00
}
});
2022-02-24 18:14:04 +01:00
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.command === "fillForm" && pageHref === msg.url) {
filledThisHref = true;
}
});
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);
}
pageHref = window.location.href;
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
};
chrome.runtime.sendMessage(msg);
}
2021-12-21 15:43:35 +01:00
}
});