bilibili 自動字幕轉換(簡體轉繁體)

For bilibili videos

  1. // ==UserScript==
  2. // @name bilibili 自動字幕轉換(簡體轉繁體)
  3. // @name:en bilibili Auto Subtitle Translation (Simplified Chinese -> Traditional Chinese)
  4. // @name:zh-TW bilibili 自動字幕轉換(簡體轉繁體)
  5. // @name:zh-CN bilibili 自动字幕转换(简体转繁体)
  6. // @description:en For bilibili videos
  7. // @description:zh-tw For bilibili videos
  8. // @description:zh-cn For bilibili videos
  9. // @namespace http://tampermonkey.net/
  10. // @version 0.1.7
  11. // @description For bilibili videos
  12. // @author CY Fung
  13. // @match https://www.bilibili.com/*
  14. // @icon https://www.google.com/s2/favicons?domain=bilibili.com
  15. // @require https://greasyfork.org/scripts/430412-chinese-conversion-api/code/Chinese%20Conversion%20API.js?version=957744
  16. // @license MIT
  17. // @run-at document-start
  18. // @grant none
  19. // ==/UserScript==
  20.  
  21. const {sc2tc} = window.ChineseConversionAPI;
  22.  
  23. (function() {
  24. 'use strict';
  25. const hKey_json_parse='rhlxuprkmayw'
  26.  
  27. JSON.parse[hKey_json_parse]||!(() => {
  28.  
  29. const $$parse=JSON.parse;
  30. JSON.parse=function(){
  31. if(typeof arguments[0]=='string' && arguments[0].length>16){
  32. if(/"(from|to|location)"\s*:\s*[\d\.]+/.test(arguments[0])){
  33. arguments[0]= sc2tc(arguments[0])
  34. }
  35. }
  36. return $$parse.apply(this,arguments)
  37. }
  38. JSON.parse.toString=()=>$$parse.toString();
  39. JSON.parse[hKey_json_parse]=true
  40.  
  41.  
  42. })();
  43.  
  44.  
  45.  
  46. })();
  47.  
  48.  
  49. (function $$() {
  50. 'use strict';
  51.  
  52. if(!document||!document.documentElement) window.requestAnimationFrame($$)
  53.  
  54. function addStyle (styleText) {
  55. const styleNode = document.createElement('style');
  56. styleNode.type = 'text/css';
  57. styleNode.textContent = styleText;
  58. document.documentElement.appendChild(styleNode);
  59. return styleNode;
  60. }
  61.  
  62. addStyle(`
  63. .bilibili-player-video-subtitle .subtitle-item-text{
  64. font-family: system-ui;
  65. }
  66. `)
  67.  
  68. })();