Greasy Fork 还支持 简体中文。

Fix kbin Code Blocks

Dirty fix for kbin code blocks federated from Lemmy. Strips out the weird <span> tags on each line.

目前為 2023-11-15 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Fix kbin Code Blocks
  3. // @namespace pamasich-kbin
  4. // @version 1.0.1
  5. // @description Dirty fix for kbin code blocks federated from Lemmy. Strips out the weird <span> tags on each line.
  6. // @author Pamasich
  7. // @match https://kbin.social/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=kbin.social
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. window.addEventListener('load', function() {
  17. for (let codeblock of document.querySelectorAll('pre code')) {
  18. let output = "";
  19. let found = false;
  20. for (let line of codeblock.innerHTML.split('\n')) {
  21. if (found == true) {
  22. line = line.slice(13, line.length);
  23. found = false;
  24. }
  25. if (line.startsWith('&lt;span style=\"color:#323232;\"&gt;')) {
  26. line = line.slice(35, line.length);
  27. found = true;
  28. }
  29. output += "\n" + line;
  30. }
  31. codeblock.innerHTML = output.slice(1,output.length);
  32. }
  33. });
  34. })();