Last active
January 3, 2016 18:35
-
-
Save dumptyd/66631621730f15ff3688 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Loop | |
// @namespace dumptyd | |
// @description Adds a loop button on YouTube videos | |
// @include https://www.youtube.com/watch?v=* | |
// @version 1.5.5 | |
// @grant none | |
// @require https://code.jquery.com/jquery-2.1.4.min.js | |
// ==/UserScript== | |
vscript=document.createElement('script'); | |
vscript.src='https://code.jquery.com/jquery-2.1.4.min.js'; | |
vscript.type='text/javascript'; | |
vscript.id='fuck'; | |
document.getElementsByTagName('head')[0].appendChild(vscript); | |
timer = ''; | |
button='<button status="0" style="color:#fff; border:1px solid #f00; position:absolute; right:112px; top:13px; width:50px; cursor:pointer; background-color:transparent; border-radius:20px ; font-weight:bold;" id="loopBtn">Loop</button>' | |
$('.ytp-right-controls').prepend(button); | |
url=window.location.href; | |
$('#loopBtn').on('click', function() { | |
if ($('#loopBtn').attr('status') == '0') | |
loopEnable(); | |
else if ($('#loopBtn').attr('status') == '1') | |
loopDisable(); | |
}) | |
function checkVideo() | |
{ | |
var currentTime = $('.ytp-time-current').text(); | |
var duration = $('.ytp-time-duration').text(); | |
var currentUrl=window.location.href; | |
if(url!=currentUrl) | |
loopDisable(); | |
if (currentTime == duration) | |
$('.ytp-play-button').trigger('click'); | |
} | |
function loopDisable() | |
{ | |
$('#loopBtn').css('background-color', 'transparent'); | |
clearInterval(timer); | |
$('#loopBtn').attr('status' , '0'); | |
} | |
function loopEnable() | |
{ | |
$('#loopBtn').css('background-color','#f00'); | |
timer = setInterval(function () | |
{ | |
checkVideo() | |
}, 3000); | |
$('#loopBtn').attr('status','1'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment