0
1

More than 3 years have passed since last update.

YouTubeの日本語以外のコメントを非表示にする拡張機能を作った(けどあまりうまく動作しなかった)話

Posted at

はじめに

過去の投稿欄を読んでもらうと分かると思うかもしれないんdねすけど、最近(特に大学院入試前とか)Vtuberの配信をめっちゃくちゃ見ていました。中でもホロライブの配信を見るのが特に多いんですけどコメント欄の英語率のまあ高いこと。アーカイブのコメントを見ようと思ったときに英語で埋め尽くされるのもまーどうかなって感じで色々と探したんですけどそのたぐいの拡張機能が見つからなかったので頑張って作りました。

コード部分

・manifest.json

{
    "manifest_version":2,
    "name":"HideENGCommentsOnStream",
    "version":"1.0.1",
    "description":"YouTubeの生配信での日本語以外で表記されているコメントを非表示にします。",
    "content_scripts":[
        {
            "matches":["https://www.youtube.com/watch*"],
            "js":["hide_engcomeonstream.js"]
        }
    ]
}

・実行部分

function DelABComment(){
    let elms__ = document.querySelectorAll("[id='message']");
    const japa = /[\u{3000}-\u{301C}\u{3041}-\u{3093}\u{309B}-\u{309E}]/mu;
    for(let i = 0; i < elms__.length; i++){
        console.log(elms__[i].innerHTML);
        //content[i] = content[i].split('<span dir="auto" class="style-scope yt-formatted-string">').join('');
        //content[i] = content[i].split('</span>').join('');
        if(!(japa.test(elms__[i].innerHTML)) && (elms__[i].innerHTML.indexOf('</path>') == -1)){
            elms__[i].parentNode.parentNode.remove();
        }
    }
}

function initialize(){
    let observer = new MutationObserver(DelABComment);
    observer.observe(document.getElementById('chat-messages'), {
       attributes: true,
       childList:  true
    });
}

window.onload = function(){
    initialize();
    DelABComment();
}

chat-messagesのローディングが入るたびにDelABCommentを実行する感じです。

理想の挙動

https://www.youtube.com/watch?v=kWPQyCIKTtk に対して

image.png

これが

image.png

こうなる感じ。

未解決部分

https://www.youtube.com/watch?v=AAr2lHZLNyU のような、プレミアム動画やアーカイブとして残されている動画だとこれが動作しません...リアルタイムコメントの方が干渉しているのかもしれないです。何か良い解決方法があったらご教授お願い致します。

0
1
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
1