YT - Looper

Puts a repeat button below YouTube videos

This script is marked as "broken" and is likely not working
Details: You can right click the video to get a "Loop" option
This script is marked as "external"
This script was commisioned by someone else, and I will not check if it works. If it breaks, contact me
Click here to install Browse More Scripts
// ==UserScript==
// @name         YT - Looper
// @namespace    37f4c9e950aa13ef73559d43b49348eb2125c115
// @version      0.3
// @description  Puts a repeat button below YouTube videos
// @author       /u/AyrA
// @match        https://www.youtube.com/*
// @match        http://www.youtube.com/*
// @match        https://youtube.com/*
// @match        http://youtube.com/*
// @grant        none
// @external     true
// @expired      true
// @broken       You can right click the video to get a "Loop" option
// ==/UserScript==

//Changelog
//0.4 - Changed title to match other scripts
//0.3 - New Youtube layout adaptation
//0.2 - Make sure it survives video switches
//0.1 - Initial Version

(function ($) {
	"use strict";

	var addBtn = function () {
		//get the area with the buttons below the video (stats, add to list, flag, ...)
		var buttons = $("div#menu.ytd-video-primary-info-renderer #top-level-buttons");

		//If the looper button exists, exit this function
		if ($(".looper-btn") || !buttons) {
			return;
		}

		var isLoop = false;
		var isColor = false;

		//create the looper button
		var looper = document.createElement("ytd-button-renderer");

		//this makes the button blinking, if repeat mode is turned on.
		var blinker = function () {
			if (isLoop || isColor) {
				looper.style.backgroundColor = isColor ? "transparent" : "#e62117";
				isColor = !isColor;
			}
		};
		var flasher = window.setInterval(blinker, 500);
		//Write the looper text. "↺" is a reload arrow.
		looper.innerHTML = "<span class=\"yt-uix-button-content\">&#x21BA; Repeat</span>";

		//turn on/off loop mode
		looper.onclick = function () {
			isLoop = !isLoop;
			$("video").loop = isLoop;
		};

		//apply some styling
		looper.style.borderRadius = "5px";
		looper.style.paddingTop = "10px";
		looper.style.cursor = "pointer";
		looper.setAttribute("class", "looper-btn style-scope ytd-menu-renderer style-default");
		looper.setAttribute("data-tooltip-text", "enable or disable video looping");
		looper.setAttribute("is-icon-button", "is-icon-button");
		looper.setAttribute("aria-label", "Repeat");

		buttons.appendChild(looper);
	};

	//watch for changes in the document content.
	//This is needed, because youtube does not really navigate when you click a link.
	//They just replace the page content.
	var mo = new MutationObserver(function (evt) {
			addBtn();
		});
	mo.observe($("body"), {
		childList: true
	});
	addBtn();
})(document.querySelector.bind(document));

/*
LICENSE:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
The full license text can be found here: http://creativecommons.org/licenses/by-nc-sa/4.0/
The link has an easy to understand version of the license and the full license text.

DISCLAIMER:
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/

Copyright © 2018 by Kevin Gut 📧 | More services | Generated for 54.236.62.49