GreasyFork - 在“代码”中显示 jQuery 警告

在查看 Greasy Fork 代码页时,通过判断 @require 行中是否有 jquery,显示特大号红色 jQuery 警告。

  1. // ==UserScript==
  2. // @name GreasyFork - jQuery Warning in the Code Tab
  3. // @name:zh-CN GreasyFork - 在“代码”中显示 jQuery 警告
  4. // @description Match "jquery" in @require lines and show large jQuery warning when you are checking out the Code tab on Greasy Fork.
  5. // @description:zh-CN 在查看 Greasy Fork 代码页时,通过判断 @require 行中是否有 jquery,显示特大号红色 jQuery 警告。
  6. // @namespace RainSlide
  7. // @author RainSlide
  8. // @icon https://greasyfork.org/packs/media/images/blacklogo96-b2384000fca45aa17e45eb417cbcbb59.png
  9. // @version 1.2.1
  10. // @license blessing
  11. // @match https://greasyfork.org/*/scripts/*/code
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. "use strict";
  16.  
  17. const pre = document.querySelector('.code-container > pre');
  18. if (
  19. pre !== null &&
  20. /\n[ \t]*\/\/[ \t]*@require[ \t]+.+?jquery/.test(pre.textContent)
  21. ) {
  22. const p = document.createElement("p");
  23. const strong = document.createElement("strong");
  24. p.style = "text-align: center;";
  25. strong.textContent = "jQuery!!!";
  26. strong.style = "color: red; font-size: 5em;";
  27. p.appendChild(strong);
  28. pre.parentNode.parentNode.insertBefore(p, pre.parentNode);
  29. }