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.31
// @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 "edit".
    var elDiv = document.createElement("div");
    elDiv.classList.add('row');
    elDiv.classList.add('ml-2');
    elDiv.classList.add('w-100');
    elDiv.id = "ContainerOflrcReader";
    var elEdit = document.getElementById("edit");
    elEdit.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){
    SetTimeEvent();

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

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

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



var isKanaMode; //load mode of kana or english
var lineidx = 0;
var time;
var editedLine;
var lines;
var timeEventFlag;

function SetTimeEvent(){

    setTimeout(() => {
        if(document.getElementById("kana").value.length != 0){
            hoge();
        }
        if(timeEventFlag){
            SetTimeEvent();
        }
    }, 20);

}

function SetLinesOfLyricsToTimelineTable(_lines) {

    isKanaMode = document.getElementById('lrcConverTypeKana').checked;
    lineidx = 0;
    lines = _lines;
    timeEventFlag = true;

    retriveLineInfo();
}


function retriveLineInfo(){

    var line = lines[lineidx++];

    //if empty line then check next line.
    var ptnOfTimeTag = /\[\d\d:\d\d:\d\d\]/g;
    if(ptnOfTimeTag.test(line) == false){
        if(lineidx < lines.length){
            retriveLineInfo();
        }else{
             timeEventFlag = false;
        }
        return;
    }

    //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);

    //Add time and lineLyrics to the timeline Table in the navigation menu "edit".
    document.getElementById("time").value = time;
    document.getElementById("words").value = editedLine;

    if(isKanaMode){
        command_kakasi();
    }else{
        command_kakasi_en();
    }
}


function hoge(){
        console.log("hoge");
        if( document.getElementById("kana").value.length != 0){
            command_add();
            if(lineidx < lines.length){
                retriveLineInfo();
            }else{
             timeEventFlag = false;
            }
        }
    }