Fix kbin Code Blocks

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

当前为 2023-11-14 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Fix kbin Code Blocks
  3. // @namespace pamasich-kbin
  4. // @version 1.0
  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. console.log(line);
  22. if (found == true) {
  23. line = line.slice(13, line.length);
  24. found = false;
  25. }
  26. console.log(line);
  27. if (line.startsWith('&lt;span style=\"color:#323232;\"&gt;')) {
  28. line = line.slice(35, line.length);
  29. found = true;
  30. }
  31. output += "\n" + line;
  32. }
  33. codeblock.innerHTML = output.slice(1,output.length);
  34. }
  35. });
  36. })();