Advertisement
AyrA

Tampermonkey script for repeat button below a Youtube video

Mar 29th, 2016
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Youtube looper
  3. // @namespace    http://ayra.ch/
  4. // @version      0.1
  5. // @description  Loops youtube videos
  6. // @author       You
  7. // @match        https://www.youtube.com/watch*
  8. // @match        http://www.youtube.com/watch*
  9. // @grant        none
  10. // ==/UserScript==
  11. /* jshint -W097 */
  12. "use strict";
  13.  
  14. (function($){
  15.  
  16.     var addBtn=function()
  17.     {
  18.         var buttons=$(".watch-secondary-actions");
  19.  
  20.         if($(".looper-btn") || !buttons)
  21.         {
  22.             return;
  23.         }
  24.  
  25.         var isLoop=false;
  26.         var isColor=false;
  27.  
  28.         var looper=document.createElement("button");
  29.         var blinker=function()
  30.         {
  31.             if(isLoop || isColor)
  32.             {
  33.                 looper.style.backgroundColor=isColor?"transparent":"#e62117";
  34.                 isColor=!isColor;
  35.             }
  36.         };
  37.         var flasher=window.setInterval(blinker,500);
  38.         looper.innerHTML="<span class=\"yt-uix-button-content\">&#x21BA; Repeat</span>";
  39.  
  40.         looper.onclick=function()
  41.         {
  42.             isLoop=!isLoop;
  43.             $("video").loop=isLoop;
  44.         };
  45.  
  46.         looper.style.borderRadius="5px";
  47.         looper.setAttribute("class","looper-btn yt-uix-button  yt-uix-button-size-default yt-uix-button-opacity yt-uix-tooltip");
  48.         looper.setAttribute("data-tooltip-text","enable or disable video looping");
  49.         looper.setAttribute("role","button");
  50.  
  51.         buttons.appendChild(looper);
  52.     };
  53.  
  54.     var mo=new MutationObserver(function(evt)
  55.     {
  56.         addBtn();
  57.     });
  58.     mo.observe($("body"),{childList:true});
  59.     addBtn();
  60. })(document.querySelector.bind(document));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement