IdlePixel Custom Interactor

Sends custom messages to an account and logs received customs

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

  1. // ==UserScript==
  2. // @name IdlePixel Custom Interactor
  3. // @namespace lbtechnology.info
  4. // @version 1.0.0
  5. // @description Sends custom messages to an account and logs received customs
  6. // @author Lux-Ferre
  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. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14. class CustomInteractorPlugin extends IdlePixelPlusPlugin {
  15. constructor() {
  16. super("custominteractor", {
  17. about: {
  18. name: GM_info.script.name,
  19. version: GM_info.script.version,
  20. author: GM_info.script.author,
  21. description: GM_info.script.description
  22. },
  23. config: [
  24. {
  25. id: "reciever",
  26. label: "Account to send custom messages to.",
  27. type: "string",
  28. max: 2000,
  29. default: ""
  30. }
  31. ]
  32. });
  33. this.previous = "";
  34. }
  35.  
  36. onLogin(){
  37. const onlineCount = $(".top-bar .gold:not(#top-bar-admin-link)");
  38. onlineCount.before(`
  39. <a href="#" class="hover float-end link-no-decoration" onclick="event.preventDefault(); IdlePixelPlus.plugins.custominteractor.sendCustom()" title="Custom message">Custom&nbsp;&nbsp;&nbsp;</a>
  40. `);
  41. }
  42.  
  43. onCustomMessageReceived(player, content, callbackId) {
  44. console.log(`${player}: ${content}`)
  45. }
  46.  
  47. sendCustom(){
  48. const reciever = this.getConfig("reciever")
  49. let customPrompt = window.prompt()
  50. const content = `interactor:${customPrompt}`
  51.  
  52. const payload = {
  53. content: content,
  54. onResponse: function(player, content, callbackId) {
  55. return true;
  56. },
  57. onOffline: function(player, content) {
  58. console.log(content)
  59. },
  60. timeout: 2000 // callback expires after 2 seconds
  61. }
  62. IdlePixelPlus.sendCustomMessage(reciever, payload)
  63. }
  64. }
  65. const plugin = new CustomInteractorPlugin();
  66. IdlePixelPlus.registerPlugin(plugin);
  67. })();