Advertisement
Chronos_Ouroboros

Untitled

May 30th, 2015
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Clean Loopy For Youtube (Improved)
  3. // @namespace VolkanK_CL_YT
  4. // @description Displays a link below YouTube videos to enable/disable auto replay.
  5. // @include *://*.youtube.com/*
  6. // @match *://*.youtube.com/*
  7. // @credits QuaraMan (embed code) .Paradise (List Loop Support) RowenStipe (GreasyFork mirror)
  8. // @version 1.9
  9. // @author Volkan K.
  10. // ==/UserScript==
  11.  
  12. myScript = function() {
  13.  
  14. var ytLoop = false;
  15. var ytPlayList;
  16. var ytPLIndex;
  17. 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
  18. var lpConOff = "LoopyOff"
  19. var lpConOn = "LoopyOn";
  20.  
  21. loopy = document.createElement("button");
  22. loopy.id = "eLoopy";
  23. loopy.setAttribute("onClick", "LoopyOnOff(); return false;");
  24. loopy.setAttribute("class", lpButton);
  25. loopy.setAttribute("role", "button");
  26. loopy.setAttribute("data-button-toggle", "true");
  27. loopy.setAttribute("type", "button");
  28. loopy.setAttribute("data-tooltip-text", "Enable auto replay")
  29. loopy.id = "loopyButton";
  30.  
  31. a = document.createElement("span");
  32. 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"/>';
  33.  
  34.  
  35. loopy.appendChild(a);
  36.  
  37. window.setTimeout(function() { initLoopy(true); }, 2500);
  38. window.setTimeout(function() { initLoopy(false); }, 3000);
  39. window.setTimeout(function() { initLoopy(false); }, 3500);
  40.  
  41. function initLoopy(addElement) {
  42. if (addElement) { document.getElementById("watch8-secondary-actions").appendChild(loopy); }
  43. ytPlayer = document.getElementById("movie_player");
  44. ytPlayer.addEventListener("onStateChange", "onPlayerStateChange");
  45. }
  46.  
  47. onPlayerStateChange = function(newState) {
  48. if (ytLoop && newState == "0"){
  49. window.setTimeout(function() { ytPlayer.playVideo(); }, 60);
  50. }
  51. }
  52.  
  53. LoopyOnOff = function() {
  54. if (ytLoop) {
  55. document.getElementById("loopyButton").setAttribute("data-tooltip-text", "Enable auto loop");
  56. document.getElementById("loopyButton").setAttribute("data-button-toggle", "true");
  57. document.getElementById("loopyContent").setAttribute("class", lpConOff);
  58.  
  59. ytLoop = false;
  60. } else {
  61. document.getElementById("loopyButton").setAttribute("data-tooltip-text", "Disable auto loop");
  62. document.getElementById("loopyButton").setAttribute("data-button-toggle", "false");
  63. document.getElementById("loopyContent").setAttribute("class", lpConOn);
  64. ytLoop = true;
  65. }
  66. }
  67.  
  68. function getCookie(name) {
  69. var results = document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
  70. if (results) {
  71. return unescape(results[2]);
  72. } else {
  73. return null;
  74. }
  75. }
  76.  
  77. function setCookie(name, value) {
  78. document.cookie = name + "=" + escape(value);
  79. }
  80.  
  81. if (typeof GM_addStyle == "undefined") {
  82. GM_addStyle = function(text) {
  83. var head = document.getElementsByTagName("head")[0];
  84. var style = document.createElement("style");
  85. style.setAttribute("type", "text/css");
  86. style.textContent = text;
  87. head.appendChild(style);
  88. }
  89. }
  90.  
  91. GM_addStyle(" \
  92. loopyButton:hover {\
  93. border: 0px none;} \
  94. img.LoopyOff{\
  95. background: url(\"http://i.imgur.com/jlhKt.png\") -0px -0px no-repeat transparent !important;\
  96. height: 18px;\
  97. width: 30px;}\
  98. img.LoopyOn{\
  99. background: url(\"http://i.imgur.com/jlhKt.png\") -0px -18px no-repeat transparent !important;\
  100. height: 18px;\
  101. width: 30px;}"
  102.  
  103. );
  104. };
  105.  
  106. // get the raw window object of the YouTube page
  107. uw = typeof unsafeWindow !== 'undefined' ? unsafeWindow : unwrap(window);
  108.  
  109. // disable Red Bar aka SPF
  110. if (uw._spf_state && uw._spf_state.config) {
  111. uw._spf_state.config['navigate-limit'] = 0;
  112. uw._spf_state.config['navigate-part-received-callback'] = function (targetUrl) {
  113. location.href = targetUrl;
  114. };
  115. }
  116.  
  117. if ( /^\/?watch/i.test(window.location.pathname) ) {
  118. document.body.appendChild(document.createElement("script")).innerHTML = "("+myScript+")()";
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement