diff --git a/extension/dist/content.js b/extension/dist/content.js index 6216ad3..04df35e 100644 --- a/extension/dist/content.js +++ b/extension/dist/content.js @@ -3,7 +3,7 @@ const VIDEOS_LIST_SELECTOR = ".reel-video-in-sequence"; const NEXT_VIDEO_BUTTON_SELECTOR = "#navigation-button-down > ytd-button-renderer > yt-button-shape > button"; const LIKE_BUTTON_SELECTOR = "ytd-reel-video-renderer[is-active] #like-button > yt-button-shape > label > button"; const DISLIKE_BUTTON_SELECTOR = "ytd-reel-video-renderer[is-active] #dislike-button > yt-button-shape > label > button"; -const COMMENTS_SELECTOR = "ytd-reel-video-renderer[is-active] ytd-engagement-panel-section-list-renderer[target-id='engagement-panel-comments-section']"; +const COMMENTS_SELECTOR = "#anchored-panel > ytd-engagement-panel-section-list-renderer:nth-child(1)"; const LIKES_COUNT_SELECTOR = "ytd-reel-video-renderer[is-active] #factoids > factoid-renderer:nth-child(1) > div > span.YtwFactoidRendererValue > span"; const VIEW_COUNT_SELECTOR = "ytd-reel-video-renderer[is-active] #factoids > view-count-factoid-renderer > factoid-renderer > div > span.YtwFactoidRendererValue > span"; const COMMENTS_COUNT_SELECTOR = "ytd-reel-video-renderer[is-active] #comments-button > ytd-button-renderer > yt-button-shape > label > div > span"; @@ -25,6 +25,8 @@ let filterMaxComments = "none"; let blockedCreators = []; let whitelistedCreators = []; let blockedTags = []; +let scrollOnNoTags = false; +let additionalScrollDelay = 0; // STATE VARIABLES let currentVideoIndex = null; let applicationIsOn = false; @@ -92,12 +94,26 @@ function videoFinished() { // If the video is finished and is equal to the amount of plays needed to skip, // check if the comments are open. const comments = document.querySelector(COMMENTS_SELECTOR); - if (scrollOnCommentsCheck || !comments) - return scrollToNextShort(); // Scroll due to scrollOnComments being true or comments not being found + const commentsActive = comments?.clientWidth > 0; + if (scrollOnCommentsCheck || !commentsActive) { + // take into account additional scroll delay + return setTimeout(() => { + if (currentVideo.duration != + document.querySelector("#shorts-container video[tabindex='-1']").duration) + return; // if the video is not the same as the one that finished, don't scroll + scrollToNextShort(); + }, additionalScrollDelay); + } else if (comments.getAttribute("visibility") === "ENGAGEMENT_PANEL_VISIBILITY_HIDDEN" || - comments.clientWidth <= 0) - return scrollToNextShort(); // Scroll due to comments not being open + comments.clientWidth <= 0) { + return setTimeout(() => { + if (currentVideo.duration != + document.querySelector("#shorts-container video[tabindex='-1']").duration) + return; // if the video is not the same as the one that finished, don't scroll + scrollToNextShort(); + }, additionalScrollDelay); + } // If the comments are open, wait for them to close let intervalComments = setInterval(() => { if (comments.getAttribute("visibility") === @@ -146,13 +162,21 @@ function checkIfVaildVideo() { currentVideo.setAttribute("loop", ""); return false; } + // Check If Advertisement + if (currentVideoParent?.querySelector("ad-badge-view-model > badge-shape > div")?.innerText && + currentVideoParent?.querySelector("ad-badge-view-model > badge-shape > div")?.innerText?.toLowerCase() === "sponsored") { + return false; + } // Check if the video is from a blocked creator and if it is, skip it (FROM SETTINGS) - const authorOfVideo = currentVideoParent?.querySelector("#text a")?.innerText + const authorOfVideo = currentVideoParent?.querySelector("#metapanel > yt-reel-metapanel-view-model > div:nth-child(2) > yt-reel-channel-bar-view-model > span > a")?.innerText ?.toLowerCase() .replace("@", ""); - const tagsOfVideo = [ - ...currentVideoParent?.querySelectorAll("h2.title a"), + let tagsOfVideo = [ + ...currentVideoParent?.querySelectorAll("#metapanel > yt-reel-metapanel-view-model > div:nth-child(3) > yt-shorts-video-title-view-model > h2 > span > span > a"), ].map((src) => src?.innerText?.toLowerCase()?.replaceAll("#", "")); + if (!currentVideoParent?.querySelector("#metapanel > yt-reel-metapanel-view-model > div:nth-child(3) > yt-shorts-video-title-view-model > h2 > span")?.innerText) { + tagsOfVideo = ["tagsLoading..."]; + } if (authorOfVideo && blockedCreators .map((c) => c?.toLowerCase()?.replace("@", "")) @@ -171,6 +195,13 @@ function checkIfVaildVideo() { .includes(authorOfVideo)) { return false; } + else if (scrollOnNoTags && + tagsOfVideo.length === 0 && + !whitelistedCreators + .map((c) => c?.toLowerCase()?.replace("@", "")) + .includes(authorOfVideo)) { + return false; + } // Check if the video is within the length filter (FROM SETTINGS) if (filterMaxLength != "none" || filterMinLength != "none") { if (currentVideo.duration < parseInt(filterMinLength) || @@ -299,6 +330,8 @@ function getParentVideo() { "filteredAuthors", "filteredTags", "scrollOnComments", + "scrollOnNoTags", + "whitelistedAuthors", ], (result) => { console.log({ result }); if (result["shortCutKeys"]) @@ -337,6 +370,10 @@ function getParentVideo() { blockedTags = [...result["filteredTags"]]; if (result["whitelistedAuthors"]) whitelistedCreators = [...result["whitelistedAuthors"]]; + if (result["scrollOnNoTags"]) + scrollOnNoTags = result["scrollOnNoTags"]; + if (result["additionalScrollDelay"]) + additionalScrollDelay = result["additionalScrollDelay"]; shortCutListener(); }); chrome.storage.onChanged.addListener((result) => { @@ -407,6 +444,14 @@ function getParentVideo() { if (newWhiteListedCreators != undefined) { whitelistedCreators = [...newWhiteListedCreators]; } + let newScrollOnNoTags = result["scrollOnNoTags"]?.newValue; + if (newScrollOnNoTags !== undefined) { + scrollOnNoTags = newScrollOnNoTags; + } + let newAdditionalScrollDelay = result["additionalScrollDelay"]?.newValue; + if (newAdditionalScrollDelay !== undefined) { + additionalScrollDelay = newAdditionalScrollDelay; + } }); })(); })(); diff --git a/extension/dist/script.js b/extension/dist/script.js index ceb5c14..95eeabe 100644 --- a/extension/dist/script.js +++ b/extension/dist/script.js @@ -17,6 +17,8 @@ const filterByMaxComments = document.querySelector("#filterByMaxComments"); const scrollDirectionInput = document.querySelector("#scrollDirectionInput"); const amountOfPlaysInput = document.querySelector("#amountOfPlaysInput"); const scrollOnCommentsInput = document.querySelector("#scrollOnComments"); +const scrollOnNoTagsInput = document.querySelector("#scrollOnNoTags"); +const additionalScrollDelayInput = document.querySelector("#additionalScrollDelay"); const nextSettings = document.querySelector("#nextSettings"); const backSettings = document.querySelector("#backSettings"); const nextFilter = document.querySelector("#nextFilter"); @@ -403,10 +405,23 @@ function getAllSettingsForPopup() { amountOfPlaysToSkip: parseInt(e.target.value), }); }); + chrome.storage.local.get(["additionalScrollDelay"], async (result) => { + let value = result["additionalScrollDelay"]; + if (value == undefined) { + await chrome.storage.local.set({ additionalScrollDelay: 0 }); + additionalScrollDelayInput.value = "0"; + } + additionalScrollDelayInput.value = value; + }); + additionalScrollDelayInput.addEventListener("change", (e) => { + chrome.storage.local.set({ + additionalScrollDelay: parseInt(e.target.value), + }); + }); chrome.storage.local.get(["scrollOnComments"], async (result) => { let value = result["scrollOnComments"]; if (value == undefined) { - await chrome.storage.local.set({ crollOnComments: false }); + await chrome.storage.local.set({ scrollOnComments: false }); scrollOnCommentsInput.checked = true; } scrollOnCommentsInput.checked = value; @@ -416,6 +431,19 @@ function getAllSettingsForPopup() { scrollOnComments: e.target.checked, }); }); + chrome.storage.local.get(["scrollOnNoTags"], async (result) => { + let value = result["scrollOnNoTags"]; + if (value == undefined) { + await chrome.storage.local.set({ scrollOnNoTags: false }); + scrollOnNoTagsInput.checked = true; + } + scrollOnNoTagsInput.checked = value; + }); + scrollOnNoTagsInput.addEventListener("change", (e) => { + chrome.storage.local.set({ + scrollOnNoTags: e.target.checked, + }); + }); chrome.storage.onChanged.addListener((result) => { if (result["applicationIsOn"]?.newValue != undefined) changeToggleButton(result["applicationIsOn"].newValue); diff --git a/extension/manifest.json b/extension/manifest.json index ca1a44f..0746c8d 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Auto Youtube Shorts Scroller", - "version": "2.5.3", + "version": "2.5.4", "content_scripts": [ { "matches": ["https://www.youtube.com/*"], diff --git a/extension/popup/popup.html b/extension/popup/popup.html index bcbfdfa..20ac585 100644 --- a/extension/popup/popup.html +++ b/extension/popup/popup.html @@ -359,7 +359,7 @@