IdlePixel Custom Interactor

Sends custom messages to an account and logs received customs

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

  1. // ==UserScript==
  2. // @name IdlePixel Custom Interactor
  3. // @namespace lbtechnology.info
  4. // @version 1.1.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.  
  13. (function() {
  14. 'use strict';
  15.  
  16. class CustomInteractorPlugin extends IdlePixelPlusPlugin {
  17. constructor() {
  18. super("custominteractor", {
  19. about: {
  20. name: GM_info.script.name,
  21. version: GM_info.script.version,
  22. author: GM_info.script.author,
  23. description: GM_info.script.description
  24. },
  25. config: [
  26. {
  27. id: "receiver",
  28. label: "Account to send custom messages to.",
  29. type: "string",
  30. max: 2000,
  31. default: ""
  32. }
  33. ]
  34. });
  35. this.previous = "";
  36. }
  37.  
  38. createPanel(){
  39. IdlePixelPlus.addPanel("interactor", "Custom Message Interactor", function() {
  40. let content = "<div>";
  41. content += "<br/>"
  42. content += `<form onsubmit='event.preventDefault(); IdlePixelPlus.plugins.custominteractor.sendCustom()'>`
  43. content += `<label for='interactor_command_in'><strong>Custom Command:&nbsp&nbsp</strong></label>`
  44. content += `<input type="text" id="interactor_command_in" name="interactor_command_in"><br><br>`
  45. content += `<input type="submit" value="Send">`
  46. content += `</form>`
  47. content += "</div>";
  48. return content;
  49. });
  50. }
  51.  
  52. onLogin(){
  53. const onlineCount = $(".top-bar .gold:not(#top-bar-admin-link)");
  54. onlineCount.before(`
  55. <a href="#" class="hover float-end link-no-decoration" onclick="event.preventDefault(); IdlePixelPlus.setPanel('interactor')" title="Custom Message Interactor">Custom&nbsp;&nbsp;&nbsp;</a>
  56. `);
  57. this.createPanel()
  58. }
  59.  
  60. onCustomMessageReceived(player, content, callbackId) {
  61. console.log(`${player}: ${content}`)
  62. }
  63.  
  64. sendCustom(){
  65. const receiver = this.getConfig("receiver")
  66. const customPrompt = $("#interactor_command_in").val()
  67. $("#interactor_command_in").val("")
  68. const content = `interactor:${customPrompt}`
  69.  
  70. const payload = {
  71. content: content,
  72. onResponse: function(player, content, callbackId) {
  73. return true;
  74. },
  75. onOffline: function(player, content) {
  76. console.log(content)
  77. },
  78. timeout: 2000 // callback expires after 2 seconds
  79. }
  80. IdlePixelPlus.sendCustomMessage(receiver, payload)
  81. }
  82. }
  83.  
  84. const plugin = new CustomInteractorPlugin();
  85. IdlePixelPlus.registerPlugin(plugin);
  86.  
  87. })();