Skip to content

Commit

Permalink
Merge pull request #62 from Jackymancs4-Fork/master
Browse files Browse the repository at this point in the history
Add native notification, options page and minor app refactoring.
  • Loading branch information
timbru31 committed Jan 13, 2019
2 parents 12fcde6 + bb8ceb1 commit 257f27a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 91 deletions.
40 changes: 0 additions & 40 deletions src/css/style.css

This file was deleted.

47 changes: 13 additions & 34 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 amazonURLs = [
'*://*.amazon.at/*',
'*://*.amazon.ca/*',
Expand All @@ -28,11 +28,19 @@ _browser.webRequest.onBeforeRequest.addListener(
},
['blocking']
);

_browser.webNavigation.onCompleted.addListener(
() => {
if (tags && tags.length) {
renderBox();
const enableNotifications = _browser.storage.local.get('enableNotifications', (item: any) => {
if (item.enableNotifications) {
_browser.notifications.create(amazonTagRemoverNotification, {
iconUrl: _browser.extension.getURL('images/icon64.png'),
message: `The following tags were found and have been removed: ${tags}`,
title: 'Amazon Tag Remover',
type: 'basic'
});
}
});
}
},
{
Expand All @@ -48,9 +56,7 @@ function interceptRequest(request: chrome.webRequest.WebRequestBodyDetails) {
if (request && request.url) {
const sanitizedResult = sanitizeURL(request.url);
if (sanitizedResult.match) {
return {
redirectUrl: sanitizedResult.url
};
return { redirectUrl: sanitizedResult.url };
}
}
}
Expand All @@ -69,32 +75,5 @@ function sanitizeURL(urlString: string) {
}
searchParams.delete('tag');
searchParams.delete('ascsubtag');
return {
match,
url: url.toString()
};
}

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

_browser.tabs.insertCSS({
file: 'css/style.css'
});
return { match, url: url.toString() };
}
15 changes: 0 additions & 15 deletions src/js/frontend.ts

This file was deleted.

20 changes: 20 additions & 0 deletions src/js/options.ts
@@ -0,0 +1,20 @@
// tslint:disable-next-line:variable-name
const __browser = chrome || browser;

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

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

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

document.addEventListener('DOMContentLoaded', restoreOptions);
document.querySelector('form')!.addEventListener('submit', saveOptions);
8 changes: 6 additions & 2 deletions src/manifest.json
Expand Up @@ -27,16 +27,20 @@
"*://*.amazon.in/*",
"*://*.amazon.it/*",
"*://*.amazon.nl/*"
],
"js": ["js/frontend.js"]
]
}
],
"options_ui": {
"page": "options.html"
},
"permissions": [
"tabs",
"activeTab",
"webNavigation",
"webRequest",
"webRequestBlocking",
"notifications",
"storage",
"*://*.amazon.at/*",
"*://*.amazon.ca/*",
"*://*.amazon.cn/*",
Expand Down
18 changes: 18 additions & 0 deletions src/options.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>

<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>

</html>

0 comments on commit 257f27a

Please sign in to comment.