Fix: minor

This commit is contained in:
eight 2019-02-03 18:38:57 +08:00
parent 6964e0f9fa
commit 5a21c72040
3 changed files with 12 additions and 6 deletions

View File

@ -332,7 +332,7 @@ const APPLY = (() => {
return rootReady().then(() =>
docRootObserver.evade(() =>
styleInjector.addMany(
Object.values.map(s => ({id: s.id, code: s.code.join('')}))
Object.values(sections).map(s => ({id: s.id, code: s.code.join('')}))
)
)
);
@ -375,8 +375,7 @@ const APPLY = (() => {
}
// In Chrome content script is orphaned on an extension update/reload
// so we need to detach event listeners
docRewriteObserver.stop();
docRootObserver.stop();
styleInjector.clear();
window.removeEventListener(chrome.runtime.id, orphanCheck, true);
try {
msg.off(applyOnMessage);

View File

@ -69,10 +69,10 @@ function createStyleInjector({compare, setStyleContent, onUpdate}) {
style.el = createStyle(style.id);
const pending = setStyleContent(style.el, style.code);
table.set(style.id, style);
const nextIndex = list.findIndex(i => compare(style, i) > 0);
const nextIndex = list.findIndex(i => compare(i, style) > 0);
if (nextIndex < 0) {
document.documentElement.appendChild(style.el);
list.push(nextIndex);
list.push(style);
} else {
document.documentElement.insertBefore(style.el, list[nextIndex].el);
list.splice(nextIndex, 0, style);

View File

@ -64,7 +64,14 @@
"run_at": "document_start",
"all_frames": true,
"match_about_blank": true,
"js": ["js/polyfill.js", "js/promisify.js", "js/msg.js", "js/prefs.js", "content/apply.js"]
"js": [
"js/polyfill.js",
"js/promisify.js",
"js/msg.js",
"js/prefs.js",
"content/style-injector.js",
"content/apply.js"
]
},
{
"matches": ["http://userstyles.org/*", "https://userstyles.org/*"],