From 60f1c257512bcfa2bff97fce4865e650637cf1fa Mon Sep 17 00:00:00 2001 From: JustOff Date: Sat, 1 Feb 2020 20:14:21 +0200 Subject: [PATCH] Import from private repo --- .gitignore | 2 + LICENSE | 373 ++++++++++++++++++ README.md | 7 + classic/bootstrap.js | 324 +++++++++++++++ classic/chrome.manifest | 3 + classic/content/prefloader.js | 119 ++++++ .../defaults/preferences/scriptlet-doctor.js | 7 + classic/icon.png | Bin 0 -> 993 bytes classic/install.rdf | 28 ++ classic/options.xul | 10 + classic/skin/icoff.png | Bin 0 -> 404 bytes classic/skin/icon.png | Bin 0 -> 386 bytes quantum/background.js | 110 ++++++ quantum/icon.png | Bin 0 -> 993 bytes quantum/manifest.json | 36 ++ quantum/options.html | 37 ++ quantum/options.js | 41 ++ quantum/skin/icoff.png | Bin 0 -> 573 bytes quantum/skin/icon.png | Bin 0 -> 620 bytes release.cmd | 20 + update.json | 14 + update.xml | 30 ++ 22 files changed, 1161 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 classic/bootstrap.js create mode 100644 classic/chrome.manifest create mode 100644 classic/content/prefloader.js create mode 100644 classic/defaults/preferences/scriptlet-doctor.js create mode 100644 classic/icon.png create mode 100644 classic/install.rdf create mode 100644 classic/options.xul create mode 100644 classic/skin/icoff.png create mode 100644 classic/skin/icon.png create mode 100644 quantum/background.js create mode 100644 quantum/icon.png create mode 100644 quantum/manifest.json create mode 100644 quantum/options.html create mode 100644 quantum/options.js create mode 100644 quantum/skin/icoff.png create mode 100644 quantum/skin/icon.png create mode 100644 release.cmd create mode 100644 update.json create mode 100644 update.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a2e2dd0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.xpi +*.exe diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..14e2f77 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/README.md b/README.md new file mode 100644 index 0000000..60cd6d7 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +

Scriptlet Doctor

