Indie_Developer
Membre
- Inscription
- 2 Avril 2015
- Messages
- 1 540
- Réactions
- 732
- Points
- 4 731
Code:
// ==UserScript==
// @name Auto Replay
// @namespace http://qcl.tw/
// @version 0.1.2
// @description Auto re-play youtube vedio.
// @match *://www.youtube.com/watch?v=*
// @copyright 2012+, Qing-Cheng Li (qcl).
// @require https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// ==/UserScript==
var replay = false;
var clickLock = false;
var id = 1;
function checkReplay(){
//console.log("!");
if( $(".ytp-time-current").html() == $(".ytp-time-duration").html() && replay ){
if(!clickLock){
clickLock = true;
$(".ytp-button-replay").trigger("click");
}
}else{
clickLock = false;
}
};
var p = $(".html5-player-chrome")[0];
var $btn = $("<button id='qcl-replay-btn' class='html5-text-button html5-threed-button yt-uix-button-reverse ytp-tooltip-anchor flip hid yt-uix-button yt-uix-button-player yt-uix-button-size-default' type='button' data-tooltip='重複播放開關' role='button' aria-pressed='false' aria-expanded='false' aria-haspopup='true' aria-activedescendant='' aria-label='重複播放'><span id='qcl-replay-text' class='yt-uix-button-content'>開啟重播</span></button>");
$btn.insertAfter(p.firstChild);
var $text = $("#qcl-replay-text");
$btn.click(function(){
//console.log("click");
if(replay){
replay = false;
window.clearInterval(id);
$text.html("開啟重播");
}else{
replay = true;
clickLock = false;
id = self.setInterval(function(){ checkReplay(); },1000);
$text.html("關閉重播");
}
});