IdlePixel Chat Links

Make links great again.

目前为 2022-10-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name IdlePixel Chat Links
  3. // @namespace com.anwinity.idlepixel
  4. // @version 1.0.1
  5. // @description Make links great again.
  6. // @author Anwinity
  7. // @license MIT
  8. // @match *://idle-pixel.com/login/play*
  9. // @grant none
  10. // @require https://greasyfork.org/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
  11. // @require https://cdnjs.cloudflare.com/ajax/libs/anchorme/2.1.2/anchorme.min.js
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. class ChatLinksPlugin extends IdlePixelPlusPlugin {
  18. constructor() {
  19. super("chatlinks", {
  20. about: {
  21. name: GM_info.script.name,
  22. version: GM_info.script.version,
  23. author: GM_info.script.author,
  24. description: GM_info.script.description
  25. }
  26. });
  27. }
  28.  
  29. replaceLinks(message) {
  30. return anchorme({
  31. input: message,
  32. options: {
  33. attributes: {
  34. target: "_blank"
  35. }
  36. }
  37. }).replace(/<a(.*?)href="(.+?)"(.*?)>(.+?)<\/a>(-+)/g, '<a$1href="$2$5"$3>$4$5</a>');
  38. }
  39.  
  40. onChat(data) {
  41. const el = $("#chat-area > *").last();
  42. el.html(this.replaceLinks(el.html()));
  43. }
  44.  
  45. }
  46.  
  47. const plugin = new ChatLinksPlugin();
  48. IdlePixelPlus.registerPlugin(plugin);
  49.  
  50. })();