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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FILES := manifest.json \
settings.html \
settings.js \
video-bg-play-content.js \
$(wildcard _locales/*/messages.json) \
icon.svg \
Expand Down
12 changes: 11 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"name": "__MSG_extensionName__",
"default_locale": "en",
"version": "1.8.1",

"permissions": ["storage"],

"description": "__MSG_extensionDescription__",
"icons": {
"48": "icon.svg",
Expand All @@ -17,6 +18,15 @@
}
},

"browser_action": {
"default_popup": "settings.html",
"default_icon": {
"48": "icon.svg",
"96": "icon.svg"
},
"default_title": "video-bg-play-settings"
},

"content_scripts": [
{
"matches": ["*://*.youtube.com/*",
Expand Down
19 changes: 19 additions & 0 deletions settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>video-bg-play-settings</title>
</head>

<body>
<label>
<input type="checkbox" id="instantAutoplay">
Instant auto-play
</label>

<script src="settings.js"></script>
</body>

</html>
9 changes: 9 additions & 0 deletions settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const checkbox = document.getElementById('instantAutoplay');

chrome.storage.sync.get('instantAutoplay', (data) => {
checkbox.checked = data.instantAutoplay || false;
});

checkbox.addEventListener('change', () => {
chrome.storage.sync.set({ instantAutoplay: checkbox.checked });
});
32 changes: 32 additions & 0 deletions video-bg-play-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ if (IS_VIMEO) {
// User activity tracking
if (IS_YOUTUBE) {
loop(pressKey, 60 * 1000, 10 * 1000); // every minute +/- 5 seconds

attachEndscreenListener();

let lastUrl = location.href;
new MutationObserver(() => {
const currentUrl = location.href;
if (currentUrl !== lastUrl) {
lastUrl = currentUrl;
attachEndscreenListener();
}
}).observe(document, { subtree: true, childList: true });
}

function pressKey() {
Expand Down Expand Up @@ -59,3 +70,24 @@ function getRandomInt(aMin, aMax) {
let max = Math.floor(aMax);
return Math.floor(Math.random() * (max - min)) + min;
}

function attachEndscreenListener() {
setInterval(() => {
let video = document.querySelector('video');
if (video) {
let desktopEndscreen = document.querySelector('.ytp-autonav-endscreen-countdown-overlay');
if ((desktopEndscreen && desktopEndscreen.style.display === "") || document.getElementById('upnext-in-message')) {
chrome.storage.sync.get('instantAutoplay', ({ instantAutoplay }) => {
let delay = instantAutoplay ? 0 : 10000;
setTimeout(() => {
let nextButton = document.querySelector('[aria-label="Play next video"]');
if (nextButton) {
video.click();
nextButton.click();
}
}, delay);
});
}
}
}, 1000);
}