lrcDownloader[typing-tube.net]

Typing Tubeの編集画面にlrcファイルのダウンロードリンクを追加します。

  1. // ==UserScript==
  2. // @name lrcDownloader[typing-tube.net]
  3. // @namespace TyepingTubeLrcDownloader
  4. // @version 1.4
  5. // @description Typing Tubeの編集画面にlrcファイルのダウンロードリンクを追加します。
  6. // @author aetenotnk
  7. // @match https://typing-tube.net/movie/edit/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. function CreateDownloadElement(){
  12. var editTab = $("#edit");
  13.  
  14. if(!editTab.length){
  15. return false;
  16. }
  17.  
  18. var downloadDiv = $("<div>");
  19. downloadDiv.addClass("row");
  20. downloadDiv.addClass("ml-2");
  21. downloadDiv.addClass("w-100");
  22. downloadDiv.attr("id", "lrcDownLoader");
  23. editTab.append(downloadDiv);
  24.  
  25. var downloadLink = $("<a>");
  26. downloadLink.attr("id", "lrcDwonloadLink");
  27. downloadLink.attr("download", $("#title").attr("value") + ".lrc");
  28. downloadLink.attr("href", "dummy");
  29. downloadLink.addClass("col-2");
  30. downloadLink.text("lrcファイルをダウンロード");
  31. downloadLink.click(GetLyrics);
  32.  
  33. downloadDiv.append(downloadLink);
  34.  
  35. return true;
  36. }
  37.  
  38. function SetDownloadLinkFile(text){
  39. var downloadLink = $("#lrcDwonloadLink");
  40. var file = new Blob([text], {type: "text/plain"});
  41. downloadLink.attr("href", URL.createObjectURL(file));
  42. }
  43.  
  44. function GetLyrics(){
  45. var lyrics = $("#subtitles_table > tbody > tr");
  46. var lyricList = [];
  47.  
  48. for(var i = 1; i < lyrics.length - 1; i++){
  49. var tds = $(lyrics[i]).find("td");
  50. var time = $(tds[0]).text().replace(" ", "");
  51. var lyric = $(tds[1]).text();
  52.  
  53. lyricList.push({
  54. second: time,
  55. lyric: lyric
  56. });
  57. }
  58.  
  59. SetDownloadLinkFile(FormatLRC(lyricList));
  60. }
  61.  
  62. function FormatLRC(lyricList){
  63. var rowFormat = "[mm:ss.xx]lyric";
  64. var lines = [];
  65.  
  66. for(var i = 0; i < lyricList.length; i++){
  67. var time = lyricList[i].second;
  68. var timeParts = time.split(".");
  69. var mm = ("00" + parseInt(parseInt(time) / 60)).slice(-2);
  70. var ss = ("00" + (parseInt(time) - mm * 60)).slice(-2);
  71. var xx = timeParts.length > 1 ? ("00" + timeParts[timeParts.length - 1]).slice(-2) : "00";
  72.  
  73. lines.push(
  74. rowFormat
  75. .replace("mm", mm)
  76. .replace("ss", ss)
  77. .replace("xx", xx)
  78. .replace("lyric", lyricList[i].lyric));
  79. }
  80.  
  81. return lines.join("\n");
  82. }
  83.  
  84. CreateDownloadElement();