From 5a21c720404961c9615afc7e45a3abab79e0dd10 Mon Sep 17 00:00:00 2001 From: eight Date: Sun, 3 Feb 2019 18:38:57 +0800 Subject: [PATCH] Fix: minor --- content/apply.js | 5 ++--- content/style-injector.js | 4 ++-- manifest.json | 9 ++++++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/content/apply.js b/content/apply.js index 14acda91..984dd1f3 100644 --- a/content/apply.js +++ b/content/apply.js @@ -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); diff --git a/content/style-injector.js b/content/style-injector.js index 5d0321c7..55b0a742 100644 --- a/content/style-injector.js +++ b/content/style-injector.js @@ -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); diff --git a/manifest.json b/manifest.json index 21374881..b8eab624 100644 --- a/manifest.json +++ b/manifest.json @@ -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/*"],