Skip to content

Commit

Permalink
Neat URL 4.1.0-webext:
Browse files Browse the repository at this point in the history
* Add source@sourceforge.net, position@sourceforge.net, callback@bilibili.com, fixes #116
* Fix #97 revert counter color to default color
* Add eloqua tracking parameters #105
* Exception support #111
* Fix Neat URL breaks Google Product Forums #122
* Add ref, tag@amazon.*, ref_@amazon.* and pf_rd_*@amazon.* by default (fixes #118 #120 #125)
* Drop pd_rd_r@amazon.*, pd_rd_w@amazon.*, pd_rd_wg@amazon.* in favor of pd_rd_*@amazon.* (including automatic upgrade path)
  • Loading branch information
Smile4ever committed Apr 17, 2018
1 parent 325dffb commit 5329da7
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 25 deletions.
10 changes: 10 additions & 0 deletions Neat URL-webext/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
4.1.0
=====
* Add source@sourceforge.net, position@sourceforge.net, callback@bilibili.com, fixes #116
* Fix #97 revert counter color to default color
* Add eloqua tracking parameters #105
* Exception support #111
* Fix Neat URL breaks Google Product Forums #122
* Add ref, tag@amazon.*, ref_@amazon.* and pf_rd_*@amazon.* by default (fixes #118 #120 #125)
* Drop pd_rd_r@amazon.*, pd_rd_w@amazon.*, pd_rd_wg@amazon.* in favor of pd_rd_*@amazon.* (including automatic upgrade path)

4.0.1
=====
* Fix ending parameters not detected when there are no query or hash parameters
Expand Down
2 changes: 2 additions & 0 deletions Neat URL-webext/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ TODO
====

* Implement recursion (example.com?url=example2.com%3Futm%3Dsomething)
* Implement color support for textarea if reliable
* Implement resetParameters
4 changes: 4 additions & 0 deletions Neat URL-webext/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"message": "Default value: main_frame. This list is comma-separated. Valid values can be found in the <a href='https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/ResourceType' target='_blank'>the list of resource types</a>.",
"description": "Please leave the link intact. You can translate the normal text and the text 'the list of resource types'. The link must not be changed. main_frame must also stay the same."
},
"counter_default_color": {
"message": "Use the default counter color",
"description": ""
},
"savepreferences": {
"message": "Save preferences",
"description": ""
Expand Down
4 changes: 4 additions & 0 deletions Neat URL-webext/_locales/nl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"message": "Standaardwaarde: main_frame. Deze lijst is kommagescheiden. Geldige waardees kunnen gevonden worden in <a href='https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/ResourceType' target='_blank'>de lijst van aanvraagtypes</a>.",
"description": "Please leave the link intact. You can translate the normal text and the text 'the list of resource types'. The link must not be changed. main_frame must also stay the same."
},
"counter_default_color": {
"message": "Gebruik de standaard achtergrondkleur voor de teller",
"description": ""
},
"savepreferences": {
"message": "Voorkeuren opslaan",
"description": ""
Expand Down
4 changes: 4 additions & 0 deletions Neat URL-webext/_locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"message": "Значение по умолчанию: main_frame. Этот список разделен запятыми. Допустимые значения можно найти здесь: <a href='https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/ResourceType' target='_blank'>the list of resource types</a>.",
"description": "Please leave the link intact. You can translate the normal text and the text 'the list of resource types'. The link must not be changed. main_frame must also stay the same."
},
"counter_default_color": {
"message": "Use the default counter color",
"description": ""
},
"savepreferences": {
"message": "Сохранить настройки",
"description": ""
Expand Down
4 changes: 4 additions & 0 deletions Neat URL-webext/_locales/uk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"message": "Значення за замовчуванням: main_frame. Цей список розділено комами. Допустимі значення можна знайти тут: <a href='https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/ResourceType' target='_blank'>the list of resource types</a>.",
"description": "Please leave the link intact. You can translate the normal text and the text 'the list of resource types'. The link must not be changed. main_frame must also stay the same."
},
"counter_default_color": {
"message": "Use the default counter color",
"description": ""
},
"savepreferences": {
"message": "Зберегти налаштування",
"description": ""
Expand Down
4 changes: 4 additions & 0 deletions Neat URL-webext/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"message": "默认值:main_frame。此列表以逗号分隔。有效值见<a href='https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/ResourceType' target='_blank'>资源类型列表</a>。",
"description": "Please leave the link intact. You can translate the normal text and the text 'the list of resource types'. The link must not be changed. main_frame must also stay the same."
},
"counter_default_color": {
"message": "Use the default counter color",
"description": ""
},
"savepreferences": {
"message": "保存设置",
"description": ""
Expand Down
72 changes: 51 additions & 21 deletions Neat URL-webext/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// * https://github.com/Smile4ever/firefoxaddons/issues/43

/// Static variables
let defaultGlobalBlockedParams = "utm_source, utm_medium, utm_term, utm_content, utm_campaign, utm_reader, utm_place, utm_userid, utm_cid, utm_name, utm_pubreferrer, utm_swu, utm_viz_id, ga_source, ga_medium, ga_term, ga_content, ga_campaign, ga_place, yclid, _openstat, fb_action_ids, fb_action_types, fb_ref, fb_source, action_object_map, action_type_map, action_ref_map, gs_l, pd_rd_r@amazon.*, pd_rd_w@amazon.*, pd_rd_wg@amazon.*, _encoding@amazon.*, psc@amazon.*, ved@google.*, ei@google.*, sei@google.*, gws_rd@google.*, cvid@bing.com, form@bing.com, sk@bing.com, sp@bing.com, sc@bing.com, qs@bing.com, pq@bing.com, feature@youtube.com, gclid@youtube.com, kw@youtube.com, $/ref@amazon.*, _hsenc, mkt_tok, hmb_campaign, hmb_medium, hmb_source";
let defaultGlobalBlockedParams = "utm_source, utm_medium, utm_term, utm_content, utm_campaign, utm_reader, utm_place, utm_userid, utm_cid, utm_name, utm_pubreferrer, utm_swu, utm_viz_id, ga_source, ga_medium, ga_term, ga_content, ga_campaign, ga_place, yclid, _openstat, fb_action_ids, fb_action_types, fb_ref, fb_source, action_object_map, action_type_map, action_ref_map, gs_l, pd_rd_*@amazon.*, _encoding@amazon.*, psc@amazon.*, ved@google.*, ei@google.*, sei@google.*, gws_rd@google.*, cvid@bing.com, form@bing.com, sk@bing.com, sp@bing.com, sc@bing.com, qs@bing.com, pq@bing.com, feature@youtube.com, gclid@youtube.com, kw@youtube.com, $/ref@amazon.*, _hsenc, mkt_tok, hmb_campaign, hmb_medium, hmb_source, source@sourceforge.net, position@sourceforge.net, callback@bilibili.com, elqTrackId, elqTrack, assetType, assetId, recipientId, campaignId, siteId, ref, tag@amazon.*, ref_@amazon.*, pf_rd_*@amazon.*";
let defaultRequestTypes = "main_frame";
let defaultBlacklist = ""; // google-analytics.com, sb.scorecardresearch.com, doubleclick.net, beacon.krxd.net"

Expand Down Expand Up @@ -57,7 +57,8 @@ function init(){
"neat_url_counter_color",
"neat_url_logging",
"neat_url_blacklist",
"neat_url_types"
"neat_url_types",
"neat_url_counter_default_color"
]).then((result) => {
neat_url_blocked_params = valueOrDefaultArray(result.neat_url_blocked_params, defaultGlobalBlockedParams);
neat_url_icon_animation = valueOrDefault(result.neat_url_icon_animation, "missing_underscore");
Expand All @@ -67,8 +68,22 @@ function init(){
neat_url_logging = valueOrDefault(result.neat_url_logging, false);
neat_url_blacklist = valueOrDefaultArray(result.neat_url_blacklist, defaultBlacklist);
neat_url_types = valueOrDefaultArray(result.neat_url_types, defaultRequestTypes);
neat_url_counter_default_color = valueOrDefault(result.neat_url_counter_default_color, true); // true as default

browser.browserAction.setBadgeBackgroundColor({color: neat_url_counter_color});
// Upgrade configuration from old releases
if(neat_url_counter_default_color == null && neat_url_counter_color == "#eeeeee"){
// Update counter_color to null
browser.storage.local.set({ neat_url_counter_color: null });

// Update counter_default_color to true
browser.storage.local.set({ neat_url_counter_default_color: true }); // not strictly needed, but this shouldn't hurt either

// Do not use any color
neat_url_counter_default_color = true;
}

if(!neat_url_counter_default_color)
browser.browserAction.setBadgeBackgroundColor({color: neat_url_counter_color});

// Re-initialise listener, hopefully fixes https://github.com/Smile4ever/firefoxaddons/issues/92
browser.webRequest.onBeforeRequest.removeListener(cleanURL);
Expand Down Expand Up @@ -138,7 +153,7 @@ function initBrowserAction(){
/// Translate Now / Neat URL code
function initContextMenus(){
browser.contextMenus.onClicked.removeListener(listener);
browser.contextMenus.removeAll();
browser.contextMenus.removeAll().catch(null);

createContextMenu("neaturl-tb-preferences", "Preferences", ["browser_action"]);
browser.contextMenus.onClicked.addListener(listener);
Expand Down Expand Up @@ -185,20 +200,17 @@ function upgradeParametersIfNeeded(){
if(neat_url_blocked_params.indexOf(defaultParam) == -1){
if(neat_url_hidden_params.indexOf(defaultParam) == -1){
//console.log("[Neat URL]: Adding parameter " + defaultParam + " during upgrade.");
if(defaultParam == "pd_rd_*@amazon.*"){
neat_url_blocked_params = removeFromArray(neat_url_blocked_params, "pd_rd_r@amazon.*");
neat_url_blocked_params = removeFromArray(neat_url_blocked_params, "pd_rd_w@amazon.*");
neat_url_blocked_params = removeFromArray(neat_url_blocked_params, "pd_rd_wg@amazon.*");
}
neat_url_blocked_params.push(defaultParam);
changes = true;
}
}
}

if(oldVersion == "1.0.1" || oldVersion == "1.1.0" || oldVersion == "1.2.0"){
// add gs_l parameter
if(neat_url_blocked_params.indexOf("gs_l") == -1){
neat_url_blocked_params.push("gs_l");
changes = true;
}
}

if(changes){
browser.storage.local.set({"neat_url_blocked_params": neat_url_blocked_params.join(', ')})
}
Expand All @@ -208,6 +220,14 @@ function upgradeParametersIfNeeded(){
}
}

function removeFromArray(array, item){
var index = array.indexOf(item);
if (index > -1) {
array.splice(index, 1);
}
return array;
}

/// Neat URL code
function removeEndings(leanURL, blockedParams){
let isSearch = leanURL.search == "" ? false : true ;
Expand Down Expand Up @@ -306,8 +326,8 @@ function buildURL(url, blockedParams, hashParams) {

/// Replace hash params
let hashUrl = new URL(url.href);
hashUrl.search = hashUrl.hash.replace('#', '');
hashUrl.hash = '';
hashUrl.search = hashUrl.hash.replace('#', '');
hashUrl.hash = '';

let searchParamsBefore = hashUrl.href;

Expand All @@ -323,24 +343,23 @@ function buildURL(url, blockedParams, hashParams) {
// #?utm_source
// Example URL: http://www.cuisineactuelle.fr/recettes/mini-burgers-au-foie-gras-331523#utm_source=Facebook&utm_medium=social&utm_campaign=PassionApero
if (hashParam.startsWith('#?')) {
let specialHashParam = hashParam.replace('#?', '');
if(neat_url_logging) console.log("[Neat URL]: buildURL - found hash parameter " + hashParam);
let specialHashParam = hashParam.replace('#?', '');
if(neat_url_logging) console.log("[Neat URL]: buildURL - found hash parameter " + hashParam);

// Wildcard support :)
// utm_*
let wildcardParam = getWildcardParam(specialHashParam);
if(wildcardParam != "") hashUrl = deleteWildcardParam(wildcardParam, hashUrl);

// utm_source
hashUrl.searchParams.delete(specialHashParam);
}
hashUrl.searchParams.delete(specialHashParam);
}
}

// Stringify from URL object adds = to the other parameters without value, sadly.
// In most cases this won't be a problem, if it is there will be bugs about it
// Workaround to above issue: only use the new value if the length is less now
// Also account for re-encoding by specifying one occurence of "="
if(searchParamsBefore.length + 1 != hashUrl.href.length){
// Workaround to above encoding issue: only use the new value if the length is less now
if(new URL(searchParamsBefore).length > new URL(hashUrl.href).length){
const newHash = hashUrl.search.replace('?', '');
url.hash = newHash ? `#${newHash}` : '';
}
Expand Down Expand Up @@ -448,6 +467,7 @@ function cleanURL(details) {

let blockedParams = [];
let hashParams = [];
let excludeParams = [];

for (let gbp of neat_url_blocked_params) {
let match = getMatch(gbp, domain, rootDomain, domainMinusSuffix, url);
Expand All @@ -458,9 +478,19 @@ function cleanURL(details) {
hashParams.push(match);
continue;
}

// Excludes
if(match.startsWith("!")){
excludeParams.push(match);
continue;
}

blockedParams.push(match);
}

for(let excludeParam of excludeParams){
blockedParams = removeFromArray(blockedParams, excludeParam.replace("!", ""));
}

//! ?a=1&a=2 is valid
// keys must be removed in reverse,
Expand Down
2 changes: 1 addition & 1 deletion Neat URL-webext/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "__MSG_extensionDescription__",
"homepage_url": "http://hugsmile.eu",
"manifest_version": 2,
"version": "4.0.1",
"version": "4.1.0",
"default_locale": "en",
"background": {
"scripts": ["background.js", "toolbaricon.js"]
Expand Down
2 changes: 1 addition & 1 deletion Neat URL-webext/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
<label><span data-i18n="counter_background_color">Counter background color</span></label><div class="descr" data-i18n="counter_background_color_descr">The background color used by the counter</div>
</div>
<div>
<div><input type="checkbox" id="neat_url_counter_default_color"><label for="neat_url_counter_default_color"><span data-i18n="counter_default_color">Use the default counter color</span></label></div>
<div><input type="color" id="neat_url_counter_color"><label for="neat_url_logging"><span data-i18n="counter_background_color">Counter background color</span></label></div>
</div>
<div>
Expand Down Expand Up @@ -233,6 +234,5 @@ <h2 data-i18n="advanced">Advanced</h2>
</form>

<script src="options.js" defer></script>

</body>
</html>
11 changes: 9 additions & 2 deletions Neat URL-webext/options.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const PREFS = {
"neat_url_blocked_params": {
"type": "value",
"default": "utm_source, utm_medium, utm_term, utm_content, utm_campaign, utm_reader, utm_place, utm_userid, utm_cid, utm_name, utm_pubreferrer, utm_swu, utm_viz_id, ga_source, ga_medium, ga_term, ga_content, ga_campaign, ga_place, yclid, _openstat, fb_action_ids, fb_action_types, fb_ref, fb_source, action_object_map, action_type_map, action_ref_map, gs_l, pd_rd_r@amazon.*, pd_rd_w@amazon.*, pd_rd_wg@amazon.*, _encoding@amazon.*, psc@amazon.*, ved@google.*, ei@google.*, sei@google.*, gws_rd@google.*, cvid@bing.com, form@bing.com, sk@bing.com, sp@bing.com, sc@bing.com, qs@bing.com, pq@bing.com, feature@youtube.com, gclid@youtube.com, kw@youtube.com, $/ref@amazon.*, _hsenc, mkt_tok, hmb_campaign, hmb_medium, hmb_source"
"default": "utm_source, utm_medium, utm_term, utm_content, utm_campaign, utm_reader, utm_place, utm_userid, utm_cid, utm_name, utm_pubreferrer, utm_swu, utm_viz_id, ga_source, ga_medium, ga_term, ga_content, ga_campaign, ga_place, yclid, _openstat, fb_action_ids, fb_action_types, fb_ref, fb_source, action_object_map, action_type_map, action_ref_map, gs_l, pd_rd_*@amazon.*, _encoding@amazon.*, psc@amazon.*, ved@google.*, ei@google.*, sei@google.*, gws_rd@google.*, cvid@bing.com, form@bing.com, sk@bing.com, sp@bing.com, sc@bing.com, qs@bing.com, pq@bing.com, feature@youtube.com, gclid@youtube.com, kw@youtube.com, $/ref@amazon.*, _hsenc, mkt_tok, hmb_campaign, hmb_medium, hmb_source, source@sourceforge.net, position@sourceforge.net, callback@bilibili.com, elqTrackId, elqTrack, assetType, assetId, recipientId, campaignId, siteId, ref, tag@amazon.*, ref_@amazon.*, pf_rd_*@amazon.*"
},
"neat_url_icon_animation": {
"type": "value",
Expand Down Expand Up @@ -31,6 +31,10 @@ const PREFS = {
"type": "value",
"default": "main_frame"
},
"neat_url_counter_default_color": {
"type": "checked",
"default": true
},
"neat_url_version": {
"type": "value",
"default": ""
Expand All @@ -44,9 +48,11 @@ var lastWidth = 0;

function getClean(text){
let clean = text.split(",");

for(let i = 0; i < clean.length; i++){
clean[i] = clean[i].trim();
}

return clean;
}

Expand Down Expand Up @@ -74,12 +80,13 @@ function saveOptions() {
}
}

document.getElementById("neat_url_blocked_params").value = currentParams.join(", ");
//document.getElementById("neat_url_blocked_params").value = currentParams.join(", ");
document.getElementById("neat_url_hidden_params").value = newHiddenParams.join(", ");

const values = {};
for(let p in PREFS) {
values[p] = document.getElementById(p)[PREFS[p].type];
if(p == "neat_url_blocked_params") values[p] = currentParams.join(", "); //formatting
}

browser.storage.local.set(values).then(() => {
Expand Down
Binary file not shown.

0 comments on commit 5329da7

Please sign in to comment.