Greasy Fork is available in English.
Auto play for bs.to (still a little bit buggy und not clean. Only working for Vivo)
当前为
// ==UserScript==
// @name bs.to autoplay
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Auto play for bs.to (still a little bit buggy und not clean. Only working for Vivo)
// @author xZaheer
// @match *://bs.to/serie/*
// @match *://vivo.sx/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_openInTab
// @grant window.close
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// ==/UserScript==
(function() {
'use strict';
handleSiteReload();
if(isLoggedIn()) {
addAutoPlayButton();
}
})();
function handleSiteReload() {
console.log('handle site load', GM_getValue('continue'))
if(GM_getValue('continue')) {
let functionToContinue = GM_getValue('continue');
console.log("continue with", functionToContinue);
eval(functionToContinue);
}
}
function isLoggedIn() {
let logoutButtonElem = document.querySelector("#root > header > section > a:nth-child(4)");
return (logoutButtonElem) ? true : false;
}
function addAutoPlayButton() {
let location = document.querySelector("#root > section > div.selectors");
let buttonElem = document.createElement('button');
buttonElem.innerHTML = "Auto Play";
buttonElem.addEventListener('click', onPlayButtonClick);
location.appendChild(buttonElem);
}
function onPlayButtonClick() {
navigateNextEpisodeToWatch();
}
function navigateToHoster() {
let vivoButton = document.querySelector("#root > section > ul.hoster-tabs.top > li > a > i.vivo");
if(!vivoButton) {
alert("sorry. autoplay only working with vivo.")
GM_deleteValue("continue");
return;
}
if(vivoButton.parentElement.parentElement.classList[0] !== "active") {
vivoButton.click();
}
GM_setValue('continue', "handleVivo('play')");
setTimeout(() => {
let playerElem = document.querySelector("section.serie .hoster-player");
let clickEvent = new Event("click");
clickEvent.which = 1;
clickEvent.pageX = 1;
clickEvent.pageY = 1;
playerElem.dispatchEvent(clickEvent);
setInterval(() => {
let captcha = document.querySelector("#rc-imageselect");
if(!captcha) {
window.close();
}
}, 5000)
}, 1000)
}
function navigateNextEpisodeToWatch() {
GM_setValue('continue', 'navigateNextEpisodeToWatch()');
let nextEpisode = document.querySelector("#root > section > table > tbody > tr:not(.watched)");
if(nextEpisode) {
GM_setValue("last", window.location.href);
GM_setValue('continue', 'navigateToHoster()');
let nextEpisodeUrl = nextEpisode.querySelector("td:nth-child(2) > a:nth-child(2)").href;
window.location.href = nextEpisodeUrl;
return;
}
let nextSession = document.querySelector("#seasons > ul > .active + li > a").href;
if(nextSession) {
window.location.href = nextSession;
return;
}
}
function handleVivo(action) {
window.addEventListener("beforeunload", window.close);
if(action === "play") {
let playButton = document.querySelector("body > div.vivo-website-wrapper > section > div > div.vivo-content-box.vivo-content-box-watch.col-md-12.col-sm-12.col-xs-12 > div.stream-content > div > button");
let fullscreenButton = document.querySelector("body > div.vivo-website-wrapper > section > div > div.vivo-content-box.vivo-content-box-watch.col-md-12.col-sm-12.col-xs-12 > div.stream-content > div > div.plyr__controls > button:nth-child(9)");
if(playButton) {
playButton.click();
fullscreenButton.click();
}
setTimeout(() => {
if(playButton.getAttribute("aria-label") === "Pause") {
GM_deleteValue("continue");
window.setInterval(() => {
let running = document.querySelector("body > div.vivo-website-wrapper > section > div > div.vivo-content-box.vivo-content-box-watch.col-md-12.col-sm-12.col-xs-12 > div.stream-content > div > div.plyr__controls > div.plyr__controls__item.plyr__time--current.plyr__time");
let max = document.querySelector("body > div.vivo-website-wrapper > section > div > div.vivo-content-box.vivo-content-box-watch.col-md-12.col-sm-12.col-xs-12 > div.stream-content > div > div.plyr__controls > div.plyr__controls__item.plyr__time--duration.plyr__time");
if(running.innerHTML !== "00:00" && running.innerHTML === max.innerHTML) {
GM_setValue("continue", "navigateNextEpisodeToWatch()");
GM_openInTab(GM_getValue("last"));
setTimeout(window.close, 100);
}
}, 2000)
}
}, 2000)
}
}