diff --git a/manifest.json b/manifest.json index 5cd819a..8945693 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "description": "Removes all suggestions from Youtube.", "manifest_version": 2, "name": "Remove Youtube Suggestions", - "version": "1.1.1", + "version": "1.2", "homepage_url": "https://github.com/emumoo/remove-youtube-suggestions", "content_scripts": [ @@ -11,5 +11,11 @@ "matches": ["*://*.youtube.com/*"], "js": ["remove-suggestions.js"] } - ] + ], + + "options_ui": { + "page": "options.html" + }, + + "permissions": ["storage"] } diff --git a/options.html b/options.html new file mode 100644 index 0000000..9b58c99 --- /dev/null +++ b/options.html @@ -0,0 +1,30 @@ + + + + + + + + + +
+ Choose which suggestions to remove + +
+ + +
+ +
+ + +
+
+ + + + + + \ No newline at end of file diff --git a/options.js b/options.js new file mode 100644 index 0000000..c9df45d --- /dev/null +++ b/options.js @@ -0,0 +1,36 @@ +function saveHomepageSetting(e) { + console.log(e.target.checked); + browser.storage.local.set({ + homepage: e.target.checked + }); +} + +function saveSidebarSetting(e) { + console.log(e.target.checked); + browser.storage.local.set({ + sidebar: e.target.checked + }); +} + +var homepage_checkbox = document.getElementById('homepage'); +var sidebar_checkbox = document.getElementById('sidebar'); + +// console.log(homepage_checkbox, sidebar_checkbox); + +homepage_checkbox.addEventListener("change", saveHomepageSetting); +sidebar_checkbox.addEventListener("change", saveSidebarSetting); + + +function restoreOptions() { + function setCurrentChoice(result) { + } + + function onError(error) { + console.log(`Error: ${error}`); + } + + var getting = browser.storage.local.get("settings"); + getting.then(setCurrentChoice, onError); +} + +document.addEventListener("DOMContentLoaded", restoreOptions); diff --git a/remove-suggestions.js b/remove-suggestions.js index e7b7fd1..355280e 100644 --- a/remove-suggestions.js +++ b/remove-suggestions.js @@ -1,30 +1,53 @@ // Lawrence Hook -// remove sidebar recommendations -let sheets = document.styleSheets; -sheets[0].insertRule(".ytd-watch-next-secondary-results-renderer { display: none !important; }"); - - +function onError(error) { + console.log(`Error: ${error}`); +} // remove homepage recommendations -function updateStyle() { +function updateStyle(setting) { // the homepage has pathname "/" which is length 1 - let property = window.location.pathname.length > 1 ? "flex" : "none"; + let property = !setting || window.location.pathname.length > 1 ? "flex" : "none"; for (let elt of document.querySelectorAll("ytd-browse")) { if (elt) elt.style.setProperty("display", property); } } -updateStyle(); -// watch for url changes -let observer = new MutationObserver(function(mutations) { - updateStyle(); - return; -}); +// After getting settings +function onGotHomepageSetting(item) { + console.log(item); + if (item.homepage) { + updateStyle(item.homepage); + + // watch for url changes + let observer = new MutationObserver(function(mutations) { + updateStyle(item.homepage); + return; + }); + + observer.observe(document.body, { + childList: true, + subtree: true, + attributes: false, + characterData: false + }); + } + +} + +function onGotSidebarSetting(item) { + console.log(item); + if (item.sidebar) { + let sheets = document.styleSheets; + sheets[0].insertRule(".ytd-watch-next-secondary-results-renderer { display: none !important; }"); + } +} + +console.log('hi'); +var gettingHomepage = browser.storage.local.get("homepage"); +gettingHomepage.then(onGotHomepageSetting, onError); + +var gettingSidebar = browser.storage.local.get("sidebar"); +gettingSidebar.then(onGotSidebarSetting, onError); +console.log('bye'); -observer.observe(document.body, { - childList: true - , subtree: true - , attributes: false - , characterData: false -})