From 31f1b675bf738f5905bf3f9e7dccf9515a471ec2 Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Thu, 12 Dec 2019 10:52:54 +0000 Subject: Fix messages --- js/background.js | 8 ++++---- js/redirectorpage.js | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'js') diff --git a/js/background.js b/js/background.js index a3b5da3..89118d0 100644 --- a/js/background.js +++ b/js/background.js @@ -290,13 +290,13 @@ chrome.runtime.onMessage.addListener( // Call setupRedirectListener to setup the redirects setUpRedirectListener(); sendResponse({ - message: "syncEnabled" + message: "sync-enabled" }); }); } else { log('No redirects are setup currently in Local, just enabling Sync'); sendResponse({ - message: "syncEnabled" + message: "sync-enabled" }); } }); @@ -316,12 +316,12 @@ chrome.runtime.onMessage.addListener( // Call setupRedirectListener to setup the redirects setUpRedirectListener(); sendResponse({ - message: "syncDisabled" + message: "sync-disabled" }); }); } else { sendResponse({ - message: "syncDisabled" + message: "sync-disabled" }); } }); diff --git a/js/redirectorpage.js b/js/redirectorpage.js index 482838f..ee2eec0 100644 --- a/js/redirectorpage.js +++ b/js/redirectorpage.js @@ -14,7 +14,7 @@ function saveChanges() { // Clean them up so angular $$hash things and stuff don't get serialized. let arr = REDIRECTS.map(normalize); - chrome.runtime.sendMessage({type:"saveredirects", redirects:arr}, function(response) { + chrome.runtime.sendMessage({type:"save-redirects", redirects:arr}, function(response) { console.log(response.message); if(response.message.indexOf("Redirects failed to save") > -1){ showMessage(response.message, false); @@ -41,7 +41,7 @@ function toggleSyncSetting() { } else { alert(response.message) - showMessage('Error occured when trying to change Sync settings. Refer logging and raise an issue',false); + showMessage('Error occured when trying to change Sync settings. Look at the logs and raise an issue',false); } el('#storage-sync-option').checked = options.isSyncEnabled; }); @@ -146,6 +146,28 @@ function pageLoad() { for (var i=0; i < response.redirects.length; i++) { REDIRECTS.push(new Redirect(response.redirects[i])); } + + if (response.redirects.length === 0) { + //Add example redirect for first time users... + REDIRECTS.push(new Redirect( + { + "description": "Example redirect, try going to http://example.com/anywordhere", + "exampleUrl": "http://example.com/some-word-that-matches-wildcard", + "exampleResult": "https://google.com/search?q=some-word-that-matches-wildcard", + "error": null, + "includePattern": "http://example.com/*", + "excludePattern": "", + "patternDesc": "Any word after example.com leads to google search for that word.", + "redirectUrl": "https://google.com/search?q=$1", + "patternType": "W", + "processMatches": "noProcessing", + "disabled": false, + "appliesTo": [ + "main_frame" + ] + } + )); + } renderRedirects(); }); -- cgit v1.2.3