Clean Loopy For Youtube

Displays a link below YouTube videos to enable/disable auto replay.

  1. // ==UserScript==
  2. // @name Clean Loopy For Youtube
  3. // @namespace Rowen
  4. // @description Displays a link below YouTube videos to enable/disable auto replay.
  5. // @include *://*.youtube.com/watch?*v=*
  6. // @include *://*.youtube.com/watch?*videos=*
  7. // @include *://*.youtube.com/watch#!*videos=*
  8. // @include *://*.youtube.com/watch#!*v=*
  9. // @include *://*.youtube.com/watch?*NR=*
  10. // @match *://*.youtube.com/watch?*v=*
  11. // @match *://*.youtube.com/watch?*videos=*
  12. // @match *://*.youtube.com/watch#!*videos=*
  13. // @match *://*.youtube.com/watch#!*v=*
  14. // @match *://*.youtube.com/watch?*NR=*
  15. // @credits QuaraMan (embed code) .Paradise (List Loop Support)
  16. // @version 1.8
  17. // ==/UserScript==
  18.  
  19. myScript = function() {
  20.  
  21. var ytLoop = false;
  22. var ytPlayList;
  23. var ytPLIndex;
  24. var lpButton = "yt-uix-button yt-uix-button-size-default yt-uix-button-opacity yt-uix-button-has-icon action-panel-trigger yt-uix-button-opacity yt-uix-tooltip"; // Button stuff
  25. var lpConOff = "LoopyOff"
  26. var lpConOn = "LoopyOn";
  27.  
  28. loopy = document.createElement("button");
  29. loopy.id = "eLoopy";
  30. loopy.setAttribute("onClick", "LoopyOnOff(); return false;");
  31. loopy.setAttribute("class", lpButton);
  32. loopy.setAttribute("role", "button");
  33. loopy.setAttribute("data-button-toggle", "true");
  34. loopy.setAttribute("type", "button");
  35. loopy.setAttribute("data-tooltip-text", "Enable auto replay")
  36. loopy.id = "loopyButton";
  37.  
  38. a = document.createElement("span");
  39. a.innerHTML = '<img height=18 width=30 id="loopyContent" class="LoopyOff" src="http://s.ytimg.com/yts/img/pixel-vfl3z5WfW.gif" alt="Loopy"/><span class="yt-uix-button-valign"/>';
  40.  
  41.  
  42. loopy.appendChild(a);
  43.  
  44. window.setTimeout(function() { initLoopy(true); }, 2500);
  45. window.setTimeout(function() { initLoopy(false); }, 3000);
  46. window.setTimeout(function() { initLoopy(false); }, 3500);
  47.  
  48. function initLoopy(addElement) {
  49. if (addElement) { document.getElementById("watch8-secondary-actions").appendChild(loopy); }
  50. ytPlayer = document.getElementById("movie_player");
  51. ytPlayer.addEventListener("onStateChange", "onPlayerStateChange");
  52. }
  53.  
  54. onPlayerStateChange = function(newState) {
  55. if (ytLoop && newState == "0"){
  56. window.setTimeout(function() { ytPlayer.playVideo(); }, 60);
  57. }
  58. }
  59.  
  60. LoopyOnOff = function() {
  61. if (ytLoop) {
  62. document.getElementById("loopyButton").setAttribute("data-tooltip-text", "Enable auto loop");
  63. document.getElementById("loopyButton").setAttribute("data-button-toggle", "true");
  64. document.getElementById("loopyContent").setAttribute("class", lpConOff);
  65.  
  66. ytLoop = false;
  67. } else {
  68. document.getElementById("loopyButton").setAttribute("data-tooltip-text", "Disable auto loop");
  69. document.getElementById("loopyButton").setAttribute("data-button-toggle", "false");
  70. document.getElementById("loopyContent").setAttribute("class", lpConOn);
  71. ytLoop = true;
  72. }
  73. }
  74.  
  75. function getCookie(name) {
  76. var results = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
  77. if (results) {
  78. return unescape(results[2]);
  79. } else {
  80. return null;
  81. }
  82. }
  83.  
  84. function setCookie(name, value) {
  85. document.cookie = name + "=" + escape(value);
  86. }
  87.  
  88. if (typeof GM_addStyle == "undefined") {
  89. GM_addStyle = function(text) {
  90. var head = document.getElementsByTagName("head")[0];
  91. var style = document.createElement("style");
  92. style.setAttribute("type", "text/css");
  93. style.textContent = text;
  94. head.appendChild(style);
  95. }
  96. }
  97.  
  98. GM_addStyle(" \
  99. loopyButton:hover {\
  100. border: 0px none;} \
  101. img.LoopyOff{\
  102. background: url(\"http://i.imgur.com/jlhKt.png\") -0px -0px no-repeat transparent !important;\
  103. height: 18px;\
  104. width: 30px;}\
  105. img.LoopyOn{\
  106. background: url(\"http://i.imgur.com/jlhKt.png\") -0px -18px no-repeat transparent !important;\
  107. height: 18px;\
  108. width: 30px;}"
  109.  
  110. );
  111. };
  112.  
  113. document.body.appendChild(document.createElement("script")).innerHTML = "("+myScript+")()";