code cosmetics
This commit is contained in:
parent
a6fdb49503
commit
7832c3c581
|
@ -55,7 +55,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function applyOnMessage(request, sender, sendResponse) {
|
function applyOnMessage(request, sender, sendResponse) {
|
||||||
if (request.styles === 'DIY') {
|
if (request.styles === 'DIY') {
|
||||||
// Do-It-Yourself tells our built-in pages to fetch the styles directly
|
// Do-It-Yourself tells our built-in pages to fetch the styles directly
|
||||||
|
@ -125,7 +124,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doDisableAll(disable = disableAll) {
|
function doDisableAll(disable = disableAll) {
|
||||||
if (!disable === !disableAll) {
|
if (!disable === !disableAll) {
|
||||||
return;
|
return;
|
||||||
|
@ -139,7 +137,6 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doExposeIframes(state = exposeIframes) {
|
function doExposeIframes(state = exposeIframes) {
|
||||||
if (state === exposeIframes || window === parent) {
|
if (state === exposeIframes || window === parent) {
|
||||||
return;
|
return;
|
||||||
|
@ -153,7 +150,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function applyStyleState({id, enabled}) {
|
function applyStyleState({id, enabled}) {
|
||||||
const inCache = disabledElements.get(id) || styleElements.get(id);
|
const inCache = disabledElements.get(id) || styleElements.get(id);
|
||||||
const inDoc = document.getElementById(ID_PREFIX + id);
|
const inDoc = document.getElementById(ID_PREFIX + id);
|
||||||
|
@ -174,7 +170,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function removeStyle({id, retire = false}) {
|
function removeStyle({id, retire = false}) {
|
||||||
const el = document.getElementById(ID_PREFIX + id);
|
const el = document.getElementById(ID_PREFIX + id);
|
||||||
if (el) {
|
if (el) {
|
||||||
|
@ -195,7 +190,6 @@
|
||||||
retiredStyleTimers.delete(id);
|
retiredStyleTimers.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function applyStyles(styles) {
|
function applyStyles(styles) {
|
||||||
if (!styles) {
|
if (!styles) {
|
||||||
// Chrome is starting up
|
// Chrome is starting up
|
||||||
|
@ -232,21 +226,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (styles.needTransitionPatch) {
|
if (styles.needTransitionPatch) {
|
||||||
// CSS transition bug workaround: since we insert styles asynchronously,
|
applyTransitionPatch();
|
||||||
// the browsers, especially Firefox, may apply all transitions on page load
|
|
||||||
delete styles.needTransitionPatch;
|
delete styles.needTransitionPatch;
|
||||||
const className = chrome.runtime.id + '-transition-bug-fix';
|
|
||||||
const docId = document.documentElement.id ? '#' + document.documentElement.id : '';
|
|
||||||
document.documentElement.classList.add(className);
|
|
||||||
applySections(0, `
|
|
||||||
${docId}.${className}:root * {
|
|
||||||
transition: none !important;
|
|
||||||
}
|
|
||||||
`);
|
|
||||||
setTimeout(() => {
|
|
||||||
removeStyle({id: 0});
|
|
||||||
document.documentElement.classList.remove(className);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gotNewStyles) {
|
if (gotNewStyles) {
|
||||||
|
@ -270,7 +251,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function applySections(styleId, code) {
|
function applySections(styleId, code) {
|
||||||
const id = ID_PREFIX + styleId;
|
const id = ID_PREFIX + styleId;
|
||||||
let el = styleElements.get(id) || document.getElementById(id);
|
let el = styleElements.get(id) || document.getElementById(id);
|
||||||
|
@ -299,7 +279,6 @@
|
||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function addStyleElement(newElement) {
|
function addStyleElement(newElement) {
|
||||||
if (!ROOT) {
|
if (!ROOT) {
|
||||||
return;
|
return;
|
||||||
|
@ -323,7 +302,6 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function replaceAll(newStyles) {
|
function replaceAll(newStyles) {
|
||||||
if ('disableAll' in newStyles &&
|
if ('disableAll' in newStyles &&
|
||||||
disableAll === newStyles.disableAll &&
|
disableAll === newStyles.disableAll &&
|
||||||
|
@ -346,12 +324,27 @@
|
||||||
oldStyles.forEach(el => el.remove()));
|
oldStyles.forEach(el => el.remove()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyTransitionPatch() {
|
||||||
|
// CSS transition bug workaround: since we insert styles asynchronously,
|
||||||
|
// the browsers, especially Firefox, may apply all transitions on page load
|
||||||
|
const className = chrome.runtime.id + '-transition-bug-fix';
|
||||||
|
const docId = document.documentElement.id ? '#' + document.documentElement.id : '';
|
||||||
|
document.documentElement.classList.add(className);
|
||||||
|
applySections(0, `
|
||||||
|
${docId}.${className}:root * {
|
||||||
|
transition: none !important;
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
setTimeout(() => {
|
||||||
|
removeStyle({id: 0});
|
||||||
|
document.documentElement.classList.remove(className);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getStyleId(el) {
|
function getStyleId(el) {
|
||||||
return parseInt(el.id.substr(ID_PREFIX.length));
|
return parseInt(el.id.substr(ID_PREFIX.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function countStylesInHash(styleHash) {
|
function countStylesInHash(styleHash) {
|
||||||
let num = 0;
|
let num = 0;
|
||||||
for (const k in styleHash) {
|
for (const k in styleHash) {
|
||||||
|
@ -370,7 +363,6 @@
|
||||||
window.removeEventListener(chrome.runtime.id, orphanCheck, true);
|
window.removeEventListener(chrome.runtime.id, orphanCheck, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function initDocRewriteObserver() {
|
function initDocRewriteObserver() {
|
||||||
// detect documentElement being rewritten from inside the script
|
// detect documentElement being rewritten from inside the script
|
||||||
docRewriteObserver = new MutationObserver(mutations => {
|
docRewriteObserver = new MutationObserver(mutations => {
|
||||||
|
@ -411,7 +403,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function initDocRootObserver() {
|
function initDocRootObserver() {
|
||||||
let lastRestorationTime = 0;
|
let lastRestorationTime = 0;
|
||||||
let restorationCounter = 0;
|
let restorationCounter = 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user