IdlePixel Custom Interactor

Sends custom messages to an account and logs received customs

当前为 2023-05-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name IdlePixel Custom Interactor
  3. // @namespace lbtechnology.info
  4. // @version 1.3.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: "Default account to send custom messages to.",
  29. type: "string",
  30. max: 20,
  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_name_in'><p style="-webkit-text-stroke:1px cadetblue;">Recipient:&nbsp&nbsp</p></label>`
  52. content += `<input type="text" id="interactor_name_in"><br/>`
  53. content += `<label for='interactor_command_in'><p style="-webkit-text-stroke:1px cadetblue;">Custom Command:&nbsp&nbsp</p></label>`
  54. content += `<input type="text" id="interactor_command_in"><br/><br/>`
  55. content += `<input type="submit" value="Send">`
  56. content += `</form>`
  57. content += `<br/>`
  58. content += `<br/>`
  59. content += `<p><p style="-webkit-text-stroke:1px cadetblue;">Most recently received customs:</p></p>`
  60. content += `<textarea id="customs_received" wrap="off" rows="10" cols="75" readonly></textarea>`
  61. content += `</div>`
  62. return content
  63. });
  64. }
  65.  
  66. onLogin(){
  67. const onlineCount = $(".top-bar .gold:not(#top-bar-admin-link)");
  68. onlineCount.before(`
  69. <a href="#" class="hover float-end link-no-decoration" onclick="event.preventDefault(); IdlePixelPlus.setPanel('interactor')" title="Custom Message Interactor">Custom&nbsp;&nbsp;&nbsp;</a>
  70. `);
  71. this.createPanel()
  72. $("#interactor_name_in").val(this.getConfig("receiver"))
  73. }
  74.  
  75. onCustomMessageReceived(player, content, callbackId) {
  76. const output_string = `${player}: ${content}`
  77. console.log(output_string)
  78. const textOutput = $("#customs_received")
  79. const lines = textOutput.val().split('\n')
  80. lines.unshift(output_string)
  81. if(lines.length > this.getConfig("textareaLines")){
  82. lines.pop()
  83. }
  84.  
  85. const newText = lines.join('\n')
  86. textOutput.val(newText)
  87. }
  88.  
  89. sendCustom(){
  90. const recipient = $("#interactor_name_in").val()
  91. const customPrompt = $("#interactor_command_in").val()
  92. $("#interactor_command_in").val("")
  93. const content = `interactor:${customPrompt}`
  94.  
  95. const payload = {
  96. content: content,
  97. onResponse: function(player, content, callbackId) {
  98. return true;
  99. },
  100. onOffline: function(player, content) {
  101. console.log(content)
  102. },
  103. timeout: 2000 // callback expires after 2 seconds
  104. }
  105. IdlePixelPlus.sendCustomMessage(recipient, payload)
  106. }
  107. }
  108.  
  109. const plugin = new CustomInteractorPlugin();
  110. IdlePixelPlus.registerPlugin(plugin);
  111.  
  112. })();