Add Expand URL Feature
Now the Add-on can expand urls and directly redirect to the target url.
This commit is contained in:
		
							parent
							
								
									244642f82c
								
							
						
					
					
						commit
						c256461340
					
				
							
								
								
									
										96
									
								
								clearurls.js
									
									
									
									
									
								
							
							
						
						
									
										96
									
								
								clearurls.js
									
									
									
									
									
								
							|  | @ -23,7 +23,7 @@ function getKeys(obj){ | ||||||
|     for(var key in obj){ |     for(var key in obj){ | ||||||
|         prvKeys.push(key); |         prvKeys.push(key); | ||||||
|     } |     } | ||||||
| }; | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| * Initialize the providers form the JSON object. | * Initialize the providers form the JSON object. | ||||||
|  | @ -50,8 +50,14 @@ function createProviders() | ||||||
|         { |         { | ||||||
|             providers[p].addException(data.providers[prvKeys[p]].exceptions[e]); |             providers[p].addException(data.providers[prvKeys[p]].exceptions[e]); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         //Add redirections to provider
 | ||||||
|  |         for(var re = 0; re < data.providers[prvKeys[p]].redirections.length; re++) | ||||||
|  |         { | ||||||
|  |             providers[p].addRedirection(data.providers[prvKeys[p]].redirections[re]); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| * Convert the external data to JSON Objects and | * Convert the external data to JSON Objects and | ||||||
|  | @ -108,7 +114,7 @@ function fetchFromURL() | ||||||
|                 loadOldDataFromStore(); |                 loadOldDataFromStore(); | ||||||
|             } |             } | ||||||
|         }); |         }); | ||||||
|     }; |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // ##################################################################
 | // ##################################################################
 | ||||||
