x0a / uBO-YouTube

Easier way to exempt your favorite YouTube channels from adblocking.
GNU General Public License v3.0
124 stars 8 forks source link

A YouTube search and push button "on air" script? #50

Closed franchesko1437 closed 1 year ago

franchesko1437 commented 1 year ago

Good afternoon. I will describe the essence of the idea. You need a script, a clicker, anything (as long as it works in the background and does not jerk the mouse cursor) that would press the "On air - Skip and go live" button in the YouTube player (such a button next to the volume slider) in several windows browser, and did it at random intervals (or, if possible, when the "Live" button turns gray.) I think this script will be easy to write with a basic knowledge of programming languages, but I do not. Please, help. "(function() { document.querySelector('ytp-live-badge') .click(); }, 3000);" Tried this script but it doesn't work image https://vk.cc/cnnYXL Link to the page where there is a YouTube player. I will be grateful for your help

x0a commented 1 year ago

Hi,

Thank you for your inquiry and suggestion. Currently this extension does not run on third party websites other than youtube.com for practical/privacy reasons (it would require requesting permissions from every user in order to update the extension and much of the extension's startup logic would have to be re-written). However I did take a look at your problem and the following userscript should work:

// ==UserScript==
// @name         Auto Click YTP Live Badge
// @namespace    your-namespace
// @version      1.0
// @description  Automatically clicks the YTP Live Badge every 3 seconds on all websites and frames.
// @match        *://*/*
// @include      *
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const skipAds = false;
    setInterval(() => {
        document.querySelector('.ytp-live-badge')?.click();

        if(skipAds) {
            const adVideo = document.querySelector('.html5-video-player.ad-showing video');
            if(!adVideo || isNaN(adVideo.duration)) return;
            adVideo.currentTime = adVideo.duration - 0.5;
            document.querySelector('.button.ytp-ad-overlay-close-button.')?.click();
        }    
    }, 3000);

})();

It clicks the .ytp-live-badge button which you correctly identified as the "* Live" button that can be clicked to keep live content current. After the button is clicked, it becomes disabled and wont be clickable until the live content becomes out of sync again. I can add similar functionality to this extension in later builds.

Set skipAds to true if you also want to skip ads. A more minimal example can just have setInterval(() => document.querySelector('.ytp-live-badge')?.click(), 3000).

Once I identify a good pattern to adopt this in the main extension, I'll go ahead and add it.

Thank you again for your suggestion and don't hesitate to leave more.

franchesko1437 commented 1 year ago

Thanks