From 28c285d982fc2ea58851ce2bf735431a812cbaba Mon Sep 17 00:00:00 2001 From: MrOtherGuy Date: Sat, 10 Oct 2020 08:34:24 +0300 Subject: [PATCH] support loading scripts as background module --- profile/chrome/utils/boot.jsm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/profile/chrome/utils/boot.jsm b/profile/chrome/utils/boot.jsm index ef64558..9eaa27e 100644 --- a/profile/chrome/utils/boot.jsm +++ b/profile/chrome/utils/boot.jsm @@ -98,7 +98,14 @@ let _uc = { while(files.hasMoreElements()){ let file = files.getNext().QueryInterface(Ci.nsIFile); if (/\.uc\.js$/i.test(file.leafName)) { - _uc.getScriptData(file); + let script = _uc.getScriptData(file); + if(script.inbackground){ + try{ + Cu.import(`chrome://userscripts/content/${script.filename}`) + }catch(e){ + console.error(e); + } + } } } }, @@ -137,6 +144,7 @@ let _uc = { startup: (header.match(/\/\/ @startup\s+(.+)\s*$/im) || def)[1], //shutdown: (header.match(/\/\/ @shutdown\s+(.+)\s*$/im) || def)[1], onlyonce: /\/\/ @onlyonce\b/.test(header), + inbackground: /\/\/ @backgroundmodule\b/.test(header), isRunning: false, get isEnabled() { return (yPref.get(_uc.PREF_SCRIPTSDISABLED) || '').split(',').indexOf(this.filename) === -1; @@ -157,7 +165,7 @@ let _uc = { }, loadScript: function (script, win) { - if (!script.regex.test(win.location.href) || !script.isEnabled) { + if (script.inbackground || !script.regex.test(win.location.href) || !script.isEnabled) { return } try {