diff --git a/Content.js b/Content.js index beb0893..e1b20b1 100644 --- a/Content.js +++ b/Content.js @@ -1,38 +1,25 @@ -function removeShortButtons(){ - const shortsButtons = document.querySelectorAll('a[title="Shorts"]'); +const observer = new MutationObserver(mutations => { + mutations.forEach(mutation => { + mutation.addedNodes.forEach(node => { + if (node.nodeType !== Node.ELEMENT_NODE) return; - shortsButtons.forEach(button => { - button.remove(); - }); -} - -function removeShortSections(){ - const sections = document.querySelectorAll("span#title.style-scope.ytd-rich-shelf-renderer"); - sections.forEach(title => { - if (title.textContent.trim() === "Shorts") { - var section = title; - for (let i = 1; i < 7; i++) { - section = section.parentElement; - if (!section){ - return; - } + // Remove shorts from sidebar + if (node.tagName === "A" && node.title === "Shorts"){ + node.remove(); } - if (section.className == "style-scope ytd-rich-shelf-renderer") { - section.style.display = "none"; + // Remove shorts sections from right side + if (node.nodeName.toLowerCase() === "ytd-reel-shelf-renderer"){ + node.remove(); } - } + + // Remove shorts sections + if (node.hasAttribute?.("is-shorts")){ + node.remove(); + } + }); }); -} - -document.addEventListener("DOMContentLoaded", function () { - removeShortButtons(); - removeShortSections(); }); -const observer = new MutationObserver(function (mutations) { - removeShortButtons(); - removeShortSections(); -}); -observer.observe(document.body, { childList: true, subtree: true }); \ No newline at end of file +observer.observe(document.body, {childList: true, subtree: true}); diff --git a/Redirect.js b/Redirect.js new file mode 100644 index 0000000..dc66ad7 --- /dev/null +++ b/Redirect.js @@ -0,0 +1,7 @@ + +if (location.pathname.startsWith("/shorts/")) { + const videoID = location.pathname.split("/")[2]; + if (videoID) { + location.replace("https://www.youtube.com/watch?v=${videoID}"); + } +} diff --git a/manifest.json b/manifest.json index c37760b..ca4537a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { - "manifest_version": 2, - "name": "Block Youtube Shorts", - "description": "Blocks the Youtube Short buttons and sections on the main page.", + "manifest_version": 3, + "name": "Remove Youtube Shorts", + "description": "Removes any trace of Shorts from Youtube.", "version": "1.0", "icons": { "16": "icon16.png", @@ -9,11 +9,25 @@ "48": "icon48.png", "128": "icon128.png" }, + "permissions": ["scripting"], "host_permissions": ["*://www.youtube.com/*"], "content_scripts": [ { "matches": ["*://www.youtube.com/*"], - "js": ["Content.js"] + "js": ["Content.js"], + "run_at": "document_idle" + }, + { + "matches": ["*://www.youtube.com/*"], + "js": ["Redirect.js"], + "run_at": "document_start" } - ] -} \ No newline at end of file + ], + "action": { + "default_icon": { + "16": "icon16.png", + "32": "icon32.png" + } + } +} + \ No newline at end of file