修复LANraragi上传页文件名乱码

修复Lanraragi上传页面中的乱码标题,并追加原始链接。使用页面内置的jQuery以避免冲突。请先修改下面的@match段以匹配您的Lanraragi基础URL。

  1. // ==UserScript==
  2. // @name Fix Garbled Titles in Lanraragi Upload
  3. // @name:zh-CN 修复LANraragi上传页文件名乱码
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.2.1
  6. // @description Fixes garbled titles on the Lanraragi upload page and appends the original source link. Utilizes the page's built-in jQuery to avoid conflicts. Please modify the @match section below to match your Lanraragi BaseURL.
  7. // @description:zh-CN 修复Lanraragi上传页面中的乱码标题,并追加原始链接。使用页面内置的jQuery以避免冲突。请先修改下面的@match段以匹配您的Lanraragi基础URL。
  8. // @author Jade
  9. // @match https://lanraragi.example.com/upload
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16.  
  17. // 等待页面 jQuery 加载完毕
  18. function waitForjQuery(callback) {
  19. const check = () => {
  20. if (typeof window.jQuery !== 'undefined') {
  21. callback(window.jQuery);
  22. } else {
  23. setTimeout(check, 100);
  24. }
  25. };
  26. check();
  27. }
  28.  
  29. waitForjQuery(function ($) {
  30. // 解码乱码
  31. function decodeGarbled(str) {
  32. try {
  33. return decodeURIComponent(escape(str));
  34. } catch {
  35. return str;
  36. }
  37. }
  38.  
  39. function isPureURL(str) {
  40. return /^https?:\/\/\S+$/i.test(str.trim());
  41. }
  42.  
  43. function fixTitleAndAppendURL($link) {
  44. if (!$link.length || $link[0].dataset.fixed) return;
  45. const href = $link.attr("href");
  46. if (!href || href === "#") return;
  47.  
  48. const originalText = $link.text();
  49. const fixedText = decodeGarbled(originalText);
  50.  
  51. if (originalText === fixedText || isPureURL(fixedText)) return;
  52.  
  53. $link.text(fixedText);
  54.  
  55. const url = $link.attr("title");
  56. if (url) {
  57. $link.after(`<br><a href="${url}" target="_blank" style="color:blue;">[Source Link]</a>`);
  58. }
  59.  
  60. $link[0].dataset.fixed = "true";
  61. }
  62.  
  63. function processAllLinks(root = document) {
  64. $(root)
  65. .find('a[id$="-name"]')
  66. .each(function () {
  67. fixTitleAndAppendURL($(this));
  68. });
  69. }
  70.  
  71. function observeAndFix() {
  72. const target = document.getElementById("files");
  73. if (!target) return;
  74.  
  75. const observer = new MutationObserver(mutations => {
  76. mutations.forEach(mutation => {
  77. mutation.addedNodes.forEach(node => {
  78. if (node.nodeType === 1) {
  79. processAllLinks(node);
  80. }
  81. });
  82.  
  83. if (mutation.type === "characterData" || mutation.type === "childList") {
  84. const parent = mutation.target.closest?.("a[id$='-name']");
  85. if (parent) fixTitleAndAppendURL($(parent));
  86. }
  87. });
  88. });
  89.  
  90. observer.observe(target, {
  91. childList: true,
  92. subtree: true,
  93. characterData: true,
  94. });
  95.  
  96. processAllLinks(target);
  97. }
  98.  
  99. $(document).ready(observeAndFix);
  100. });
  101. })();

QingJ © 2025

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