tiktok.js
// ==UserScript==
// @name tiktok
// @namespace http://tampermonkey.net/
// @version 1.0
// @description move to next video on videoend
// @author Yugo Yamamoto
// @match https://www.tiktok.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=symmetric.co.jp
// @grant none
// ==/UserScript==
function movenext(){
console.log("ended");
let event = new Event("click",{bubbles: true});
let button = document.querySelector("button[data-e2e=arrow-right]");
if ( !button ) {return; }
button.dispatchEvent(event);
}
(function() {
'use strict';
setInterval(function(){
let videos = document.getElementsByTagName('video');
if (videos.length == 0){
return;
}
videos[0].addEventListener('ended',movenext);
},1000);
})();
これで連続再生ができる。
videoタグでvideoを再生しているので、videoが終わったときのendedのイベントが取得できる。
実際に動かしてるのは、PC上のChrome + Tampermonkey。
本当はドキュメントがロードされた後にvideoタグにaddEventListenerをつければよかったんだけど、タイミングによってはvideoタグが存在しない時があったので、定期的にvideoタグを探しに行くスクリプトにした。