diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/background.js | 32 | ||||
-rw-r--r-- | js/popup.js | 21 | ||||
-rw-r--r-- | js/redirect.js | 13 | ||||
-rw-r--r-- | js/redirectorpage.js | 2 | ||||
-rw-r--r-- | js/util.js | 6 |
5 files changed, 48 insertions, 26 deletions
diff --git a/js/background.js b/js/background.js index e74ae50..3c84b38 100644 --- a/js/background.js +++ b/js/background.js @@ -1,8 +1,8 @@ //This is the background script. It is responsible for actually redirecting requests, //as well as monitoring changes in the redirects and the disabled status and reacting to them. -function log(msg) { - if (log.enabled) { +function log(msg, force) { + if (log.enabled || force) { console.log('REDIRECTOR: ' + msg); } } @@ -127,12 +127,12 @@ function monitorChanges(changes, namespace) { } if (changes.logging) { - log('Logging settings have changed, updating...'); - updateLogging(); + log.enabled = changes.logging.newValue; + log('Logging settings have changed to ' + changes.logging.newValue, true); //Always want this to be logged... } if (changes.enableNotifications){ - log('notifications setting changed'); - enableNotifications=changes.enableNotifications.newValue; + log('notifications setting changed to ' + changes.enableNotifications.newValue); + enableNotifications = changes.enableNotifications.newValue; } } chrome.storage.onChanged.addListener(monitorChanges); @@ -201,7 +201,12 @@ function setUpRedirectListener() { function updateIcon() { chrome.storage.local.get({disabled:false}, function(obj) { - setIcon(obj.disabled ? 'icon-disabled' : 'icon-active'); + if (window.matchMedia('(prefers-color-scheme: dark)')) { + setIcon('icon-light'); + } else { + setIcon('icon-dark'); + } + //setIcon(obj.disabled ? 'icon-light' : 'icon-dark'); }); } @@ -327,12 +332,9 @@ chrome.runtime.onMessage.addListener( //First time setup updateIcon(); -function updateLogging() { - chrome.storage.local.get({logging:false}, function(obj) { - log.enabled = obj.logging; - }); -} -updateLogging(); +chrome.storage.local.get({logging:false}, function(obj) { + log.enabled = obj.logging; +}); chrome.storage.local.get({ isSyncEnabled: false @@ -388,7 +390,7 @@ function sendNotifications(redirect, originalUrl, redirectedUrl ){ "items": items, "title": head, "message": head, - "iconUrl": "images/icon-active-38.png" + "iconUrl": "images/icon-dark-38.png" }); } else{ var message = "Applied rule : " + redirect.description + " and redirected original page " + originalUrl + " to " + redirectedUrl; @@ -397,7 +399,7 @@ function sendNotifications(redirect, originalUrl, redirectedUrl ){ "type": "basic", "title": "Redirector", "message": message, - "iconUrl": "images/icon-active-38.png" + "iconUrl": "images/icon-dark-38.png" }); } } diff --git a/js/popup.js b/js/popup.js index 36d0685..8ac707c 100644 --- a/js/popup.js +++ b/js/popup.js @@ -15,10 +15,7 @@ function toggle(prop) { }); } -storage.get({logging:false, enableNotifications:false, disabled: false}, function(obj) { - viewModel = obj; - applyBinding(); -}) + function openRedirectorSettings() { @@ -41,3 +38,19 @@ function openRedirectorSettings() { }); return; }; + + +function pageLoad() { + storage.get({logging:false, enableNotifications:false, disabled: false}, function(obj) { + viewModel = obj; + applyBinding(); + }) + + el('#enable-notifications').addEventListener('input', () => toggle('enableNotifications')); + el('#enable-logging').addEventListener('input', () => toggle('logging')); + el('#toggle-disabled').addEventListener('click', () => toggle('disabled')); + el('#open-redirector-settings').addEventListener('click', openRedirectorSettings); +} + +pageLoad(); +//Setup page... diff --git a/js/redirect.js b/js/redirect.js index 3bdf0f0..dfc59aa 100644 --- a/js/redirect.js +++ b/js/redirect.js @@ -155,6 +155,10 @@ Redirect.prototype = { return; } + if (match.isMatch && !match.redirectTo.match(/^https?\:\/\//)) { + this.error = 'The redirect result must start with http:// or https://, current result is: "' + match.redirectTo + "."; + return; + } if (!match.isMatch) { this.error = 'The include pattern does not match the example url.'; return; @@ -241,6 +245,7 @@ Redirect.prototype = { noProcessing : 'Use matches as they are', urlEncode : 'E.g. turn /bar/foo?x=2 into %2Fbar%2Ffoo%3Fx%3D2', urlDecode : 'E.g. turn %2Fbar%2Ffoo%3Fx%3D2 into /bar/foo?x=2', + doubleUrlDecode : 'E.g. turn %252Fbar%252Ffoo%253Fx%253D2 into /bar/foo?x=2', base64Decode : 'E.g. turn aHR0cDovL2Nubi5jb20= into http://cnn.com' }; @@ -264,11 +269,11 @@ Redirect.prototype = { var repl = matches[i] || ''; if (this.processMatches == 'urlDecode') { repl = unescape(repl); - } - if (this.processMatches == 'urlEncode') { + } else if (this.processMatches == 'doubleUrlDecode') { + repl = unescape(unescape(repl)); + } else if (this.processMatches == 'urlEncode') { repl = encodeURIComponent(repl); - } - if (this.processMatches == 'base64decode') { + } else if (this.processMatches == 'base64decode') { if (repl.indexOf('%') > -1) { repl = unescape(repl); } diff --git a/js/redirectorpage.js b/js/redirectorpage.js index 379da96..fd5be8c 100644 --- a/js/redirectorpage.js +++ b/js/redirectorpage.js @@ -18,7 +18,7 @@ function saveChanges() { console.log(response.message); if(response.message.indexOf("Redirects failed to save") > -1){ showMessage(response.message, false); - }else{ + } else{ console.log('Saved ' + arr.length + ' redirects at ' + new Date() + '. Message from background page:' + response.message); } }); @@ -12,8 +12,10 @@ function dataBind(el, dataObject) { if (tag.tagName.toLowerCase() === 'input') { if (tag.getAttribute('type').toLowerCase() === 'radio') { tag.checked = dataObject[prop] === tag.getAttribute('value'); - } else { - tag.value = dataObject[prop]; + } else if (tag.getAttribute('type').toLowerCase() === 'checkbox') { + tag.checked = dataObject[prop]; + } else { + tag.value = dataObject[prop]; } } else if (tag.tagName.toLowerCase() === 'select') { for (let opt of tag.querySelectorAll('option')) { |