0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

TikTokで連続再生するためのGreasemonkeyスクリプト

Last updated at Posted at 2022-04-09
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タグを探しに行くスクリプトにした。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?