Skip to content

Commit

Permalink
fix: remove outdated longurl code
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 committed Dec 12, 2016
1 parent 0af105a commit d478d1e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -11,10 +11,10 @@ This extension removes the tracking ID before Chrome is performing the request,
(soon)

## Features
* amzn.to shortlinks are expanded via long URL and then processed
* Visual feedback which tag was removed
* Works on starting parameter (?tag) and appended parameter (&tag)
* Full support for all amazon sites (e.g. from Germany, Mexico or UK to China and Italy)
* amazn.to links are supported, too, since the expanded request to the amazon site is intercepted

## License
This plugin is released under the
Expand Down
32 changes: 3 additions & 29 deletions js/background.js
Expand Up @@ -20,8 +20,7 @@ const amazonURLs = [
'*://*.amazon.ie/*',
'*://*.amazon.in/*',
'*://*.amazon.it/*',
'*://*.amazon.nl/*',
'*://*.amzn.to/*'
'*://*.amazon.nl/*'
];

// Intercept requests from amazon
Expand All @@ -44,39 +43,14 @@ chrome.webNavigation.onCompleted.addListener(() => {
function interceptRequest(request) {
if (request && request.url) {
return {
redirectUrl: analyzeURL(request.url)
redirectUrl: sanitizeURL(request.url)
};
}
}

// If the URL is shortened use longurl to expand
function analyzeURL(url) {
if (url.indexOf('amzn.to') > -1) {
return expandURL(url);
} else {
return sanitizeURL(url);
}
}

// Expand URL via longurl.org
function expandURL(shortURL) {
shortURL = encodeURIComponent(shortURL);
let longURL = `http://api.longurl.org/v2/expand?${shortURL}&format=json&user-agent=Amazon-Tag-Remover%2v0.1`;
chrome.runtime.sendMessage({
method: 'GET',
action: 'xhttp',
url: longURL
}, responseText => {
if (responseText) {
let url = JSON.parse(responseText)['long-url'];
return sanitizeURL(url);
}
});
}

// Strip tag from URL
function sanitizeURL(url) {
url = decodeURIComponent(url);
url = decodeURIComponent(encodeURIComponent(url));
let matches = appendedRegex.exec(url);
if (matches) {
url = url.replace(appendedRegex, '');
Expand Down
3 changes: 1 addition & 2 deletions manifest.json
Expand Up @@ -54,8 +54,7 @@
"*://*.amazon.ie/*",
"*://*.amazon.in/*",
"*://*.amazon.it/*",
"*://*.amazon.nl/*",
"*://*.amzn.to/*"
"*://*.amazon.nl/*"
]
}

0 comments on commit d478d1e

Please sign in to comment.