+ +**Scriptlet Doctor** provides a workaround for [Gecko](https://en.wikipedia.org/wiki/Gecko_%28software%29) / [Goanna](https://en.wikipedia.org/wiki/Goanna_%28software%29)-based browsers (such as [Basilisk](https://www.basilisk-browser.org/), [Firefox](https://www.mozilla.org/firefox/), [Pale Moon](https://www.palemoon.org/)) to allow inline scripts (scriptlets) inserted by add-ons, regardless of site restrictions. This can be particularly useful to overcome the limitations of blocker extensions, such as [uBlock Origin](https://github.com/gorhill/uBlock), on sites that have a strict content security policy ([CSP](https://developer.mozilla.org/docs/Web/HTTP/CSP)). + +Please note that the way **Scriptlet Doctor** works reduces the overall resistance to [XSS](https://developer.mozilla.org/docs/Glossary/Cross-site_scripting) attacks, although most sites on the Internet still do not impose strict CSP rules and nevertheless remain [fairly safe](https://en.wikipedia.org/wiki/Cross-site_scripting#Selectively_disabling_scripts). However, it is recommended to keep **Scriptlet Doctor** enabled only for a limited list of domains, as configured by default. + +**Installation packages** are located in the [releases section](https://github.com/JustOff/scriptlet-doctor/releases) and can be easily distinguished by file names: one for browsers using **classic** extensions (Pale Moon 27+, Firefox 45-56, etc.) and the other for Firefox **Quantum** (68+). diff --git a/classic/bootstrap.js b/classic/bootstrap.js new file mode 100644 index 0000000..d45480b --- /dev/null +++ b/classic/bootstrap.js @@ -0,0 +1,324 @@ +var Cc = Components.classes, Ci = Components.interfaces, Cu = Components.utils; +Cu.import("resource://gre/modules/Services.jsm"); + +var branch = "extensions.scriptlet-doctor."; +var enabled, unhideToolbar, clearReportOnly, limitToDomains, domRegex = null, gWindowListener = null; + +function listTest(host) { + if (domRegex === null) { + try { + var domainList = Services.prefs.getBranch(branch).getComplexValue("domainList", Ci.nsISupportsString).data; + domRegex = new RegExp("^([^.]+\\.)*(" + domainList.replace(/(\*\.?|\s+\.?|^\.)/g,"").replace(/;\.?/g,"|").replace(/\./g,"\\.") + ")\\.?$"); + } catch (e) { + return false; + } + } + return domRegex.test(host); +} + +var httpResponseObserver = { + observe: function (subject, topic, data) { + if ((topic == "http-on-examine-response" || topic == "http-on-examine-cached-response") && subject instanceof Ci.nsIHttpChannel) { + if (limitToDomains && !listTest(subject.URI.host)) { + return; + } + try { + var csp = subject.getResponseHeader("Content-Security-Policy"); + csp = csp.replace(/script-src.+?(;|$)/, m => { + m = m.replace(/ '(none|unsafe-hashes|strict-dynamic|nonce-.+?|sha[0-9]+-.+?=)'/g, ""); + m = m.replace(/script-src(?!.+?'unsafe-inline')/, "script-src 'unsafe-inline'"); + return m; + }); + subject.setResponseHeader("Content-Security-Policy", csp, false); + } catch (e) {} + if (clearReportOnly) { + subject.setResponseHeader("Content-Security-Policy-Report-Only", "", false); + } + } + }, + register: function () + { + Services.obs.addObserver(this, "http-on-examine-response", false); + Services.obs.addObserver(this, "http-on-examine-cached-response", false); + }, + unregister: function () + { + Services.obs.removeObserver(this, "http-on-examine-response"); + Services.obs.removeObserver(this, "http-on-examine-cached-response"); + } +}; + +function $(node, childId) { + if (node.getElementById) { + return node.getElementById(childId); + } else { + return node.querySelector("#" + childId); + } +} + +function bImg (b, img) { + b.style.listStyleImage = 'url("chrome://scriptlet-doctor/skin/' + img + '.png")'; +} + +var button = { + meta : { + id : "scriptlet-doctor-button", + label : "Scriptlet Doctor", + tooltiptext : "Scriptlet Doctor", + class : "toolbarbutton-1 chromeclass-toolbar-additional" + }, + install : function (w) { + var doc = w.document; + var b = doc.createElement("toolbarbutton"); + for (var a in this.meta) { + b.setAttribute(a, this.meta[a]); + } + + var toolbox = $(doc, "navigator-toolbox"); + toolbox.palette.appendChild(b); + + var {toolbarId, nextItemId} = this.getPrefs(), + toolbar = toolbarId && $(doc, toolbarId); + if (toolbar) { + // Handle special items with dynamic ids + var match = /^(separator|spacer|spring)\[(\d+)\]$/.exec(nextItemId); + if (match !== null) { + var dynItems = toolbar.querySelectorAll("toolbar" + match[1]); + if (match[2] < dynItems.length) { + nextItemId = dynItems[match[2]].id; + } + } + var nextItem = nextItemId && $(doc, nextItemId); + if (nextItem && nextItem.parentNode && nextItem.parentNode.id == toolbarId) { + toolbar.insertItem(this.meta.id, nextItem); + } else { + var ids = (toolbar.getAttribute("currentset") || "").split(","); + nextItem = null; + for (var i = ids.indexOf(this.meta.id) + 1; i > 0 && i < ids.length; i++) { + nextItem = $(doc, ids[i]) + if (nextItem) { + break; + } + } + toolbar.insertItem(this.meta.id, nextItem); + } + if (unhideToolbar && toolbar.getAttribute("collapsed") == "true") { + w.setToolbarVisibility(toolbar, true); + } + } + return b; + }, + afterCustomize : function (e) { + var toolbox = e.target, + b = $(toolbox.parentNode, button.meta.id), + toolbarId, nextItem, nextItemId; + if (b) { + var parent = b.parentNode; + nextItem = b.nextSibling; + if (parent && parent.localName == "toolbar") { + toolbarId = parent.id; + nextItemId = nextItem && nextItem.id; + } + } + // Handle special items with dynamic ids + var match = /^(separator|spacer|spring)\d+$/.exec(nextItemId); + if (match !== null) { + var dynItems = nextItem.parentNode.querySelectorAll("toolbar" + match[1]); + for (var i = 0; i < dynItems.length; i++) { + if (dynItems[i].id == nextItemId) { + nextItemId = match[1] + "[" + i + "]"; + break; + } + } + } + button.setPrefs(toolbarId, nextItemId); + }, + getPrefs : function () { + var p = Services.prefs.getBranch(branch); + return { + toolbarId : p.getCharPref("bar"), + nextItemId : p.getCharPref("before") + }; + }, + setPrefs : function (toolbarId, nextItemId) { + var p = Services.prefs.getBranch(branch); + p.setCharPref("bar", toolbarId || ""); + p.setCharPref("before", nextItemId || ""); + } +}; + +var scrdIn = function (w) { + var b = button.install(w); + + var windowPrefsWatcher = { + observe: function (subject, topic, data) { + if (topic == "nsPref:changed" && data == "enabled") { + if (Services.prefs.getBranch(branch).getBoolPref("enabled")) { + bImg(b, "icon"); + } else { + bImg(b, "icoff"); + } + } + }, + register: function () { + var prefsService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService); + this.prefBranch = prefsService.getBranch(branch); + this.prefBranch.addObserver("", this, false); + }, + unregister: function () { + this.prefBranch.removeObserver("", this); + } + } + + return { + init : function () { + windowPrefsWatcher.register(); + w.addEventListener("aftercustomization", button.afterCustomize, false); + b.addEventListener("command", this.run, false); + bImg(b, enabled ? "icon" : "icoff"); + }, + done : function () { + windowPrefsWatcher.unregister(); + w.removeEventListener("aftercustomization", button.afterCustomize, false); + b.removeEventListener("command", this.run, false); + b.parentNode.removeChild(b); + b = null; + }, + run : function (e) { + if (e.ctrlKey || e.metaKey) { + var mrw = Services.wm.getMostRecentWindow("navigator:browser"); + mrw.BrowserOpenAddonsMgr("addons://detail/scriptlet-doctor@Off.JustOff/preferences"); + } else { + Services.prefs.getBranch(branch).setBoolPref("enabled", !enabled); + } + } + }; +}; + +var globalPrefsWatcher = { + observe: function (subject, topic, data) { + if (topic != "nsPref:changed") return; + switch (data) { + case "enabled": + if (Services.prefs.getBranch(branch).getBoolPref("enabled")) { + httpResponseObserver.register(); + enabled = true; + } else { + httpResponseObserver.unregister(); + enabled = false; + } + break; + case "clearReportOnly": + clearReportOnly = Services.prefs.getBranch(branch).getBoolPref("clearReportOnly"); + break; + case "limitToDomains": + limitToDomains = Services.prefs.getBranch(branch).getBoolPref("limitToDomains"); + break; + case "domainList": + var domainList = Services.prefs.getBranch(branch).getComplexValue("domainList", Ci.nsISupportsString).data; + if (domainList == "") { + Services.prefs.getBranch(branch).clearUserPref("domainList"); + } + domRegex = null; + break; + case "unhideToolbar": + unhideToolbar = Services.prefs.getBranch(branch).getBoolPref("unhideToolbar"); + break; + } + }, + register: function () { + var prefsService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService); + this.prefBranch = prefsService.getBranch(branch); + this.prefBranch.addObserver("", this, false); + }, + unregister: function () { + this.prefBranch.removeObserver("", this); + } +} + +function BrowserWindowObserver(handlers) { + this.handlers = handlers; +} + +BrowserWindowObserver.prototype = { + observe: function (aSubject, aTopic, aData) { + if (aTopic == "domwindowopened") { + aSubject.QueryInterface(Ci.nsIDOMWindow).addEventListener("load", this, false); + } else if (aTopic == "domwindowclosed") { + if (aSubject.document.documentElement.getAttribute("windowtype") == "navigator:browser") { + this.handlers.onShutdown(aSubject); + } + } + }, + handleEvent: function (aEvent) { + let aWindow = aEvent.currentTarget; + aWindow.removeEventListener(aEvent.type, this, false); + + if (aWindow.document.documentElement.getAttribute("windowtype") == "navigator:browser") { + this.handlers.onStartup(aWindow); + } + } +}; + +function browserWindowStartup (aWindow) { + aWindow.scriptletDoctor = scrdIn(aWindow); + aWindow.scriptletDoctor.init() +} + +function browserWindowShutdown (aWindow) { + aWindow.scriptletDoctor.done(); + delete aWindow.scriptletDoctor; +} + +function startup(data, reason) { + Cu.import("chrome://scriptlet-doctor/content/prefloader.js"); + PrefLoader.loadDefaultPrefs(data.installPath, "scriptlet-doctor.js"); + + var p = Services.prefs.getBranch(branch); + clearReportOnly = p.getBoolPref("clearReportOnly"); + limitToDomains = p.getBoolPref("limitToDomains"); + listTest(); + enabled = p.getBoolPref("enabled"); + if (enabled) { + httpResponseObserver.register(); + } + globalPrefsWatcher.register(); + unhideToolbar = p.getBoolPref("unhideToolbar"); + + var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher); + gWindowListener = new BrowserWindowObserver({ + onStartup: browserWindowStartup, + onShutdown: browserWindowShutdown + }); + ww.registerNotification(gWindowListener); + + var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); + var winenu = wm.getEnumerator("navigator:browser"); + while (winenu.hasMoreElements()) { + browserWindowStartup(winenu.getNext()); + } +} + +function shutdown(data, reason) { + if (reason == APP_SHUTDOWN) return; + + var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(Ci.nsIWindowWatcher); + ww.unregisterNotification(gWindowListener); + gWindowListener = null; + + var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); + var winenu = wm.getEnumerator("navigator:browser"); + while (winenu.hasMoreElements()) { + browserWindowShutdown(winenu.getNext()); + } + + globalPrefsWatcher.unregister(); + if (enabled) { + httpResponseObserver.unregister(); + } + + Cu.unload("chrome://scriptlet-doctor/content/prefloader.js"); +} + +function install(data, reason) {} +function uninstall(data, reason) {} diff --git a/classic/chrome.manifest b/classic/chrome.manifest new file mode 100644 index 0000000..06a83a8 --- /dev/null +++ b/classic/chrome.manifest @@ -0,0 +1,3 @@ +content scriptlet-doctor content/ + +skin scriptlet-doctor classic/1.0 skin/ diff --git a/classic/content/prefloader.js b/classic/content/prefloader.js new file mode 100644 index 0000000..1c35717 --- /dev/null +++ b/classic/content/prefloader.js @@ -0,0 +1,119 @@ +/* Copyright (c) 2009, Mozilla Foundation + * All rights reserved. + * http://opensource.org/licenses/BSD-3-Clause + */ + +var Cc = Components.classes; +var Ci = Components.interfaces; +var Cu = Components.utils; + +Cu.import("resource://gre/modules/Services.jsm"); + +var EXPORTED_SYMBOLS = ["PrefLoader"]; + +var PrefLoader = {}; +PrefLoader.prefDomain = "extensions.scriptlet-doctor."; + +function loadDefaultPrefs(path, fileName) +{ + try + { + var uri; + var baseURI = Services.io.newFileURI(path); + + if (path.isDirectory()) + uri = Services.io.newURI("defaults/preferences/" + fileName, null, baseURI).spec; + else + uri = "jar:" + baseURI.spec + "!/defaults/preferences/" + fileName; + + Services.scriptloader.loadSubScript(uri, {pref: pref}); + } + catch (err) + { + Cu.reportError(err); + } +} + +function clearDefaultPrefs(domain) +{ + domain = domain || PrefLoader.prefDomain; + var pb = Services.prefs.getDefaultBranch(domain); + + var names = pb.getChildList(""); + for (var i=0; i=0hNIfRGsv9W$V8 zh&YHu5jKIGb-}bl6`<-u7zI{_Y$il6+=PvcvPXe#(k}_}3ua*X`Iqfw62WYx_;?ZiHL@|$1Sq>`f{z? zGbdLoHgEs1dhhC5?H7K<+V@-LY`*)gn(?i{kJmY3W#7JQt(m>QtZV!7yW$t*rvLxL zwAH&S^=$htVf`0vlNQhXuK4X{aME7R9Lcm)&NCNfj~?3CZ=Y$kl095!#!dOZ+bn(s zD$I2{wpZ<3M|#c1-rJJeH@nLpeTaIdB{F-*^siEt>T~7gYff-SoLK*mwM+P!ve4J9 zNB?~gl3R7_k)ZjW{O{+|OvOxVi)woKcq-cELM!&qUwbq-z~EQ|<3CRWP7VGFZnpW= zdMo%h_qtSznVu+=aSar6le+$}JHXhyD)!K;mV#(s+n&{jD_O7Dd@5<{cL=Z3tE{wW zeQdy#{Ue-JGVXt5U{<@@AJHkR7Tz>!m{$L7!}I^2mnWNVo@N-4x9Z`)OoRUVc?{hr zv=6=OO1j>4?&B}s3pY0ih z_6RZt+w(hk&idk78S`m-xWI-=hFGb<%=(|d4lMEgaA``|k@R2cPT5X7jgpL36cp8& z^B3&9;?%7=@!EoW{a+&;R9PpQUZ^SK;c6CIYTk1zWETJ1wM#prl*Hw191=PWj<4CY zBVwzY-j=B5vYUy_lB-nb-V2I&r{RhT3p$jvMF0-ZR)~Y)k&wO{Ijv!w7%uM=+!3~ zllEH*M}OIDS1&Ake2)ExZL5SHTJ5bXd;js*dA8TA^`8$Wi2f_M@NeVYeJ#@ylFekF xml${K`OeSIy;qMn=C+Bi`it9#;xE-R7zb`)b)55D2beDyJYD@<);T3K0RXcs(}(~7 literal 0 HcmV?d00001 diff --git a/classic/install.rdf b/classic/install.rdf new file mode 100644 index 0000000..ae35ceb --- /dev/null +++ b/classic/install.rdf @@ -0,0 +1,28 @@ + + + + scriptlet-doctor@Off.JustOff + 1.0.1 + 2 + true + Scriptlet Doctor + Allow inline scripts regardless of site policy + Off JustOff <Off.Just.Off@gmail.com> + https://github.com/JustOff/scriptlet-doctor/ + https://raw.githubusercontent.com/JustOff/scriptlet-doctor/master/update.xml + + + {8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4} + 27.0.0 + 29.* + + + + + {ec8030f7-c20a-464f-9b0e-13a3a9e97384} + 45.0 + 56.* + + + + diff --git a/classic/options.xul b/classic/options.xul new file mode 100644 index 0000000..2beff39 --- /dev/null +++ b/classic/options.xul @@ -0,0 +1,10 @@ + + + + + + + + Use ; as a delimiter for multiple domains + + diff --git a/classic/skin/icoff.png b/classic/skin/icoff.png new file mode 100644 index 0000000000000000000000000000000000000000..3b0a0a5dd982780817e983d57a4b6f18ba966afc GIT binary patch literal 404 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbK}X@F0NE07LH0ud1rNIWb|paNWK zFvY=Yu^70G^?pClVzrVWzhH(>?BDP7>;G!hQlF~)=+fT#Gm4`fP2{g_o!#ADC&2yw z_0iQS0TSyzADac#vBJ~EF+}3BZr@F@Lka@U#tw~9+2YaPYft{KUnIDfzo3X;k}Y2B z>ZzRDE`JI{|MRSSBKud-DqOzz?)8wIY>{b=)n6xv|C3I>(wudsl6Ot9oH6?viTNqB zp1JgSvq{L7rAVLP`>?O$d+(!Nnogn*To+od%6P%(;BQwl_e;KSG{f@?^BQ{#*`(NJ zW(M8c#QwnQSMpk3|6{*d51Fb2U%IF*o+P}dHL>jngZm>sg&J3d4L~$ literal 0 HcmV?d00001 diff --git a/classic/skin/icon.png b/classic/skin/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..64ab1bdb63d79f2faaf5ae4f7a577974f5d709af GIT binary patch literal 386 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbK}PJmB{E0A`~d`KU3%H*UI&_3mo zAirRS@1G3rG%)uou}{@j|23=g(X~sv=NCuwygg(uy?J#?fSZNT#%!)5K;?@(T^vIs zE}Qm;3msMvaGw53Li)Ryb?o>3$t;EU*n3R0H+n46V_W+>;fZ_X1C=R}{Q+w~?#nV= zcT)30=%k$yCTHATYptZ(n2)}>qqNDw+`5m)fS=*FHPdI-Fq1uZ8qP5-7GJulFh}9G zqDhd;6V5|&ZV|UO)ib@@6O_ps+P!Am?>Xna8kTO}zoOdb|5fex*~hP5|1*<8!A(xM h^jJ%r=4}bZ_&@h}LyF(WHv(PD;OXk;vd$@?2>=i2qYVH6 literal 0 HcmV?d00001 diff --git a/quantum/background.js b/quantum/background.js new file mode 100644 index 0000000..1c87541 --- /dev/null +++ b/quantum/background.js @@ -0,0 +1,110 @@ +var defaultDomains = "yandex.by;yandex.kz;yandex.ru;yandex.ua;yandex.net;yastatic.net"; +var enabled = false, limitToDomains, domainPattern; + +function updateCSP(e) { + e.responseHeaders.forEach(header => { + if (header.name.toLowerCase() == "content-security-policy") { + header.value = header.value.replace(/script-src.+?(;|$)/, m => { + m = m.replace(/ '(none|unsafe-hashes|strict-dynamic|nonce-.+?|sha[0-9]+-.+?=)'/g, ""); + m = m.replace(/script-src(?!.+?'unsafe-inline')/, "script-src 'unsafe-inline'"); + return m; + }); + } + }); + return {responseHeaders: e.responseHeaders}; +} + +function enableScDoctor(updateIcon = true) { + var matchPattern; + if (limitToDomains) { + matchPattern = domainPattern; + } else { + matchPattern = ["*://*/*"]; + } + browser.webRequest.onHeadersReceived.addListener( + updateCSP, + {urls : matchPattern}, + ["blocking", "responseHeaders"] + ); + if (updateIcon) { + browser.browserAction.setIcon({path: "skin/icon.png"}); + } +} + +function disableScDoctor(updateIcon = true) { + browser.webRequest.onHeadersReceived.removeListener(updateCSP); + if (updateIcon) { + browser.browserAction.setIcon({path: "skin/icoff.png"}); + } +} + +function restartScDoctor() { + if (enabled) { + disableScDoctor(false /*updateIcon*/); + enableScDoctor(false /*updateIcon*/); + } +} + +function buttonListener(tab, OnClickData) { + if (OnClickData.modifiers.includes("Ctrl")) { + browser.runtime.openOptionsPage(); + } else { + if (enabled) { + browser.storage.local.set({"enabled": false}); + } else { + browser.storage.local.set({"enabled": true}); + } + } +} + +function updateDomainList(domains) { + domainPattern = []; + domains.split(";").forEach(domain => { + domainPattern.push("*://*." + domain.trim().replace(/^\*\.?/,"") + "/*"); + }); +} + +function storageListener(changes) { + if (changes["enabled"]) { + if (changes["enabled"].newValue) { + enabled = true; + enableScDoctor(); + } else { + enabled = false; + disableScDoctor(); + } + } else if (changes["domainList"]) { + updateDomainList(changes["domainList"].newValue || defaultDomains); + if (limitToDomains) { + restartScDoctor(); + } + } else if (changes["limitToDomains"]) { + limitToDomains = changes["limitToDomains"].newValue; + restartScDoctor(); + } +} + +browser.storage.onChanged.addListener(storageListener); +browser.browserAction.onClicked.addListener(buttonListener); + +browser.storage.local.get(["enabled", "limitToDomains", "domainList", "defaultDomains"], res => { + if (res.defaultDomains != defaultDomains) { + browser.storage.local.set({"defaultDomains": defaultDomains}); + } + if (res.domainList === undefined) { + browser.storage.local.set({"domainList": defaultDomains}); + } else { + updateDomainList(res.domainList); + } + if (res.limitToDomains === undefined) { + browser.storage.local.set({"limitToDomains": true}); + } else { + limitToDomains = res.limitToDomains; + } + if (res.enabled === undefined) { + browser.storage.local.set({"enabled": true}); + } else if (res.enabled) { + enabled = true; + enableScDoctor(); + } +}); diff --git a/quantum/icon.png b/quantum/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..4050443c039b5968922a53c8e5af85f121c3f7bd GIT binary patch literal 993 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA3?vioaBc-s69RlfT!FM>=0hNIfRGsv9W$V8 zh&YHu5jKIGb-}bl6`<-u7zI{_Y$il6+=PvcvPXe#(k}_}3ua*X`Iqfw62WYx_;?ZiHL@|$1Sq>`f{z? zGbdLoHgEs1dhhC5?H7K<+V@-LY`*)gn(?i{kJmY3W#7JQt(m>QtZV!7yW$t*rvLxL zwAH&S^=$htVf`0vlNQhXuK4X{aME7R9Lcm)&NCNfj~?3CZ=Y$kl095!#!dOZ+bn(s zD$I2{wpZ<3M|#c1-rJJeH@nLpeTaIdB{F-*^siEt>T~7gYff-SoLK*mwM+P!ve4J9 zNB?~gl3R7_k)ZjW{O{+|OvOxVi)woKcq-cELM!&qUwbq-z~EQ|<3CRWP7VGFZnpW= zdMo%h_qtSznVu+=aSar6le+$}JHXhyD)!K;mV#(s+n&{jD_O7Dd@5<{cL=Z3tE{wW zeQdy#{Ue-JGVXt5U{<@@AJHkR7Tz>!m{$L7!}I^2mnWNVo@N-4x9Z`)OoRUVc?{hr zv=6=OO1j>4?&B}s3pY0ih z_6RZt+w(hk&idk78S`m-xWI-=hFGb<%=(|d4lMEgaA``|k@R2cPT5X7jgpL36cp8& z^B3&9;?%7=@!EoW{a+&;R9PpQUZ^SK;c6CIYTk1zWETJ1wM#prl*Hw191=PWj<4CY zBVwzY-j=B5vYUy_lB-nb-V2I&r{RhT3p$jvMF0-ZR)~Y)k&wO{Ijv!w7%uM=+!3~ zllEH*M}OIDS1&Ake2)ExZL5SHTJ5bXd;js*dA8TA^`8$Wi2f_M@NeVYeJ#@ylFekF xml${K`OeSIy;qMn=C+Bi`it9#;xE-R7zb`)b)55D2beDyJYD@<);T3K0RXcs(}(~7 literal 0 HcmV?d00001 diff --git a/quantum/manifest.json b/quantum/manifest.json new file mode 100644 index 0000000..5bda87f --- /dev/null +++ b/quantum/manifest.json @@ -0,0 +1,36 @@ +{ + "manifest_version": 2, + "name": "Scriptlet Doctor", + "version": "1.0.1", + "description": "Allow inline scripts regardless of site policy", + "author": "Off JustOff ", + "homepage_url": "https://github.com/JustOff/scriptlet-doctor/", + "browser_specific_settings": { + "gecko": { + "id": "scriptlet-doctor@Off.JustOff", + "strict_min_version": "68.0", + "update_url": "https://raw.githubusercontent.com/JustOff/scriptlet-doctor/master/update.json" + } + }, + "icons": { + "48": "icon.png" + }, + "background": { + "scripts": [ + "background.js" + ] + }, + "browser_action": { + "default_icon": "skin/icoff.png", + "default_title": "Scriptlet Doctor" + }, + "options_ui": { + "page": "options.html" + }, + "permissions": [ + "", + "webRequest", + "webRequestBlocking", + "storage" + ] +} diff --git a/quantum/options.html b/quantum/options.html new file mode 100644 index 0000000..9ca77fb --- /dev/null +++ b/quantum/options.html @@ -0,0 +1,37 @@ + + + + + + + + + + + + + diff --git a/quantum/options.js b/quantum/options.js new file mode 100644 index 0000000..550d958 --- /dev/null +++ b/quantum/options.js @@ -0,0 +1,41 @@ +window.onload = () => { + browser.storage.local.get(["enabled", "limitToDomains", "domainList", "defaultDomains"], res => { + var checkEnabled = true, defaultDomains = res.defaultDomains; + var enabled = document.querySelector("#enabled"); + enabled.checked = res.enabled; + enabled.onchange = () => { + if (checkEnabled) { + browser.storage.local.set({ + enabled: enabled.checked + }); + } + } + var limitToDomains = document.querySelector("#limitToDomains"); + limitToDomains.checked = res.limitToDomains; + limitToDomains.onchange = () => { + browser.storage.local.set({ + limitToDomains: limitToDomains.checked + }); + } + var domainList = document.querySelector("#domainList"); + domainList.value = res.domainList; + domainList.onkeyup = domainList.onchange = () => { + if (domainList.value.trim() == "") { + domainList.value = defaultDomains; + } + browser.storage.local.set({ + domainList: domainList.value.trim() + }); + } + function buttonListener(tab, OnClickData) { + if (!OnClickData.modifiers.includes("Ctrl")) { + browser.storage.local.get("enabled", res => { + checkEnabled = false; + enabled.checked = res.enabled; + checkEnabled = true; + }); + } + } + browser.browserAction.onClicked.addListener(buttonListener); + }); +} diff --git a/quantum/skin/icoff.png b/quantum/skin/icoff.png new file mode 100644 index 0000000000000000000000000000000000000000..3500a34450c632b55bb1700d7b025f39ce57f398 GIT binary patch literal 573 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dynE^f_u0T2*6+}ctpb8MngJ=Yj za0aqY@fOofK+BX$g8YIRSbluG{p#X$9nMpS7kYLymc*+nNC=tp?CH%4v8{UicwO(} zGp+9#7#I^hT^vI!PUi-{oYiE&%S-Sxj~M)^OF)qR&ZZ?3G!UZ0e&bEe$+T${#aKjQ;7cZ+{z*S;~I5*PX= zW5p4^MgE^(oBM8^z*Q`JO#R0J(VOC&8E@K|{dSyIX#Dx8M{8%`%@4b^+LlO|%NRO2 zGoR|Ykht&p4Ur!|=7~goko^6;Su^P>@46))oefKp<_CFvh+-CMQ0rxo-hbrOf!2*u zITAb*)ZEuH?AC9nt3Sh+#OSRsPcxpCapDAbrDOLiiuY`>3A(0Y674wuT;S%wq=k?F z2utKlIdt9pj0oH3GL}O}!VWvdaZmRwwVF2PHsj*Etrz>O&+X06O>0Z(7M_%Jbamyk zs3+SVaZ64x7cdO$|E3@zSF_;U4I$E{$>3{nTvy;nRpE(}(nRHX-fq?C8xyz zCmQiR^8dSe>hf0;tc}8x_B8XyOn7@j;aJs;g!aucDjCW*98_agTc3M#{&2YHfEVy{r zTK>j7o(ERe`VMDR9k%XS$TC?$tRsH;@>>o%PbPLe%gOJXKF$5qjFyWkA@5`)H!fUb zkp7olVvk1a`g#N5))nl$0#$LQB{!6W&Kci)7xCdp@$&;3)1Ia}L*{*OxvU!N@&4eWnL0fB95$SX?FEls z{-9=@Uf*ujfB#8NlWyD3sVw{C-)vr0_{RQYwj1{W(f$d*7-R5s^>bP0l+XkK-9i=L literal 0 HcmV?d00001 diff --git a/release.cmd b/release.cmd new file mode 100644 index 0000000..854a3f0 --- /dev/null +++ b/release.cmd @@ -0,0 +1,20 @@ +@echo off +set VER=1.0.1 + +sed -i -E "s/version>.+?%VER%.+?%VER% + + + + + + + 1.0.1 + + + {8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4} + 27.0.0 + 29.* + https://github.com/JustOff/scriptlet-doctor/releases/download/1.0.1/scriptlet-doctor-classic-1.0.1.xpi + + + + + {ec8030f7-c20a-464f-9b0e-13a3a9e97384} + 45.0 + 56.* + https://github.com/JustOff/scriptlet-doctor/releases/download/1.0.1/scriptlet-doctor-classic-1.0.1.xpi + + + + + + + +