diff options
| -rw-r--r-- | js/background.js | 64 | ||||
| -rw-r--r-- | js/popup.js | 17 | ||||
| -rw-r--r-- | manifest.json | 2 | ||||
| -rw-r--r-- | popup.html | 4 | 
4 files changed, 80 insertions, 7 deletions
diff --git a/js/background.js b/js/background.js index 2f99793..e087c22 100644 --- a/js/background.js +++ b/js/background.js @@ -7,6 +7,7 @@ function log(msg) {  	}  }  log.enabled = false; +var enableNotifications=false;  var storageArea = chrome.storage.local;  //Redirects partitioned by request type, so we have to run through @@ -67,7 +68,7 @@ function checkRedirects(details) {  		return {};  	} - +	  	for (var i = 0; i < list.length; i++) {  		var r = list[i];  		var result = r.getMatch(details.url); @@ -91,8 +92,10 @@ function checkRedirects(details) {  			} -			log('Redirecting ' + details.url + ' ===> ' + result.redirectTo + ', type: ' + details.type + ', pattern: ' + r.includePattern); - +			log('Redirecting ' + details.url + ' ===> ' + result.redirectTo + ', type: ' + details.type + ', pattern: ' + r.includePattern + ' which is in Rule : ' + r.description); +			if(enableNotifications){ +				sendNotifications(r, details.url, result.redirectTo); +			}  			ignoreNextRequest[result.redirectTo] = new Date().getTime();  			return { redirectUrl: result.redirectTo }; @@ -126,7 +129,11 @@ function monitorChanges(changes, namespace) {      if (changes.logging) {          log('Logging settings have changed, updating...');          updateLogging(); -    } +	} +	if (changes.enableNotifications){ +		log('notifications setting changed'); +		enableNotifications=changes.enableNotifications.newValue; +	}  }  chrome.storage.onChanged.addListener(monitorChanges); @@ -342,6 +349,9 @@ chrome.storage.local.get({  //wrapped the below inside a function so that we can call this once we know the value of storageArea from above.   function setupInitial() { +	chrome.storage.local.get({enableNotifications:false},function(obj){ +		enableNotifications = obj.enableNotifications; +	});  	chrome.storage.local.get({  		disabled: false @@ -354,4 +364,48 @@ function setupInitial() {  	});  }  log('Redirector starting up...'); -       
\ No newline at end of file +	 +// Below is a feature request by an user who wished to see visual indication for an Redirect rule being applied on URL  +// https://github.com/einaregilsson/Redirector/issues/72 +// By default, we will have it as false. If user wishes to enable it from settings page, we can make it true until user disables it (or browser is restarted) + +// Upon browser startup, just set enableNotifications to false. +// Listen to a message from Settings page to change this to true. +function sendNotifications(redirect, originalUrl, redirectedUrl ){ +	//var message = "Applied rule : " + redirect.description + " and redirected original page " + originalUrl + " to " + redirectedUrl; +	log("Showing redirect success notification"); +	//Firefox and other browsers does not yet support "list" type notification like in Chrome. +	// Console.log(JSON.stringify(chrome.notifications)); -- This will still show "list" as one option but it just won't work as it's not implemented by Firefox yet +	// Can't check if "chrome" typeof either, as Firefox supports both chrome and browser namespace. +	// So let's use useragent.  +	// Opera UA has both chrome and OPR. So check against that ( Only chrome which supports list) - other browsers to get BASIC type notifications. + +	if(navigator.userAgent.toLowerCase().indexOf("chrome") > -1 && navigator.userAgent.toLowerCase().indexOf("OPR")<0){ +		var items = [{title:"Original page: ", message: originalUrl},{title:"Redirected to: ",message:redirectedUrl}]; +		var head = "Redirector - Applied rule : " + redirect.description; +		chrome.notifications.create({ +			"type": "list", +			"items": items, +			"title": head, +			"message": head, +			"iconUrl": "images/icon-active-38.png" +		  });	} +	else{ +		var message = "Applied rule : " + redirect.description + " and redirected original page " + originalUrl + " to " + redirectedUrl; + +		chrome.notifications.create({ +        	"type": "basic", +        	"title": "Redirector", +			"message": message, +			"iconUrl": "images/icon-active-38.png" +		}); +	} +} + +chrome.runtime.onStartup.addListener(handleStartup); +function handleStartup(){ +	enableNotifications=false; +	chrome.storage.local.set({ +		enableNotifications: false +	}); +}
\ No newline at end of file diff --git a/js/popup.js b/js/popup.js index 6658fc0..c27a29f 100644 --- a/js/popup.js +++ b/js/popup.js @@ -30,6 +30,23 @@ angular.module('popupApp', []).controller('PopupCtrl', ['$scope', function($s) {  		});  	}; +	 +	//Toggle Notifications by sending a notifications +	$s.enableNotifications = false;  +	 +	storage.get({enableNotifications:false},function(obj){ +		$s.enableNotifications = obj.enableNotifications; +		$s.$apply(); +	}); +	 +	$s.toggleNotifications=function(){ +		storage.get({enableNotifications:false},function(obj){ +		storage.set({enableNotifications:!obj.enableNotifications}); +			$s.enableNotifications = !obj.enableNotifications; +			$s.$apply(); +	}); +	} +  	$s.openRedirectorSettings = function() {  		//switch to open one if we have it to minimize conflicts diff --git a/manifest.json b/manifest.json index e3128f1..1325ba9 100644 --- a/manifest.json +++ b/manifest.json @@ -11,7 +11,7 @@                 "64": "images/icon-active-64.png",                "128": "images/icon-active-128.png" }, -  "permissions" : ["webRequest", "webRequestBlocking", "storage", "tabs", "http://*/*", "https://*/*"], +  "permissions" : ["webRequest", "webRequestBlocking", "storage", "tabs", "http://*/*", "https://*/*", "notifications"],    "applications": {      "gecko": { @@ -12,6 +12,8 @@  		<div class="disabled"><span ng-show="disabled">Disabled</span></div>  		<button ng-click="toggleDisabled()">{{disabled ? 'Enable Redirector' : 'Disable Redirector'}}</button>          <button ng-click="openRedirectorSettings()">Edit Redirects</button> -        <label><input type="checkbox" ng-model="logging" ng-click="toggleLogging()" /> Logging enabled</label> +		<label><input type="checkbox" ng-model="logging" ng-click="toggleLogging()" /> Logging enabled</label> +		<br/> +		<label><input type="checkbox" ng-model="enableNotifications" ng-click="toggleNotifications()" /> Enable Notifications</label>  	</body>  </html>  | 
