lrcReader[typing-tube.net]

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

目前為 2019-10-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
        //----------------------------------------------------
    }
}