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.2.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. id: "textareaLines",
  35. label: "Number of lines to display on custom panel.",
  36. type: "integer",
  37. min: 1,
  38. max: 30,
  39. default: 10
  40. }
  41. ]
  42. });
  43. this.previous = "";
  44. }
  45.  
  46. createPanel(){
  47. IdlePixelPlus.addPanel("interactor", "Custom Message Interactor", function() {
  48. let content = `<div>`
  49. content += `<br/>`
  50. content += `<form onsubmit='event.preventDefault(); IdlePixelPlus.plugins.custominteractor.sendCustom()'>`
  51. content += `<label for='interactor_command_in'><strong>Custom Command:&nbsp&nbsp</strong></label>`
  52. content += `<input type="text" id="interactor_command_in"><br/><br/>`
  53. content += `<input type="submit" value="Send">`
  54. content += `</form>`
  55. content += `<br/>`
  56. content += `<br/>`
  57. content += `<p><strong>Most recently received customs:</strong></p>`
  58. content += `<textarea id="customs_received" wrap="off" rows="10" cols="175" readonly></textarea>`
  59. content += `</div>`
  60. return content
  61. });
  62. }
  63.  
  64. onLogin(){
  65. const onlineCount = $(".top-bar .gold:not(#top-bar-admin-link)");
  66. onlineCount.before(`
  67. <a href="#" class="hover float-end link-no-decoration" onclick="event.preventDefault(); IdlePixelPlus.setPanel('interactor')" title="Custom Message Interactor">Custom&nbsp;&nbsp;&nbsp;</a>
  68. `);
  69. this.createPanel()
  70. }
  71.  
  72. onCustomMessageReceived(player, content, callbackId) {
  73. const output_string = `${player}: ${content}`
  74. console.log(output_string)
  75. const textOutput = $("#customs_received")
  76. const lines = textOutput.val().split('\n')
  77. lines.unshift(output_string)
  78. if(lines.length > this.getConfig("textareaLines")){
  79. lines.pop()
  80. }
  81.  
  82. const newText = lines.join('\n')
  83. textOutput.val(newText)
  84. }
  85.  
  86. sendCustom(){
  87. const receiver = this.getConfig("receiver")
  88. const customPrompt = $("#interactor_command_in").val()
  89. $("#interactor_command_in").val("")
  90. const content = `interactor:${customPrompt}`
  91.  
  92. const payload = {
  93. content: content,
  94. onResponse: function(player, content, callbackId) {
  95. return true;
  96. },
  97. onOffline: function(player, content) {
  98. console.log(content)
  99. },
  100. timeout: 2000 // callback expires after 2 seconds
  101. }
  102. IdlePixelPlus.sendCustomMessage(receiver, payload)
  103. }
  104. }
  105.  
  106. const plugin = new CustomInteractorPlugin();
  107. IdlePixelPlus.registerPlugin(plugin);
  108.  
  109. })();