IdlePixel Custom Interactor

Sends custom messages to an account and logs received customs

当前为 2023-10-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name IdlePixel Custom Interactor
  3. // @namespace lbtechnology.info
  4. // @version 1.6.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: "receiver",
  26. label: "Default account to send custom messages to.",
  27. type: "string",
  28. max: 20,
  29. default: ""
  30. },
  31. {
  32. id: "textareaLines",
  33. label: "Number of lines to display on custom panel.",
  34. type: "integer",
  35. min: 1,
  36. max: 30,
  37. default: 10
  38. },
  39. {
  40. id: "ignorePluginList",
  41. label: "List of plugins to ignore customs from (comma separated.)",
  42. type: "string",
  43. max: 2000,
  44. default: ""
  45. }
  46. ]
  47. });
  48. this.previous = "";
  49. }
  50.  
  51. createPanel(){
  52. const rowNumber = this.getConfig("textareaLines")
  53. IdlePixelPlus.addPanel("interactor", "Custom Message Interactor", function() {
  54. let content = `<div>`
  55. content += `<br/>`
  56. content += `<form onsubmit='event.preventDefault(); IdlePixelPlus.plugins.custominteractor.sendRawCustom()'>`
  57. content += `<label for='interactor_name_in'><p style="-webkit-text-stroke:1px cadetblue;">Recipient:&nbsp&nbsp</p></label>`
  58. content += `<input type="text" id="interactor_name_in"><br/>`
  59. content += `<label for='interactor_command_in'><p style="-webkit-text-stroke:1px cadetblue;">Custom Command:&nbsp&nbsp</p></label>`
  60. content += `<input type="text" size="75" id="interactor_command_in"><br/><br/>`
  61. content += `<input type="submit" value="Send">`
  62. content += `</form>`
  63. content += `<br/>`
  64. content += `<br/>`
  65. content += `<p><p style="-webkit-text-stroke:1px cadetblue;">Most recently received customs:</p></p>`
  66. content += `<textarea id="customs_received" wrap="soft" rows="${rowNumber}" style="width: 95%" readonly></textarea>`
  67. content += `</div>`
  68. return content
  69. });
  70. }
  71.  
  72. onLogin(){
  73. const onlineCount = $(".top-bar .gold:not(#top-bar-admin-link)");
  74. onlineCount.before(`
  75. <a href="#" class="hover float-end link-no-decoration" onclick="event.preventDefault(); IdlePixelPlus.setPanel('interactor')" title="Custom Message Interactor">Custom&nbsp;&nbsp;&nbsp;</a>
  76. `);
  77. this.createPanel()
  78. $("#interactor_name_in").val(this.getConfig("receiver"))
  79. }
  80.  
  81. onCustomMessageReceived(player, content, callbackId) {
  82. const customData = this.parseCustom(player, content, callbackId)
  83.  
  84. const rawIgnoreList = this.getConfig("ignorePluginList").toLowerCase()
  85. const ignoreList = rawIgnoreList.split(',');
  86. if (ignoreList[0] === ""){ignoreList.shift()}
  87.  
  88. if (ignoreList.includes(customData.plugin.toLowerCase())){
  89. return
  90. }
  91.  
  92. const output_string = `${player}: ${customData.plugin}: ${customData.command}: ${customData.payload}`
  93. console.log(output_string)
  94. this.addToPseudoConsole(output_string)
  95. }
  96.  
  97. parseCustom(player, content, callbackId){
  98. const customData = {
  99. player: player,
  100. callbackId: callbackId,
  101. anwinFormatted: false
  102. }
  103. const splitPayload = content.split(":")
  104. if(splitPayload.length >= 3){
  105. customData.anwinFormatted = true
  106. customData.plugin = splitPayload[0]
  107. customData.command = splitPayload[1]
  108. customData.payload = splitPayload.slice(2).join(":")
  109. } else {
  110. customData.anwinFormatted = false
  111. customData.plugin = "unknown"
  112. customData.command = "unknown"
  113. customData.payload = content
  114. }
  115.  
  116. return customData
  117.  
  118. }
  119. addToPseudoConsole(output_string){
  120. const textOutput = $("#customs_received")
  121. const lines = textOutput.val().split('\n')
  122. lines.unshift(output_string)
  123. if(lines.length > this.getConfig("textareaLines")){
  124. lines.pop()
  125. }
  126.  
  127. const newText = lines.join('\n')
  128. textOutput.val(newText)
  129. }
  130. sendRawCustom(){
  131. const recipient = $("#interactor_name_in").val()
  132. const customPrompt = $("#interactor_command_in").val()
  133. $("#interactor_command_in").val("")
  134. const content = `interactor:${customPrompt}`
  135.  
  136. const payload = {
  137. content: content,
  138. onResponse: function(player, content, callbackId) {
  139. return true;
  140. },
  141. onOffline: function(player, content) {
  142. console.log(content)
  143. },
  144. timeout: 2000 // callback expires after 2 seconds
  145. }
  146. IdlePixelPlus.sendCustomMessage(recipient, payload)
  147. }
  148. }
  149. const plugin = new CustomInteractorPlugin();
  150. IdlePixelPlus.registerPlugin(plugin);
  151. })();