Where is magnet!(Modified)

琉璃神社磁链高亮(修改版)

  1. // ==UserScript==
  2. // @name Where is magnet!(Modified)
  3. // @license GPL version 3
  4. // @encoding utf-8
  5. // @namespace https://sinon.top/
  6. // @version 1.3
  7. // @description 琉璃神社磁链高亮(修改版)
  8. // @author SinonJZH
  9. // @match https://www.liuli.se/*
  10. // @match https://www.liuli.pl/*
  11. // @match https://www.liuli.app/*
  12. // @match https://www.liuli.cat/*
  13. // @match https://www.hacg.cat/*
  14. // @match https://www.hacg.mom/*
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. /* ---------配置项--------- */
  20. //指定链接显示的颜色,默认为#00FFFF
  21. const LINK_COLOR = '#00FFFF'
  22. //指定磁链按钮文字颜色,默认为black
  23. const BUTTON_TEXT_COLOR = 'black'
  24. //指定磁链按钮颜色,默认为#00FFFF
  25. const BUTTON_BACKGROUND = '#00FFFF'
  26. /* ------------------------ */
  27. 'use strict';
  28. addLoadEvent(main());
  29.  
  30. function addLoadEvent(func)
  31. {
  32. var oldOnload = window.onload;
  33. if (typeof window.onload != "function") {
  34. window.onload = func;
  35. } else {
  36. window.onload = function() {
  37. oldOnload();
  38. func();
  39. }
  40. }
  41. }
  42.  
  43. function main()
  44. {
  45. if (typeof jQuery === 'undefined') {
  46. return;
  47. }
  48. if (!jQuery("body").hasClass("single")) {
  49. return
  50. }
  51. var container = jQuery('.entry-content');
  52. if (container.length === 0) {
  53. return;
  54. }
  55. var rawHtml = container.html();
  56. var url = "";
  57. var title = jQuery("h1.entry-title");
  58. var count = 0;
  59. container.html(rawHtml.replace(/([a-fA-F0-9]{40})/g, function (a, b) {
  60. url = `magnet:?xt=urn:btih:${b}`;
  61. count = count+1;
  62. title.before('<a href="' + url + '" style="background-color: '+ BUTTON_BACKGROUND +'; border: none; color: '+ BUTTON_TEXT_COLOR +'; padding: 10px 10px; text-align: center; text-decoration: none; display: inline-block; font-size: 12px; border-radius: 12px;float: left;">发现磁链'
  63. + count.toString() + '</a>');
  64. return `<br><a style="color: `+ LINK_COLOR +`;font-weight: bold;font-size: 120%" href="${url}">${b}</a><br>`;
  65. }));
  66. if(count == 0){
  67. title.before('<a href="' + url + '" style="background-color: red; border: none; color: black; padding: 10px 10px; text-align: center; text-decoration: none; display: inline-block; font-size: 12px; border-radius: 12px;float: left;">未发现磁链</a>');
  68. }
  69. }
  70. })();