add angular-round selector
This commit is contained in:
+26
-8
@@ -2,7 +2,11 @@
|
||||
"use strict";
|
||||
|
||||
const EXCLUDED_ANCESTORS = "head, script, style, noscript, template, textarea, select, option";
|
||||
const FONT_FAMILY = '"Glagolify Noto Sans Glagolitic"';
|
||||
const FONT_FAMILIES = Object.freeze({
|
||||
round: '"Glagolify Noto Sans Glagolitic"',
|
||||
angular: '"Glagolify Shafarik Angular"'
|
||||
});
|
||||
let fontFamily = FONT_FAMILIES.round;
|
||||
const trackedText = new Map();
|
||||
const styledElements = new Map();
|
||||
const observers = new Map();
|
||||
@@ -53,8 +57,19 @@
|
||||
|
||||
function appliedFontFamily(computedFamily) {
|
||||
return computedFamily
|
||||
? `${FONT_FAMILY}, ${computedFamily}`
|
||||
: `${FONT_FAMILY}, sans-serif`;
|
||||
? `${fontFamily}, ${computedFamily}`
|
||||
: `${fontFamily}, sans-serif`;
|
||||
}
|
||||
function setFontStyle(style) {
|
||||
const nextFontFamily = FONT_FAMILIES[style];
|
||||
if (!nextFontFamily || nextFontFamily === fontFamily) {
|
||||
return;
|
||||
}
|
||||
|
||||
fontFamily = nextFontFamily;
|
||||
for (const [element, record] of styledElements) {
|
||||
writeAppliedFont(element, record, record.pageComputedFamily);
|
||||
}
|
||||
}
|
||||
|
||||
function writeAppliedFont(element, record, computedFamily) {
|
||||
@@ -77,12 +92,13 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const computedFamily = getComputedStyle(element).fontFamily;
|
||||
const record = {
|
||||
pageValue: element.style.getPropertyValue("font-family"),
|
||||
pagePriority: element.style.getPropertyPriority("font-family"),
|
||||
pageComputedFamily: computedFamily,
|
||||
appliedValue: ""
|
||||
};
|
||||
const computedFamily = getComputedStyle(element).fontFamily;
|
||||
styledElements.set(element, record);
|
||||
writeAppliedFont(element, record, computedFamily);
|
||||
}
|
||||
@@ -101,7 +117,8 @@
|
||||
|
||||
record.pageValue = currentValue;
|
||||
record.pagePriority = currentPriority;
|
||||
writeAppliedFont(element, record, getComputedStyle(element).fontFamily);
|
||||
record.pageComputedFamily = getComputedStyle(element).fontFamily;
|
||||
writeAppliedFont(element, record, record.pageComputedFamily);
|
||||
}
|
||||
|
||||
function restoreFont(element, record) {
|
||||
@@ -301,7 +318,8 @@
|
||||
ownStyleMutationCounts = new WeakMap();
|
||||
}
|
||||
|
||||
function setEnabled(target) {
|
||||
function setEnabled(target, style) {
|
||||
setFontStyle(style);
|
||||
if (target) {
|
||||
enable();
|
||||
} else {
|
||||
@@ -314,12 +332,12 @@
|
||||
if (!message || message.type !== "glagolify:set-enabled" || typeof message.enabled !== "boolean") {
|
||||
return undefined;
|
||||
}
|
||||
return Promise.resolve(setEnabled(message.enabled));
|
||||
return Promise.resolve(setEnabled(message.enabled, message.fontStyle));
|
||||
});
|
||||
|
||||
browser.runtime.sendMessage({ type: "glagolify:document-ready" })
|
||||
.then((response) => {
|
||||
setEnabled(Boolean(response && response.enabled));
|
||||
setEnabled(Boolean(response && response.enabled), response && response.fontStyle);
|
||||
})
|
||||
.catch(() => {
|
||||
setEnabled(false);
|
||||
|
||||
Reference in New Issue
Block a user