code cosmetics

This commit is contained in:
tophf 2017-12-09 21:30:00 +03:00
parent a6fdb49503
commit 7832c3c581

View File

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