From 68d8df39e3d9d7b90e48147d57cc7b79812ee7c8 Mon Sep 17 00:00:00 2001 From: Thomas Benhamou Date: Thu, 26 Jul 2018 14:47:45 +0200 Subject: [PATCH] 1.2 : [Added regexp based whitelist] --- background.js | 56 ++-- js/jspop.js | 0 manifest.json | 11 +- popup.html | 767 ++++++++++++++++++++++++++------------------------ popup.js | 20 ++ readme.md | 5 + 6 files changed, 467 insertions(+), 392 deletions(-) create mode 100644 js/jspop.js create mode 100644 popup.js diff --git a/background.js b/background.js index 1666d3a..a98d620 100644 --- a/background.js +++ b/background.js @@ -1,13 +1,27 @@ +var defaultRgx = ["http://*/*", "https://*/*"].join('\n') +var regexpesarray = []; +function updateRegexpes(save) +{ + browser.storage.local.get("regstr", function(res) { + var regstr = (res.regstr || defaultRgx); + regexpesarray = []; + var regexpesarray = regstr.split("\n") + console.log(regexpesarray) -// Add the new header to the original array, -// and return it. + browser.webRequest.onHeadersReceived.removeListener(setHeader) + browser.webRequest.onHeadersReceived.addListener(setHeader, + {urls : regexpesarray}, + ["blocking", "responseHeaders"] + ); + }); +} function setHeader(e) { -for (var header of e.responseHeaders) { - if (header.name.toLowerCase() === "x-frame-options") { - header.value = "ALLOW"; - } - } + for (var header of e.responseHeaders) { + if (header.name.toLowerCase() === "x-frame-options") { + header.value = "ALLOW"; + } + } var setMyCookie = { name: "x-frame-options", value: "ALLOW" @@ -15,16 +29,24 @@ for (var header of e.responseHeaders) { e.responseHeaders.push(setMyCookie); return {responseHeaders: e.responseHeaders}; } - // Listen for onHeaderReceived for the target page. // Set "blocking" and "responseHeaders". -browser.webRequest.onHeadersReceived.addListener( - setHeader, - {urls : ["http://*/*", "https://*/*"]}, - ["blocking", "responseHeaders"] -); +updateRegexpes(); console.log("Loaded") -browser.browserAction.onClicked.addListener(function() -{ - alert(); -}) \ No newline at end of file +var portFromCS; +function connected(p) { + portFromCS = p; + //portFromCS.postMessage({greeting: "hi there content script!"}); + portFromCS.onMessage.addListener(function(m) { + if(m.updateRegexpes) + { + + browser.storage.local.set({"regstr":m.updateRegexpes}, function(res) { + updateRegexpes(); + }); + + + } +}); +} +browser.runtime.onConnect.addListener(connected); diff --git a/js/jspop.js b/js/jspop.js new file mode 100644 index 0000000..e69de29 diff --git a/manifest.json b/manifest.json index 9c42618..a19379e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Ignore X-Frame-Options", - "version": "1.1", + "version": "1.2", "description": "Allows all sites to be loaded in iframes, despite X-Frame-Options header settings.", "homepage_url": "https://github.com/ThomazPom/Moz-Ext-Ignore-X-Frame-Options", "icons": { @@ -9,8 +9,14 @@ "96": "icons/2x.png" }, + "content_scripts":[ + { + "matches": [""], + "js": ["js/jspop.js"] + } + ], "permissions": [ - "", "webRequest", "webRequestBlocking"] + "", "webRequest", "webRequestBlocking","storage"] , "browser_action": { @@ -19,7 +25,6 @@ "default_popup": "popup.html" }, - "background": { "scripts": ["background.js"] } diff --git a/popup.html b/popup.html index 66e0d81..aa8cc08 100644 --- a/popup.html +++ b/popup.html @@ -1,373 +1,396 @@ - - - - - - - - -
- -
- + + + + + + + + +
+ +
+ Whitelist Regexp (1 per line) : +

+ +
+ + +
+ \ No newline at end of file diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..e43ade0 --- /dev/null +++ b/popup.js @@ -0,0 +1,20 @@ +// content-script.js +var defaultRgx = ["http://*/*", "https://*/*"].join('\n') +var myPort = browser.runtime.connect({name:"port-from-cs"}); +myPort.onMessage.addListener(function(m) { + document.querySelector("#warning").innerText=m.message +}); +browser.storage.local.get("regstr", function(res) { + regstr = (res.regstr || defaultRgx); + document.querySelector(".listextarea").value=regstr; +}); +window.onload= function() +{ + txarea = document.querySelector(".listextarea"); + txarea.onkeyup = txarea.onchange = function(){ + regstr = txarea.value.trim() + browser.storage.local.set({"regstr": regstr}, function() { + myPort.postMessage({updateRegexpes: regstr}); + }); + } +} \ No newline at end of file diff --git a/readme.md b/readme.md index f036c9c..64aaa8a 100644 --- a/readme.md +++ b/readme.md @@ -4,3 +4,8 @@ The extension allows you to load remote content in iframes even if the server di # Compatibility - Firefox Quantum 48+ + +# Versions + +- 1.1 : Initial release +- 1.2 : [Added regexp based whitelist](https://github.com/ThomazPom/Moz-Ext-Ignore-X-Frame-Options/issues/1) \ No newline at end of file