diff --git a/src/css/style.css b/src/css/style.css deleted file mode 100644 index 8a103fc8..00000000 --- a/src/css/style.css +++ /dev/null @@ -1,40 +0,0 @@ -.amazon-tag-remover { - background: #2c3539; - border: 2px solid #fff; - border-radius: 5px; - bottom: 15px; - box-shadow: 0 0 20px #000; - color: #fff; - padding: 7px 10px; - position: fixed; - right: 20px; - z-index: 50; -} - -.amazon-tag-remover-fade-in { - animation: fadein 2s; - opacity: 1; -} - -.amazon-tag-remover-fade-out { - animation: fadeout 2s; - opacity: 0; -} - -@keyframes fadein { - from { - opacity: 0; - } - to { - opacity: 1; - } -} - -@keyframes fadeout { - from { - opacity: 1; - } - to { - opacity: 0; - } -} diff --git a/src/js/background.ts b/src/js/background.ts index 7b2da551..6ca07b6b 100644 --- a/src/js/background.ts +++ b/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/*', @@ -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' + }); + } + }); } }, { @@ -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 }; } } } @@ -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() }; } diff --git a/src/js/frontend.ts b/src/js/frontend.ts deleted file mode 100644 index 13de4e69..00000000 --- a/src/js/frontend.ts +++ /dev/null @@ -1,15 +0,0 @@ -// tslint:disable-next-line:variable-name -const __browser = chrome || browser; -__browser.runtime.onMessage.addListener((request, _, resetTag) => { - const div = document.createElement('div'); - div.className = 'amazon-tag-remover'; - div.textContent = `The following tags were found and have been removed: ${request.tags}`; - document.body.appendChild(div); - div.classList.toggle('amazon-tag-remover-fade-in'); - - setTimeout(() => { - div.classList.toggle('amazon-tag-remover-fade-in'); - div.classList.toggle('amazon-tag-remover-fade-out'); - }, 7000); - resetTag(null); -}); diff --git a/src/js/options.ts b/src/js/options.ts new file mode 100644 index 00000000..a7671a75 --- /dev/null +++ b/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('#enable-notifications')!.checked + }); +} + +function restoreOptions() { + function setCurrentChoice(result: any) { + document.querySelector('#enable-notifications')!.checked = result.enableNotifications; + } + + __browser.storage.local.get('enableNotifications', setCurrentChoice); +} + +document.addEventListener('DOMContentLoaded', restoreOptions); +document.querySelector('form')!.addEventListener('submit', saveOptions); diff --git a/src/manifest.json b/src/manifest.json index be52a645..b6fb8ac6 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -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/*", diff --git a/src/options.html b/src/options.html new file mode 100644 index 00000000..6dfdea48 --- /dev/null +++ b/src/options.html @@ -0,0 +1,18 @@ + + + + + + + + +
+ +
+
+ +
+ + + +