mirror of
https://github.com/lawrencehook/remove-youtube-suggestions.git
synced 2026-07-25 06:54:31 +00:00
add a settings page
This commit is contained in:
+8
-2
@@ -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"]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<fieldset>
|
||||
<legend>Choose which suggestions to remove</legend>
|
||||
|
||||
<div>
|
||||
<input type="checkbox" id="homepage" name="feature"
|
||||
value="homepage" checked />
|
||||
<label for="homepage">Homepage</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="checkbox" id="sidebar" name="feature"
|
||||
value="sidebar" checked />
|
||||
<label for="sidebar">Sidebar</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<script src="options.js"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+36
@@ -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);
|
||||
+42
-19
@@ -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
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user