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.7.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' class="interactor-label">Recipient:&nbsp&nbsp</label>`
  58. content += `<input type="text" id="interactor_name_in"><br/>`
  59. content += `<label for='interactor_command_in' class="interactor-label">Custom Command:&nbsp&nbsp</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 class="interactor-label">Most recently received customs:</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. if ("ui-tweaks" in IdlePixelPlus.plugins){
  81. this.applyTheme("UIT")
  82. } else {
  83. this.applyTheme("default")
  84. }
  85. }
  86.  
  87. onCustomMessageReceived(player, content, callbackId) {
  88. const customData = this.parseCustom(player, content, callbackId)
  89.  
  90. const rawIgnoreList = this.getConfig("ignorePluginList").toLowerCase()
  91. const ignoreList = rawIgnoreList.split(',');
  92. if (ignoreList[0] === ""){ignoreList.shift()}
  93.  
  94. if (ignoreList.includes(customData.plugin.toLowerCase())){
  95. return
  96. }
  97.  
  98. const output_string = `${player}: ${customData.plugin}: ${customData.command}: ${customData.payload}`
  99. console.log(output_string)
  100. this.addToPseudoConsole(output_string)
  101. }
  102.  
  103. parseCustom(player, content, callbackId){
  104. const customData = {
  105. player: player,
  106. callbackId: callbackId,
  107. anwinFormatted: false
  108. }
  109. const splitPayload = content.split(":")
  110. if(splitPayload.length >= 3){
  111. customData.anwinFormatted = true
  112. customData.plugin = splitPayload[0]
  113. customData.command = splitPayload[1]
  114. customData.payload = splitPayload.slice(2).join(":")
  115. } else {
  116. customData.anwinFormatted = false
  117. customData.plugin = "unknown"
  118. customData.command = "unknown"
  119. customData.payload = content
  120. }
  121.  
  122. return customData
  123.  
  124. }
  125. addToPseudoConsole(output_string){
  126. const textOutput = $("#customs_received")
  127. const lines = textOutput.val().split('\n')
  128. lines.unshift(output_string)
  129. if(lines.length > this.getConfig("textareaLines")){
  130. lines.pop()
  131. }
  132.  
  133. const newText = lines.join('\n')
  134. textOutput.val(newText)
  135. }
  136. applyTheme(theme){
  137. let backgroundColour = "#ffffff"
  138. let textColour = "#000000"
  139. let labelColour = "#000000"
  140. if (theme==="UIT"){
  141. backgroundColour = IdlePixelPlus.plugins["ui-tweaks"].config["color-chat-area"]
  142. textColour = IdlePixelPlus.plugins["ui-tweaks"].config["font-color-chat-area"]
  143. labelColour = IdlePixelPlus.plugins["ui-tweaks"].config["font-color-panels"]
  144. }
  145.  
  146. $(".interactor-label").css({"color": labelColour})
  147. $("#customs_received").css({"color": textColour, "background-color": backgroundColour})
  148. }
  149.  
  150. sendRawCustom(){
  151. const recipient = $("#interactor_name_in").val()
  152. const customPrompt = $("#interactor_command_in").val()
  153. $("#interactor_command_in").val("")
  154. const content = `interactor:${customPrompt}`
  155.  
  156. const payload = {
  157. content: content,
  158. onResponse: function(player, content, callbackId) {
  159. return true;
  160. },
  161. onOffline: function(player, content) {
  162. console.log(content)
  163. },
  164. timeout: 2000 // callback expires after 2 seconds
  165. }
  166. IdlePixelPlus.sendCustomMessage(recipient, payload)
  167. }
  168. }
  169. const plugin = new CustomInteractorPlugin();
  170. IdlePixelPlus.registerPlugin(plugin);
  171. })();