-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
24 lines (21 loc) · 714 Bytes
/
script.js
File metadata and controls
24 lines (21 loc) · 714 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
async function insertStyle() {
const options = await chrome.storage.sync.get("rules");
if (!options.rules) return;
let styles = "";
for (const rule of options.rules) {
if (rule["enable"]) {
for (const local of rule["locals"]) {
styles += `@font-face{font-family:'${rule["source"]}';src:local('${local.fullName}');`
+ `font-weight:${local.weight};font-style:${local.style};}`;
}
}
}
document.head.insertAdjacentHTML("beforeend", `<style id="fontswap">${styles}</style>`);
};
const observer = new MutationObserver(() => {
if (document.head) {
insertStyle();
observer.disconnect();
}
});
observer.observe(document, { childList: true, subtree: true });