Greasy Fork is available in English.
Userscript for audio background (YouTube and YouTube music)
// ==UserScript==
// @name LatBel
// @namespace http://tampermonkey.net/
// @version 1.6
// @description Userscript for audio background (YouTube and YouTube music)
// @author dehacking_guy
// @license MIT
// @match *://*/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// 1. Block tab switching detection completely
Object.defineProperty(document, 'hidden', {value: false, writable: false});
Object.defineProperty(document, 'visibilityState', {value: 'visible', writable: false});
const blockEvent = (event) => event.stopImmediatePropagation();
['visibilitychange', 'webkitvisibilitychange', 'pagehide', 'blur'].forEach(evt => {
window.addEventListener(evt, blockEvent, true);
});
// 2. Aggressive Playback Enforcement
document.addEventListener('pause', (event) => {
const target = event.target;
if (target && target.tagName === 'VIDEO') {
if (!document.hasFocus()) {
let attempts = 0;
// Try to force play every 500ms
const forcePlay = setInterval(() => {
attempts++;
target.play().then(() => {
// If successful, stop the loop
clearInterval(forcePlay);
}).catch(err => {
console.warn('Screen-off auto-play blocked by OS:', err);
});
// Give up after 10 attempts (5 seconds) to prevent crashing the page
if (attempts >= 10) {
clearInterval(forcePlay);
}
}, 500);
}
}
}, true);
})();