lrcReader[typing-tube.net]

Add buttons to load the .lrc format file on the edit screen on typing-tube.net.

当前为 2019-10-13 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         lrcReader[typing-tube.net]
// @namespace    http://tampermonkey.net/lrcReader
// @version      0.1
// @description  Add buttons to load the .lrc format file on the edit screen on typing-tube.net.
// @author       Spacia
// @match        https://typing-tube.net/movie/edit?videoid=*
// @grant        none
// ==/UserScript==


//This is the Entry point.
(function() {
    'use strict';

    AddLrcReaderElements();

})();


function AddLrcReaderElements(){

    // Add a div element to be container to the bottom of the navigation menu "Settings".
    var elDiv = document.createElement("div");
    elDiv.classList.add('row');
    elDiv.classList.add('ml-2');
    elDiv.classList.add('w-100');
    elDiv.id = "ContainerOflrcReader";
    var elSetting = document.getElementById("setting");
    elSetting.appendChild(elDiv);
    var elDevId = document.getElementById("ContainerOflrcReader");

    // Add a button for uploading .lrc format file in container created by former code.
    var elTextDiv = document.createElement("div");
    elTextDiv.classList.add("col-2");
    elTextDiv.innerHTML = "lrcファイルを参照";
    elDevId.appendChild(elTextDiv);

    var elForm = document.createElement("form");
    elForm.classList.add("col-6");
    elForm.innerHTML = "<div><input name='lrcFile' type='file' accept='.lrc'></div>";
    elForm.addEventListener('change', onLoadLrc);
    elDevId.appendChild(elForm);

    // Add radio buttons to select English or Kana.
    var elForm2 = document.createElement("form");
    elForm2.classList.add("col-4");
    elForm2.innerHTML = "<span style='padding-right:20px;'><label><input id='lrcConverTypeKana' name='lrcConvertType' type='radio' value='kana' checked>かな </label></span><span><label><input name='lrcConvertType' type='radio' value='eng'>英語</label></span>";
    elDevId.appendChild(elForm2);

}


function onLoadLrc(event){
    var _file = event.target.files[0];
    if(_file){
        var fr = new FileReader();
        fr.onload = function(e) {

            // A file was loaded.
            GetLinesOfLyrics(fr.result.split('\n'));

        }
        fr.readAsText(_file);
    }else{
        alert("Failed to load file formated .lrc");
    }
}


function GetLinesOfLyrics(lines) {


    var isKanaMode; //load mode of kana or english
    isKanaMode = document.getElementById('lrcConverTypeKana').checked;


    for(var i = 0;i < lines.length; ++i){
        var line = lines[i];

        var time;
        var editedLine;

        //if empty line then don't execute the rest of code.
        var ptnOfTimeTag = /\[\d\d:\d\d:\d\d\]/g;
        if(!ptnOfTimeTag.test(line)){continue;}

        //get time for this line.
        var ptnOfTwoDigidTime = /\d\d/g;
        var timesStr = line.match(ptnOfTwoDigidTime);
        var minute = parseFloat(timesStr[0]);
        var second = parseFloat(timesStr[1]);
        var centiSec = parseFloat(timesStr[2]);
        time = minute * 60 + second + centiSec * 0.01;
        //console.log(time);

        //get line of text.
        editedLine = line.replace(ptnOfTimeTag,"").trim();
        //console.log(editedLine);



        //bug-- ここが順次処理されればかんせいです。////////////////////////////////////////////////////////////////////////////////////
        //Add time and lineLyrics to the timeline Table in the navigation menu "edit".
        //time, 歌詞の項目に歌詞情報をぶち込みます。
        document.getElementById("time").value = time;
        document.getElementById("words").value = editedLine;

        //かな、または英語の変換ボタンを押します。(非同期、うまく順番通り処理されない)
//         if(isKanaMode){
//             command_kakasi();
//         }else{
//             command_kakasi_en();
//         }
        //tmp solution for english (代替としてよみにもそのまま歌詞ぶち込みます。)
        document.getElementById("kana").value = editedLine;

        //追加ボタンを押してタイムテーブルに追加します。////////////////////////////////////////////////////////////////////////////////////
        command_add();
        //----------------------------------------------------
    }
}