Fix: firefox

This commit is contained in:
eight 2018-10-11 23:39:11 +08:00
parent 5cfea3933f
commit a57b3b2716

View File

@ -37,7 +37,7 @@ const APPLY = (() => {
if (!isOwnPage) { if (!isOwnPage) {
window.dispatchEvent(new CustomEvent(chrome.runtime.id, { window.dispatchEvent(new CustomEvent(chrome.runtime.id, {
detail: {method: 'orphan'} detail: pageObject({method: 'orphan'})
})); }));
window.addEventListener(chrome.runtime.id, orphanCheck, true); window.addEventListener(chrome.runtime.id, orphanCheck, true);
} }
@ -52,6 +52,13 @@ const APPLY = (() => {
const setStyleContent = createSetStyleContent(); const setStyleContent = createSetStyleContent();
function pageObject(target) {
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts
const obj = new window.Object();
Object.assign(obj, target);
return obj;
}
function createSetStyleContent() { function createSetStyleContent() {
// FF59+ bug workaround // FF59+ bug workaround
// See https://github.com/openstyles/stylus/issues/461 // See https://github.com/openstyles/stylus/issues/461
@ -66,11 +73,12 @@ const APPLY = (() => {
}; };
} }
return (el, content) => { return (el, content) => {
window.dispatchEvent(EVENT_NAME, new CustomEvent({detail: { const detail = pageObject({
method: 'setStyleContent', method: 'setStyleContent',
id: el.id, id: el.id,
content content
}})); });
window.dispatchEvent(new CustomEvent(EVENT_NAME, {detail}));
}; };
function injectPageScript() { function injectPageScript() {
@ -416,14 +424,15 @@ const APPLY = (() => {
const docId = document.documentElement.id ? '#' + document.documentElement.id : ''; const docId = document.documentElement.id ? '#' + document.documentElement.id : '';
document.documentElement.classList.add(className); document.documentElement.classList.add(className);
applySections(0, ` applySections(0, `
${docId}.${className}:root * { ${docId}.${CSS.escape(className)}:root * {
transition: none !important; transition: none !important;
} }
`); `);
setTimeout(() => { // repaint
removeStyle({id: 0}); // eslint-disable-next-line no-unused-expressions
document.documentElement.classList.remove(className); document.documentElement.offsetWidth;
}); removeStyle({id: 0});
document.documentElement.classList.remove(className);
} }
function getStyleId(el) { function getStyleId(el) {