Watch on Piped button

adds a watch on Piped button

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Watch on Piped button
// @namespace   Violentmonkey Scripts
// @match       https://www.youtube.com/*
// @grant       GM_addStyle
// @version     1.0
// @author      jside
// @description adds a watch on Piped button
// ==/UserScript==

function WaitForElement(selector, callback) { // @_@
    if (document.querySelector(selector)) {
        callback();
    } else {
        setTimeout(function() {
            WaitForElement(selector, callback);
        }, 100);
    }
}

let css = `
.script-button-css {
  background-color: #98789d !important;
  color: #0f0f0f !important;
  margin-right: 8px;

}

.script-button-css:hover {
  background-color: #79607d !important;
}
`;

GM_addStyle(css)

function likeSegmentFound() {

    var like = document.getElementById("segmented-buttons-wrapper");
    var button = document.createElement("a");
    button.innerText = "Watch on Piped"
    button.classList = "yt-spec-button-shape-next yt-spec-button-shape-next--tonal yt-spec-button-shape-next--mono yt-spec-button-shape-next--size-m script-button-css";

    button.onclick = function () {
        if (window.location.href.indexOf('youtube.com/watch') > -1) {
            window.location.replace(window.location.toString().replace('www.youtube.com', 'piped.video'));
        }
    };

  like.prepend(button); // does not need to be reapplied for some reason :)
}


WaitForElement("#segmented-buttons-wrapper", likeSegmentFound);