Typingtube拡張new02

・。・

当前为 2023-09-20 提交的版本,查看 最新版本

// ==UserScript==
// @name         Typingtube拡張new02
// @license MIT
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  ・。・
// @author       つべ
// @match       https://typing-tube.net/movie/show*
// @icon         https://www.gEoogle.com/s2/favicons?sz=64&domain=typing-tube.net
// @grant        none
// ==/UserScript==
const settings = {
    videoBelow: true,         // 動画を下に配置
    scroll: true,     // 指定場所までエンターでスクロール
    showKPM: true,           // KPM表示
    showPossibleScore: true, // 達成可能スコア表示
};

const scrollDistance = -49;
/*指定場所までエンターでスクロールが有効のときのみ*/
/*スクロールの高さ調整。マイナスにすると上に、プラスにすると下に行きます。*/

function moveVideoBelow(){
    const YOUTUBE = document.getElementById("youtube-movie");
    const TYPING_AREA = document.getElementById("controlbox");
    YOUTUBE.parentNode.insertBefore(YOUTUBE,TYPING_AREA.nextSibling);
    /*動画下に表示  Toshi氏のを借用*/
}

function addTypingLineListContainer(){
    document.getElementsByClassName('modal-content')[1].insertAdjacentHTML('beforeend',`<div class="modal-body" id="typing-line-list-container"></div>`);
}
/*F4等で消えてしまったResult表示のdivを追加*/

function hideRanks(){
    document.getElementById('status').style.display = 'block'
    document.getElementById('ranking_roma').style.display = 'none'
    document.getElementById('ranking_kana').style.display = 'none'
    document.getElementById('ranking_flick').style.display = 'none'
};
/*エンターを押したら下の表示をstatusに切り替えてその他を表示しなくする*/

function updateKPMAndPossibleScore() {
    if (!is_played) return;

    if (settings.showKPM && !document.getElementById('line-speed-kpm')) {
        document.getElementById('line_remaining_time').insertAdjacentHTML("beforeend", ` - <span id="line-speed-kpm">0KPM</span>`);
    }

    if (settings.showPossibleScore && !document.getElementById('PS')) {
        document.getElementById('score-value').insertAdjacentHTML("afterend", `<span id="PS" style="font-size: 0.7em; color: rgb(204, 153, 204);">0</span>`);
    }

    if (settings.showKPM) {
        document.getElementById("line-speed-kpm").textContent = `${Math.floor(line_typingspeed * 60)}KPM`;
    }

    if (settings.showPossibleScore) {
        const possibleScore = (200000 - escape_score) / 2000;
        document.getElementById("PS").textContent = Math.round(possibleScore * 100) / 100;
    }
}

document.addEventListener('keydown', (e) => {
    if (is_played) {
        updateKPMAndPossibleScore();
    }

    if (e.code === 'Enter' && settings.scroll) {
        document.getElementById("gauge").scrollIntoView(true);
        scrollBy(0, scrollDistance);
        hideRanks();
    }

    if (e.code === 'F4') {
        addTypingLineListContainer();
    }
});

document.getElementById('restart').addEventListener('click', addTypingLineListContainer);

if (settings.videoBelow) {
    moveVideoBelow();
}