Skip to content

Commit

Permalink
feat: make extension compatible with Firefox and Edge
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 committed Feb 2, 2017
1 parent 6d83b5b commit 115e7cc
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 9 deletions.
3 changes: 3 additions & 0 deletions background.html
@@ -0,0 +1,3 @@
<html>
<script type="text/javascript" src="js/background.js"></script>
</html>
13 changes: 7 additions & 6 deletions js/background.js
@@ -1,6 +1,7 @@
'use strict';
let tag;

let tag;
const _browser = this.browser || this.chrome;
const appendedRegex = /&tag=\w+-\d{2}/g;
const leadingRegex = /\?tag=\w+-\d{2}/g;
const leadingRegexWithAppendix = /tag=\w+-\d{2}&/g;
Expand All @@ -24,12 +25,12 @@ const amazonURLs = [
];

// Intercept requests from amazon
chrome.webRequest.onBeforeRequest.addListener(interceptRequest, {
_browser.webRequest.onBeforeRequest.addListener(interceptRequest, {
'urls': amazonURLs
}, ['blocking']);

// When request is completed, render the box
chrome.webNavigation.onCompleted.addListener(() => {
_browser.webNavigation.onCompleted.addListener(() => {
if (tag) {
renderBox();
}
Expand Down Expand Up @@ -73,19 +74,19 @@ function sanitizeURL(url) {
}

function renderBox() {
chrome.tabs.query({
_browser.tabs.query({
active: true,
currentWindow: true
}, tabs => {
chrome.tabs.sendMessage(tabs[0].id, {
_browser.tabs.sendMessage(tabs[0].id, {
tag: tag
}, () => {
tag = undefined;
});
});

// add CSS
chrome.tabs.insertCSS({
_browser.tabs.insertCSS({
file: 'css/style.css'
});
}
4 changes: 3 additions & 1 deletion js/frontend.js
@@ -1,6 +1,8 @@
'use strict';

chrome.runtime.onMessage.addListener((request, sender, resetTag) => {
const _browser = this.browser || this.chrome;

_browser.runtime.onMessage.addListener((request, sender, resetTag) => {
const div = document.createElement('div');
div.className = 'amazon-tag-remover';
div.textContent = `The following tag was found and has been removed: ${request.tag}`;
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
@@ -1,9 +1,9 @@
{
"name": "Amazon Tag Remover",
"version": "0.1.1",
"version": "0.2.0",
"minimum_chrome_version": "45",
"manifest_version": 2,
"author": "Tim 'xGhOsTkiLLeRx' Brust",
"author": "Tim 'timbru31' Brust",
"description": "Remove the Amazon affiliate tracking ID (tag) from amazon links",
"background": {
"scripts": [
Expand Down
65 changes: 65 additions & 0 deletions manifest_edge.json
@@ -0,0 +1,65 @@
{
"name": "Amazon Tag Remover",
"version": "0.2.0",
"manifest_version": 2,
"author": "Tim 'timbru31' Brust",
"description": "Remove the Amazon affiliate tracking ID (tag) from amazon links",
"background": {
"page": "background.html",
"persistent": true
},
"content_scripts": [{
"matches": [
"*://*.amazon.at/*",
"*://*.amazon.ca/*",
"*://*.amazon.cn/*",
"*://*.amazon.co.jp/*",
"*://*.amazon.co.uk/*",
"*://*.amazon.com.au/*",
"*://*.amazon.com.br/*",
"*://*.amazon.com.mx/*",
"*://*.amazon.com/*",
"*://*.amazon.de/*",
"*://*.amazon.es/*",
"*://*.amazon.fr/*",
"*://*.amazon.ie/*",
"*://*.amazon.in/*",
"*://*.amazon.it/*",
"*://*.amazon.nl/*"
],
"js": [
"js/frontend.js"
]
}],
"permissions": [
"tabs",
"activeTab",
"webNavigation",
"webRequest",
"webRequestBlocking",
"*://*.amazon.at/*",
"*://*.amazon.ca/*",
"*://*.amazon.cn/*",
"*://*.amazon.co.jp/*",
"*://*.amazon.co.uk/*",
"*://*.amazon.com.au/*",
"*://*.amazon.com.br/*",
"*://*.amazon.com.mx/*",
"*://*.amazon.com/*",
"*://*.amazon.de/*",
"*://*.amazon.es/*",
"*://*.amazon.fr/*",
"*://*.amazon.ie/*",
"*://*.amazon.in/*",
"*://*.amazon.it/*",
"*://*.amazon.nl/*"
],
"icons": {
"16": "images/icon16.png",
"32": "images/icon32.png",
"48": "images/icon48.png",
"64": "images/icon64.png",
"128": "images/icon128.png"
},
"minimum_edge_version": "33.14281.1000.0"
}

0 comments on commit 115e7cc

Please sign in to comment.