Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Fixed short videos in subscription feed not removing parent element
Browse files Browse the repository at this point in the history
  • Loading branch information
probablyraging committed Jan 9, 2023
1 parent 471cd8d commit 3308a4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
});

function hideShorts() {
console.log(chrome.storage.sync.get(['toggleHomeFeedState']));
// Check for shorts videos and tabs every 100 milliseconds
setInterval(() => {
chrome.storage.sync.get(['toggleState'], function (result) {
Expand All @@ -22,7 +21,7 @@ function hideShorts() {
// Home Feed
chrome.storage.sync.get(['toggleHomeFeedState'], function (result) {
if (result.toggleHomeFeedState === 'on') hideElements('#title.style-scope.ytd-rich-shelf-renderer');
if (result.toggleHomeFeedState === 'on' && tab.url === 'https://www.youtube.com/') hideElements('[href^="/shorts/"]');
if (result.toggleHomeFeedState === 'on') hideElements('[href^="/shorts/"]');
});
// Home Feed
chrome.storage.sync.get(['toggleTabState'], function (result) {
Expand All @@ -33,6 +32,12 @@ function hideShorts() {
}, 100);

function hideElements(selector, text) {
if (selector === '[href^="/shorts/"]') {
const shorts = document.querySelectorAll('[href^="/shorts/"]');
shorts.forEach(short => {
short.parentNode.parentNode.parentNode.style.display = 'none';
});
}
// Find all elements matching the provided selector and hide them if they contain the provided text
const elements = document.querySelectorAll(selector);
elements.forEach(element => {
Expand Down
8 changes: 6 additions & 2 deletions src/scripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ document.addEventListener('DOMContentLoaded', () => {
if (mainResult.toggleState === undefined) {
// Update toggle state in storage
chrome.storage.sync.set({ toggleState: 'on' });
toggleNavButton.classList.add('toggled');
toggleHomeFeedButton.classList.add('toggled');
toggleTabButton.classList.add('toggled');
} else if (mainResult.toggleState === 'on') {
toggleBtn.src = '../images/power-button-on.svg';
toggleNavButton.classList.add('toggled');
toggleHomeFeedButton.classList.add('toggled');
toggleTabButton.classList.add('toggled');
} else {
toggleBtn.src = '../images/power-button-off.svg';
toggleNavButton.classList.remove('toggled');
Expand Down Expand Up @@ -94,7 +100,6 @@ document.addEventListener('DOMContentLoaded', () => {
// Toggle nav hiding
// When popup window is opened, check the toggle state and update the UI accordingly
chrome.storage.sync.get(['toggleNavState'], result => {
console.log(mainResult.toggleState);
if (result.toggleNavState === undefined) {
// Update toggle state in storage
chrome.storage.sync.set({ toggleNavState: 'on' });
Expand Down Expand Up @@ -123,7 +128,6 @@ document.addEventListener('DOMContentLoaded', () => {
// Toggle home feed hiding
// When popup window is opened, check the toggle state and update the UI accordingly
chrome.storage.sync.get(['toggleHomeFeedState'], result => {
console.log(result);
if (result.toggleHomeFeedState === undefined) {
// Update toggle state in storage
chrome.storage.sync.set({ toggleHomeFeedState: 'on' });
Expand Down
2 changes: 1 addition & 1 deletion src/views/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</div>
</div>
<div class="switch-wrapper">
<p class="switch-label tooltip" tooltip="Hide Shorts videos on the home feed">Home Feed <i class="bi bi-question-circle"></i></p>
<p class="switch-label tooltip" tooltip="Hide Shorts videos on the home and subscription feeds">Home & Subscription Feed <i class="bi bi-question-circle"></i></p>
<div class="toggle-container homefeed-container">
<button class="toggle-button homefeed-toggle"></button>
</div>
Expand Down

0 comments on commit 3308a4c

Please sign in to comment.