Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions extension/plugins/content/RandomYTVid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import ContentPlugin from '../../lib/ContentPlugin.js';

class RandomYTVid extends ContentPlugin {
constructor() {
super('Open another YouTube video then clicked');
}

id = 'e1ec49fd-a3e2-4dc1-ac5d-d2d2a326410c';

settings = {
enabled: false,
yt_only: true,
};

redirected = false;

run() {
const randomVID = () => {
// so that the event listener is only triggered once
this.redirected = true;
const videos = document.querySelectorAll(
'a[id="thumbnail"][href*="/watch"]'
);
videos[Math.floor(Math.random() * videos.length)].click();
};

if (location.hostname.includes('youtube') && this.settings.yt_only) {
// listen on YT navigate events
document.addEventListener('yt-navigate-start', (e) => {
// check if we are on a "watch" page
if (e.path[2].baseURI.includes('watch') && !this.redirected) {
randomVID();
} else {
this.redirected = false;
}
});
}
}

cleanup() {}
}

export default RandomYTVid;
2 changes: 2 additions & 0 deletions extension/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import RandomElementFocus from './content/RandomElementFocus.js';
import KeyRepeat from './content/KeyRepeat.js';
import HideCursorRandomly from './content/HideCursorRandomly.js';
import RedirectToRandomTranslation from './content/RedirectToRandomTranslation.js';
import RandomYTVid from './content/RandomYTVid.js';

export default [
new RandomDiscordNotification(),
Expand All @@ -32,4 +33,5 @@ export default [
new KeyRepeat(),
new HideCursorRandomly(),
new RedirectToRandomTranslation(),
new RandomYTVid(),
];