Watch on Piped button

adds a watch on Piped button

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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);