Skip to content

Commit

Permalink
refactor: negate disabling notifications
Browse files Browse the repository at this point in the history
fix: amazon.com.tr support
  • Loading branch information
timbru31 committed Jan 13, 2019
1 parent 257f27a commit 9fc87c0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 45 deletions.
11 changes: 7 additions & 4 deletions src/js/background.ts
@@ -1,7 +1,7 @@
// tslint:disable-next-line:variable-name
const _browser = chrome || browser;
let tags: string[] = [];
let amazonTagRemoverNotification: string = 'amazon-tag-remover-notification';
const amazonTagRemoverNotification = 'amazon-tag-remover-notification';
const amazonURLs = [
'*://*.amazon.at/*',
'*://*.amazon.ca/*',
Expand All @@ -11,6 +11,7 @@ const amazonURLs = [
'*://*.amazon.com.au/*',
'*://*.amazon.com.br/*',
'*://*.amazon.com.mx/*',
'*://*.amazon.com.tr/*',
'*://*.amazon.com/*',
'*://*.amazon.de/*',
'*://*.amazon.es/*',
Expand All @@ -20,6 +21,7 @@ const amazonURLs = [
'*://*.amazon.it/*',
'*://*.amazon.nl/*'
];
const storage = _browser.storage.sync || _browser.storage.local;

_browser.webRequest.onBeforeRequest.addListener(
interceptRequest,
Expand All @@ -31,8 +33,8 @@ _browser.webRequest.onBeforeRequest.addListener(
_browser.webNavigation.onCompleted.addListener(
() => {
if (tags && tags.length) {
const enableNotifications = _browser.storage.local.get('enableNotifications', (item: any) => {
if (item.enableNotifications) {
storage.get('disableNotifications', (item: any) => {
if (!item.disableNotifications) {
_browser.notifications.create(amazonTagRemoverNotification, {
iconUrl: _browser.extension.getURL('images/icon64.png'),
message: `The following tags were found and have been removed: ${tags}`,
Expand All @@ -41,12 +43,13 @@ _browser.webNavigation.onCompleted.addListener(
});
}
});
tags = [];
}
},
{
url: [
{
urlMatches: 'https?://w*.?amazon.(at|ca|cn|co.jp|co.uk|com.au|com.br|com.mx|com|de|es|fr|ie|in|it|nl)/w*'
urlMatches: 'https?://w*.?amazon.(at|ca|cn|co.jp|co.uk|com.au|com.br|com.mx|com.tr|com|de|es|fr|ie|in|it|nl)/w*'
}
]
}
Expand Down
10 changes: 6 additions & 4 deletions src/js/options.ts
@@ -1,19 +1,21 @@
// tslint:disable-next-line:variable-name
const __browser = chrome || browser;
// tslint:disable-next-line:variable-name
const _storage = __browser.storage.sync || __browser.storage.local;

function saveOptions(e: Event) {
e.preventDefault();
__browser.storage.local.set({
enableNotifications: document.querySelector<HTMLInputElement>('#enable-notifications')!.checked
_storage.set({
disableNotifications: document.querySelector<HTMLInputElement>('#disable-notifications')!.checked
});
}

function restoreOptions() {
function setCurrentChoice(result: any) {
document.querySelector<HTMLInputElement>('#enable-notifications')!.checked = result.enableNotifications;
document.querySelector<HTMLInputElement>('#disable-notifications')!.checked = result.disableNotifications;
}

__browser.storage.local.get('enableNotifications', setCurrentChoice);
_storage.get('disableNotifications', setCurrentChoice);
}

document.addEventListener('DOMContentLoaded', restoreOptions);
Expand Down
25 changes: 2 additions & 23 deletions src/manifest.json
@@ -1,35 +1,13 @@
{
"name": "Amazon Tag Remover",
"version": "0.4.0",
"minimum_chrome_version": "62",
"minimum_chrome_version": "67",
"manifest_version": 2,
"author": "Tim 'timbru31' Brust",
"description": "Remove the Amazon affiliate tracking ID (tag) from amazon links",
"background": {
"scripts": ["js/background.js"]
},
"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/*"
]
}
],
"options_ui": {
"page": "options.html"
},
Expand All @@ -49,6 +27,7 @@
"*://*.amazon.com.au/*",
"*://*.amazon.com.br/*",
"*://*.amazon.com.mx/*",
"*://*.amazon.com.tr/*",
"*://*.amazon.com/*",
"*://*.amazon.de/*",
"*://*.amazon.es/*",
Expand Down
25 changes: 11 additions & 14 deletions src/options.html
@@ -1,18 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>

<head>
<meta charset="utf-8">
</head>

<body>
<form>
<label>Show notifications: <input type="checkbox" id="enable-notifications" checked></label>
<br>
<br>
<button type="submit">Save</button>
</form>
<script src="js/options.js"></script>
</body>

<body>
<form>
<label>Disable notifications: <input type="checkbox" id="disable-notifications"/></label> <br />
<br />
<button type="submit">Save</button>
</form>
<script src="js/options.js"></script>
</body>
</html>

0 comments on commit 9fc87c0

Please sign in to comment.