From 0e6c5e35ac71dccec12ae6a4d062b35c30f9a58e Mon Sep 17 00:00:00 2001 From: Jeremy Schomery Date: Thu, 16 Mar 2017 17:06:33 +0330 Subject: [PATCH] Path for configureCommands is chosen based on user's browser (Opera incomatibility) --- messaging.js | 13 +++++++++++++ openOptions.js | 9 ++++----- options/index.html | 1 + options/index.js | 8 +++++--- popup.js | 8 +++----- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/messaging.js b/messaging.js index 111991ad..7dfe54b3 100644 --- a/messaging.js +++ b/messaging.js @@ -131,3 +131,16 @@ function stringAsRegExp(s, flags) { function wildcardAsRegExp(s, flags) { return new RegExp(s.replace(/[{}()\[\]\/\\.+?^$:=!|]/g, "\\$&").replace(/\*/g, '.*?'), flags); } + +var configureCommands = { + get url () { + return navigator.userAgent.indexOf('OPR') > -1 ? + 'opera://settings/configureCommands' : + 'chrome://extensions/configureCommands' + }, + open: () => { + chrome.tabs.create({ + 'url': configureCommands.url + }); + } +}; diff --git a/openOptions.js b/openOptions.js index 6d4f1f06..24a73fb7 100644 --- a/openOptions.js +++ b/openOptions.js @@ -1,3 +1,6 @@ +/* globals configureCommands */ +'use strict'; + document.querySelector('#manage-options-button').addEventListener("click", function() { if (chrome.runtime.openOptionsPage) { // Supported (Chrome 42+) @@ -8,11 +11,7 @@ document.querySelector('#manage-options-button').addEventListener("click", funct } }); -document.querySelector('#manage-shortcuts-button').addEventListener("click", function() { - chrome.tabs.create({ - 'url': 'chrome://extensions/configureCommands' - }); -}); +document.querySelector('#manage-shortcuts-button').addEventListener("click", configureCommands.open); document.querySelector('#editor-styles-button').addEventListener("click", function() { chrome.tabs.create({ diff --git a/options/index.html b/options/index.html index a234d6fd..a27a1ddc 100644 --- a/options/index.html +++ b/options/index.html @@ -56,6 +56,7 @@ 2: , chrome://extensions/configureCommands + diff --git a/options/index.js b/options/index.js index 604c3211..9797bc35 100644 --- a/options/index.js +++ b/options/index.js @@ -1,3 +1,4 @@ +/* globals configureCommands */ 'use strict'; function restore () { @@ -88,8 +89,9 @@ document.addEventListener('click', e => { }); } else if (cmd === 'open-keyboard') { - chrome.tabs.create({ - url: 'chrome://extensions/configureCommands' - }); + configureCommands.open(); } }); +// overwrite the default URL if browser is Opera +document.querySelector('[data-cmd="open-keyboard"]').textContent = + configureCommands.url; diff --git a/popup.js b/popup.js index f96483e1..cfdda45f 100644 --- a/popup.js +++ b/popup.js @@ -1,3 +1,5 @@ +/* globals configureCommands */ + var writeStyleTemplate = document.createElement("a"); writeStyleTemplate.className = "write-style-link"; @@ -238,11 +240,7 @@ document.querySelector('#popup-options-button').addEventListener("click", functi } }); -document.querySelector('#popup-shortcuts-button').addEventListener("click", function() { - chrome.tabs.create({ - 'url': 'chrome://extensions/configureCommands' - }); -}); +document.querySelector('#popup-shortcuts-button').addEventListener("click", configureCommands.open); // popup width document.body.style.width = (localStorage.getItem('popupWidth') || '246') + 'px';