IdlePixel+ Custom Handling

Library for parsing custom messages.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/484046/1307197/IdlePixel%2B%20Custom%20Handling.js

  1. // ==UserScript==
  2. // @name IdlePixel+ Custom Handling
  3. // @namespace lbtechnology.info
  4. // @version 1.0.0
  5. // @description Library for parsing custom messages.
  6. // @author Lux-Ferre
  7. // @license MIT
  8. // @match *://idle-pixel.com/login/play*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. if(window.Customs) {
  14. // already loaded
  15. return;
  16. }
  17.  
  18. class Customs {
  19. sendBasicCustom(recipient, pluginValue, command, data){
  20. const content = `${pluginValue}:${command}:${data}`
  21.  
  22. const payload = {
  23. content: content,
  24. onResponse: function(player, content, callbackId) {
  25. return true;
  26. },
  27. onOffline: function(player, content) {
  28. console.log(content)
  29. },
  30. timeout: 2000 // callback expires after 2 seconds
  31. }
  32.  
  33. IdlePixelPlus.sendCustomMessage(recipient, payload)
  34. }
  35. parseCustom(player, content, callbackId){
  36. const customData = {
  37. player: player,
  38. callbackId: callbackId,
  39. anwinFormatted: false
  40. }
  41. const splitPayload = content.split(":")
  42. if(splitPayload.length >= 3){
  43. customData.anwinFormatted = true
  44. customData.plugin = splitPayload[0]
  45. customData.command = splitPayload[1]
  46. customData.payload = splitPayload.slice(2).join(":")
  47. } else {
  48. customData.anwinFormatted = false
  49. customData.plugin = "unknown"
  50. customData.command = "unknown"
  51. customData.payload = content
  52. }
  53.  
  54. return customData
  55. }
  56. }
  57.  
  58. // Add to window and init
  59. window.Customs = new Customs();
  60.  
  61. })();