From 7e33e89e511362da85e327f416308a5454db3c21 Mon Sep 17 00:00:00 2001 From: Gabriele Cirulli Date: Wed, 27 Jul 2016 21:38:50 +0200 Subject: [PATCH 1/5] Restore basic functionality of permissions dialog. Fixes #98 --- lib/extras/permissions.html | 3 ++- lib/settings.js | 23 ----------------------- lib/setup.js | 25 +++++++++++++++++++++++++ manifest.json | 1 + 4 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 lib/setup.js diff --git a/lib/extras/permissions.html b/lib/extras/permissions.html index 14f8afb..7c3f0b2 100644 --- a/lib/extras/permissions.html +++ b/lib/extras/permissions.html @@ -1,6 +1,6 @@ - +
@@ -8,6 +8,7 @@
+ diff --git a/lib/settings.js b/lib/settings.js index 5127874..af6fd7f 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -1,20 +1,3 @@ -function BrowserAbstraction() -{ - this.firefoxOptions = self.options; -} - -BrowserAbstraction.prototype.getUrl = function( name ) { - return HNSpecial.isChrome ? - chrome.runtime.getURL( name ) : - this.firefoxOptions.urlBase + name; -}; - -BrowserAbstraction.prototype.getDefaultOptions = function( cb ) { - return HNSpecial.isChrome ? - _.request( HNSpecial.browser.getUrl( "lib/defaults.json" ), "GET", cb ) : - cb( this.firefoxOptions.defaultOptions ); -}; - function Settings() { var self = this; @@ -523,11 +506,5 @@ Settings.prototype.updateAndReload = function () { (function () { // Run the settings module as soon as possible - this.HNSpecial = {}; - - if( this.chrome !== undefined ) - this.HNSpecial.isChrome = true; - this.HNSpecial.browser = new BrowserAbstraction(); - this.HNSpecial.settings = new Settings(); }).call(this); diff --git a/lib/setup.js b/lib/setup.js new file mode 100644 index 0000000..6e8b891 --- /dev/null +++ b/lib/setup.js @@ -0,0 +1,25 @@ +function BrowserAbstraction() { + this.firefoxOptions = self.options; +} + +BrowserAbstraction.prototype.getUrl = function (name) { + return HNSpecial.isChrome ? + chrome.runtime.getURL( name ) : + this.firefoxOptions.urlBase + name; +}; + +BrowserAbstraction.prototype.getDefaultOptions = function (cb) { + return HNSpecial.isChrome ? + _.request( HNSpecial.browser.getUrl("lib/defaults.json"), "GET", cb ) : + cb(this.firefoxOptions.defaultOptions); +}; + +(function () { + this.HNSpecial = {}; + + if (this.chrome !== undefined) { + this.HNSpecial.isChrome = true; + } + + this.HNSpecial.browser = new BrowserAbstraction(); +}).call(this); diff --git a/manifest.json b/manifest.json index 43911f1..1204df9 100644 --- a/manifest.json +++ b/manifest.json @@ -32,6 +32,7 @@ { "matches": [ "http://news.ycombinator.com/*", "https://news.ycombinator.com/*" ], "js": [ + "lib/setup.js", "lib/tools/utility.js", "lib/settings.js", "lib/modules/visual_theme.js", From 94388500db0725fb1d887786b3b293d5547f5ea8 Mon Sep 17 00:00:00 2001 From: Gabriele Cirulli Date: Wed, 27 Jul 2016 21:57:09 +0200 Subject: [PATCH 2/5] Restore cosmetics of the permissions dialog --- lib/extras/permissions.html | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/extras/permissions.html b/lib/extras/permissions.html index 7c3f0b2..0413faf 100644 --- a/lib/extras/permissions.html +++ b/lib/extras/permissions.html @@ -1,6 +1,7 @@ +
From c958510ee89685da3f271d8345b4bc83701f50e8 Mon Sep 17 00:00:00 2001 From: Gabriele Cirulli Date: Wed, 27 Jul 2016 21:57:30 +0200 Subject: [PATCH 3/5] Make mark_as_read permissions message browser-independent --- lib/defaults.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/defaults.json b/lib/defaults.json index 15f2c13..897e097 100644 --- a/lib/defaults.json +++ b/lib/defaults.json @@ -24,7 +24,7 @@ "permissions": { "mark_as_read": { "permissions": ["history"], - "description": "Mark As Read uses the chrome.history API to add links that you mark as read to your browser history." + "description": "Mark As Read uses additional browser permissions to add links that you mark as read to your history." } }, "tips": [ From e89edf40f8860b270cb60fdc3d4a677e55ed0f5b Mon Sep 17 00:00:00 2001 From: Gabriele Cirulli Date: Wed, 27 Jul 2016 20:14:47 +0200 Subject: [PATCH 4/5] Refactor stylesheet injection into utility --- lib/modules/dark_theme.js | 6 +----- lib/modules/high_contrast.js | 6 +----- lib/modules/visual_theme.js | 6 +----- lib/tools/utility.js | 8 ++++++++ 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/modules/dark_theme.js b/lib/modules/dark_theme.js index e681b65..c504c8c 100644 --- a/lib/modules/dark_theme.js +++ b/lib/modules/dark_theme.js @@ -1,7 +1,3 @@ HNSpecial.settings.registerModule( "dark_theme", function() { - var theme = document.createElement( "link" ); - theme.rel = "stylesheet"; - theme.type = "text/css"; - theme.href = HNSpecial.browser.getUrl( "lib/extras/hn_theme_dark.css" ); - document.getElementsByTagName( "head" )[ 0 ].appendChild( theme ); + _.injectStylesheet("lib/extras/hn_theme_dark.css"); } ); diff --git a/lib/modules/high_contrast.js b/lib/modules/high_contrast.js index 8e90399..08229c5 100644 --- a/lib/modules/high_contrast.js +++ b/lib/modules/high_contrast.js @@ -1,7 +1,3 @@ HNSpecial.settings.registerModule("high_contrast", function () { - var theme = document.createElement( "link" ); - theme.rel = "stylesheet"; - theme.type = "text/css"; - theme.href = HNSpecial.browser.getUrl( "lib/extras/hn_theme_light_contrast.css" ); - document.getElementsByTagName( "head" )[ 0 ].appendChild( theme ); + _.injectStylesheet("lib/extras/hn_theme_light_contrast.css"); }); diff --git a/lib/modules/visual_theme.js b/lib/modules/visual_theme.js index 9782817..ee63612 100644 --- a/lib/modules/visual_theme.js +++ b/lib/modules/visual_theme.js @@ -13,11 +13,7 @@ HNSpecial.settings.registerModule("visual_theme", function () { // Add this extension's CSS theme if( !HNSpecial.settings.moduleEnabled( "dark_theme" ) && !HNSpecial.settings.moduleEnabled( "high_contrast" ) ) { - var theme = document.createElement("link"); - theme.rel = "stylesheet"; - theme.type = "text/css"; - theme.href = HNSpecial.browser.getUrl( "lib/extras/hn_theme_light.css" ); - document.getElementsByTagName('head')[0].appendChild(theme); + _.injectStylesheet("lib/extras/hn_theme_light.css"); } // Store the topcolor so we can use it later diff --git a/lib/tools/utility.js b/lib/tools/utility.js index 562f6a4..4b58a48 100644 --- a/lib/tools/utility.js +++ b/lib/tools/utility.js @@ -118,5 +118,13 @@ } }; + _.injectStylesheet = function (path) { + var theme = document.createElement("link"); + theme.rel = "stylesheet"; + theme.type = "text/css"; + theme.href = HNSpecial.browser.getUrl(path); + document.getElementsByTagName("head")[0].appendChild(theme); + }; + this._ = _; }).call(this); From c0f544a68830c9e9560bfafe04a9adfdea9ef006 Mon Sep 17 00:00:00 2001 From: Gabriele Cirulli Date: Wed, 27 Jul 2016 22:26:26 +0200 Subject: [PATCH 5/5] Pass theme information to the permissions iframe and load theme if necessary --- lib/extras/_theme.styl | 3 +++ lib/extras/background.js | 1 - lib/extras/permissions.html | 2 +- lib/extras/permissions.js | 7 ++++++- lib/settings.js | 6 +++++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/extras/_theme.styl b/lib/extras/_theme.styl index 2612fa3..9a40bf0 100644 --- a/lib/extras/_theme.styl +++ b/lib/extras/_theme.styl @@ -183,6 +183,9 @@ $hnspecial-button line-height 1.5 color menu-color + &.hnspecial-settings-menu-inner-transparent + background transparent + strong font-weight 400 color darken(menu-color, 20%) diff --git a/lib/extras/background.js b/lib/extras/background.js index a9c108f..b38ad0d 100644 --- a/lib/extras/background.js +++ b/lib/extras/background.js @@ -22,7 +22,6 @@ } else { - console.log("stupid chrom"); var search = require("sdk/places/history"); search( params diff --git a/lib/extras/permissions.html b/lib/extras/permissions.html index 0413faf..a59d4b1 100644 --- a/lib/extras/permissions.html +++ b/lib/extras/permissions.html @@ -4,7 +4,7 @@ -
+

diff --git a/lib/extras/permissions.js b/lib/extras/permissions.js index f3efb82..4e90e38 100644 --- a/lib/extras/permissions.js +++ b/lib/extras/permissions.js @@ -4,6 +4,11 @@ _.load(function () { var modulePermissionsDescription = null; // The description of the optional permissions var originalPermissionStatus = null; var isPermissionsEnabled = false; // Are the permissions for this module enabled? + var theme = window.location.hash.match(/~(.*)/); + + if (theme && theme[1] === "dark") { + _.injectStylesheet("lib/extras/hn_theme_dark.css"); + } // Lookup the state of the current permission var checkPermissionState = function () { @@ -62,7 +67,7 @@ _.load(function () { var permissions = JSON.parse(results).permissions; // What module are we requesting optional permissions for? - moduleName = window.location.hash.replace(/^#/, ""); + moduleName = window.location.hash.replace(/^#|~.*/g, ""); if (permissions[moduleName] !== undefined) { modulePermissions = permissions[moduleName].permissions; diff --git a/lib/settings.js b/lib/settings.js index af6fd7f..331c63b 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -354,6 +354,8 @@ Settings.prototype.applyPermissions = function (permissions, map) { }; Settings.prototype.setupOptionalPermissions = function (container, moduleName, moduleActivated) { + var self = this; + if (HNSpecial.isChrome) { // Remove the iframe if it exists var element = document.getElementById("hnspecial-permissions-" + moduleName); @@ -363,11 +365,13 @@ Settings.prototype.setupOptionalPermissions = function (container, moduleName, m var complete = function () { // Add the iframe, passing in the module name + var themeModifier = self.currentSettings.dark_theme ? "dark" : "light"; + var iframe = _.createElement("iframe", { classes: ["hnspecial-permissions-iframe"], attributes: { id: "hnspecial-permissions-" + moduleName, - src: HNSpecial.browser.getUrl("lib/extras/permissions.html#" + moduleName) + src: HNSpecial.browser.getUrl("lib/extras/permissions.html#" + moduleName + "~" + themeModifier) } }); container.appendChild(iframe);