|  | @ -127,9 +133,10 @@ function fetchFromURL() | ||||||
| function Provider(_name,_completeProvider = false){ | function Provider(_name,_completeProvider = false){ | ||||||
|     var name = _name; |     var name = _name; | ||||||
|     var urlPattern; |     var urlPattern; | ||||||
|     var rules = new Array(); |     var rules = []; | ||||||
|     var exceptions = new Array(); |     var exceptions = []; | ||||||
|     var canceling = _completeProvider; |     var canceling = _completeProvider; | ||||||
|  |     var redirections = []; | ||||||
| 
 | 
 | ||||||
|     if(_completeProvider){ |     if(_completeProvider){ | ||||||
|         rules.push(".*"); |         rules.push(".*"); | ||||||
|  | @ -170,14 +177,6 @@ function Provider(_name,_completeProvider = false){ | ||||||
|         rules.push(rule); |         rules.push(rule); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|     * Set the rules for the provider |  | ||||||
|     * @param String _rules RegEx as string |  | ||||||
|     */ |  | ||||||
|     this.setRules = function(_rules) { |  | ||||||
|         rules = _rules; |  | ||||||
|     }; |  | ||||||
| 
 |  | ||||||
|     /** |     /** | ||||||
|     * Return all rules as an array. |     * Return all rules as an array. | ||||||
|     * |     * | ||||||
|  | @ -217,6 +216,38 @@ function Provider(_name,_completeProvider = false){ | ||||||
| 
 | 
 | ||||||
|         return result; |         return result; | ||||||
|     }; |     }; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Add a redirection to the redirections array. | ||||||
|  |     * | ||||||
|  |     * @param String redirection   RegExp as string | ||||||
|  |     */ | ||||||
|  |     this.addRedirection = function(redirection) { | ||||||
|  |         redirections.push(redirection); | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |     * Return all redirection. | ||||||
|  |     * | ||||||
|  |     * @return url | ||||||
|  |     */ | ||||||
|  |     this.getRedirection = function(url) { | ||||||
|  |         var re = null; | ||||||
|  | 
 | ||||||
|  |         for(var i = 0; i < redirections.length; i++) | ||||||
|  |         { | ||||||
|  |             result = (url.match(new RegExp(redirections[i], "gi"))); | ||||||
|  | 
 | ||||||
|  |             if (result && result.length > 0) | ||||||
|  |             { | ||||||
|  |                 re = (new RegExp(redirections[i], "gi")).exec(url)[1]; | ||||||
|  | 
 | ||||||
|  |                 break; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return re; | ||||||
|  |     }; | ||||||
| } | } | ||||||
| // ##################################################################
 | // ##################################################################
 | ||||||
| 
 | 
 | ||||||
|  | @ -237,6 +268,21 @@ function removeFieldsFormURL(provider, request) | ||||||
| 
 | 
 | ||||||
|     if(provider.matchURL(url)) |     if(provider.matchURL(url)) | ||||||
|     { |     { | ||||||
|  |         /* | ||||||
|  |          * Expand the url by provider redirections. So no tracking on | ||||||
|  |          * url redirections form sites to sites. | ||||||
|  |          */ | ||||||
|  |         var re = provider.getRedirection(url); | ||||||
|  |         if(re !== null) | ||||||
|  |         { | ||||||
|  |             url = decodeURIComponent(re); | ||||||
|  | 
 | ||||||
|  |             return { | ||||||
|  |                 "redirect": true, | ||||||
|  |                 "url": url | ||||||
|  |             }; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         for (var i = 0; i < rules.length; i++) { |         for (var i = 0; i < rules.length; i++) { | ||||||
|             var bevorReplace = url; |             var bevorReplace = url; | ||||||
| 
 | 
 | ||||||
|  | @ -285,8 +331,8 @@ function removeFieldsFormURL(provider, request) | ||||||
|         "changes": changes, |         "changes": changes, | ||||||
|         "url": url, |         "url": url, | ||||||
|         "cancel": cancel |         "cancel": cancel | ||||||
|     } |  | ||||||
|     }; |     }; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| * Return the number of parameters query strings. | * Return the number of parameters query strings. | ||||||
|  | @ -365,7 +411,9 @@ function clearUrl(request) | ||||||
| 
 | 
 | ||||||
|             var result = { |             var result = { | ||||||
|                 "changes": false, |                 "changes": false, | ||||||
|                 "url": "" |                 "url": "", | ||||||
|  |                 "redirect": false, | ||||||
|  |                 "cancel": false | ||||||
|             }; |             }; | ||||||
| 
 | 
 | ||||||
|             /* |             /* | ||||||
|  | @ -374,11 +422,21 @@ function clearUrl(request) | ||||||
|             for (var i = 0; i < providers.length; i++) { |             for (var i = 0; i < providers.length; i++) { | ||||||
|                 result = removeFieldsFormURL(providers[i], request); |                 result = removeFieldsFormURL(providers[i], request); | ||||||
| 
 | 
 | ||||||
|  |                 /* | ||||||
|  |                  * Expand urls and bypass tracking. | ||||||
|  |                  * Cancel the active request. | ||||||
|  |                  */ | ||||||
|  |                 if(result.redirect) | ||||||
|  |                 { | ||||||
|  |                     browser.tabs.update(request.tabId, {url: result.url}); | ||||||
|  |                     return {cancel: true}; | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|                 /* |                 /* | ||||||
|                 * Cancel the Request and redirect to the site blocked alert page, |                 * Cancel the Request and redirect to the site blocked alert page, | ||||||
|                 * to inform the user about the full url blocking. |                 * to inform the user about the full url blocking. | ||||||
|                 */ |                 */ | ||||||
|                 if(result["cancel"]){ |                 if(result.cancel){ | ||||||
|                     return { |                     return { | ||||||
|                         redirectUrl: siteBlockedAlert |                         redirectUrl: siteBlockedAlert | ||||||
|                     }; |                     }; | ||||||
|  | @ -388,15 +446,15 @@ function clearUrl(request) | ||||||
|                 * Ensure that the function go not into |                 * Ensure that the function go not into | ||||||
|                 * an loop. |                 * an loop. | ||||||
|                 */ |                 */ | ||||||
|                 if(result["changes"]){ |                 if(result.changes){ | ||||||
|                     return { |                     return { | ||||||
|                         redirectUrl: result["url"] |                         redirectUrl: result.url | ||||||
|                     }; |                     }; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| }; | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| * Call by each tab is closed. | * Call by each tab is closed. | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user