fanyi

翻译库

当前为 2024-08-18 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/503008/1430138/fanyi.js

  1. // ==UserScript==
  2. // @name fanyi
  3. // @namespace fireloong
  4. // @version 0.0.12
  5. // @description 翻译库
  6. // @author Itsky71
  7. // @grant none
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. function fanyi(translates, id, dev = false, delay = false){
  12. let doc;
  13. if(typeof id === 'number'){
  14. switch(id){
  15. case 1:
  16. doc = '.toctree a,.ui-heading > h1,.ui-prose > .section p,.ui-prose > .section li,.ui-prose > .section h2>a,.ui-prose > .section h3>a,.ui-prose > .section h4>a,.ui-prose > .section dl>dt,.ui-prose > .section dl > dd,.hljs-comment';
  17. break;
  18. case 2:
  19. doc = '.ui-heading > h1,.ui-prose .section > h2 > a,.ui-prose p,.pagination-item > a,.pagination-item > span,.ui-prose li';
  20. break;
  21. default:
  22. break;
  23. }
  24. } else {
  25. doc = id;
  26. }
  27. const myFunc = (bb) => {
  28. $(bb).html(translates[$(bb).text()]);
  29. };
  30.  
  31. let n = 0;
  32. let jsonStr = '';
  33. $(doc).each(function(i,v){
  34. if(translates.hasOwnProperty($(this).text())) {
  35. if(typeof delay === 'number'){
  36. setTimeout(myFunc, delay, this);
  37. } else {
  38. $(this).html(translates[$(this).text()]);
  39. }
  40. } else if(dev) {
  41. console.log(n,v,$(this).text());
  42. jsonStr += '\''+$(this).text().replaceAll('\\','\\\\').replaceAll('\'','\\\'').replaceAll("\n",'\\n')+'\': \'\','+"\n";
  43. n++;
  44. }
  45. });
  46. if(dev){
  47. console.info(jsonStr);
  48. }
  49. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址