Skip to content

Commit

Permalink
Added Scroll Delay setting, Added block videos with no tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyson3101 committed Dec 19, 2024
1 parent 5764910 commit 976ac55
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 21 deletions.
61 changes: 53 additions & 8 deletions extension/dist/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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") ===
Expand Down Expand Up @@ -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("@", ""))
Expand All @@ -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) ||
Expand Down Expand Up @@ -299,6 +330,8 @@ function getParentVideo() {
"filteredAuthors",
"filteredTags",
"scrollOnComments",
"scrollOnNoTags",
"whitelistedAuthors",
], (result) => {
console.log({ result });
if (result["shortCutKeys"])
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
}
});
})();
})();
Expand Down
30 changes: 29 additions & 1 deletion extension/dist/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
@@ -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/*"],
Expand Down
25 changes: 24 additions & 1 deletion extension/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ <h3>Comments</h3>
</div>
</div>

<div data-pageIndex="2" class="settingsPage scrollSettings">
<div data-pageIndex="2" class="settingsPage scrollSettings scroll list">
<div>
<label for="scrollDirection"
><p style="font-size: 1rem">
Expand Down Expand Up @@ -396,6 +396,19 @@ <h3>Comments</h3>
checked="true"
/>
</div>
<div>
<label for="additionalScrollDelay"
>Additional Scroll Delay (ms):</label
>
<input
type="number"
name="additionalScrollDelay"
id="additionalScrollDelay"
value="0"
min="0"
style="width: 40%"
/>
</div>
</div>
<div data-pageIndex="3" class="settingsPage">
<label for="shortCutInteractInput"
Expand Down Expand Up @@ -458,6 +471,16 @@ <h3>Comments</h3>
</p></label
>
<textarea id="filterTags" class="urlsList"></textarea>
<br />
<div>
<label for="scrollOnNoTags">Scroll when video has no tags:</label>
<input
type="checkbox"
name="scrollOnNoTags"
id="scrollOnNoTags"
checked="false"
/>
</div>
</div>
<div data-pageIndex="5" class="settingsPage">
<label for="whitelistTags" style="margin-top: 0.5rem; display: block">
Expand Down
99 changes: 90 additions & 9 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const LIKE_BUTTON_SELECTOR =
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']";
"#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 =
Expand All @@ -33,6 +33,8 @@ let filterMaxComments = "none";
let blockedCreators = [];
let whitelistedCreators = [];
let blockedTags = [];
let scrollOnNoTags = false;
let additionalScrollDelay = 0;

// STATE VARIABLES
let currentVideoIndex: number = null;
Expand Down Expand Up @@ -115,14 +117,39 @@ 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
else if (
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']"
) as HTMLVideoElement
).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
) {
return setTimeout(() => {
if (
currentVideo.duration !=
(
document.querySelector(
"#shorts-container video[tabindex='-1']"
) as HTMLVideoElement
).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(() => {
Expand Down Expand Up @@ -173,17 +200,50 @@ function checkIfVaildVideo() {
currentVideo.setAttribute("loop", "");
return false;
}

// Check If Advertisement

if (
(
currentVideoParent?.querySelector(
"ad-badge-view-model > badge-shape > div"
) as HTMLDivElement
)?.innerText &&
(
currentVideoParent?.querySelector(
"ad-badge-view-model > badge-shape > div"
) as HTMLDivElement
)?.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") as HTMLAnchorElement
currentVideoParent?.querySelector(
"#metapanel > yt-reel-metapanel-view-model > div:nth-child(2) > yt-reel-channel-bar-view-model > span > a"
) as HTMLAnchorElement
)?.innerText
?.toLowerCase()
.replace("@", "");
const tagsOfVideo = (
let tagsOfVideo = (
[
...currentVideoParent?.querySelectorAll("h2.title a"),
...currentVideoParent?.querySelectorAll(
"#metapanel > yt-reel-metapanel-view-model > div:nth-child(3) > yt-shorts-video-title-view-model > h2 > span > span > a"
),
] as HTMLAnchorElement[]
).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"
) as HTMLSpanElement
)?.innerText
) {
tagsOfVideo = ["tagsLoading..."];
}

if (
authorOfVideo &&
blockedCreators
Expand All @@ -206,6 +266,14 @@ 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)
Expand Down Expand Up @@ -351,6 +419,8 @@ function getParentVideo() {
"filteredAuthors",
"filteredTags",
"scrollOnComments",
"scrollOnNoTags",
"whitelistedAuthors",
],
(result) => {
console.log({ result });
Expand Down Expand Up @@ -387,6 +457,9 @@ function getParentVideo() {
if (result["filteredTags"]) blockedTags = [...result["filteredTags"]];
if (result["whitelistedAuthors"])
whitelistedCreators = [...result["whitelistedAuthors"]];
if (result["scrollOnNoTags"]) scrollOnNoTags = result["scrollOnNoTags"];
if (result["additionalScrollDelay"])
additionalScrollDelay = result["additionalScrollDelay"];

shortCutListener();
}
Expand Down Expand Up @@ -457,6 +530,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;
}
});
})();
})();
Expand Down
Loading

0 comments on commit 976ac55

Please sign in to comment.