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.3
// @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();
    SetTimeEvent();

})();

function SetTimeEvent(){

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

}

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


function SetLinesOfLyricsToTimelineTable(_lines) {

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

    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();
        }
        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();
            }
        }
    }