Gamdom Notify

Rain Notifications

  1. // ==UserScript==
  2. // @name Gamdom Notify
  3. // @description Rain Notifications
  4. // @version 2.4
  5. // @author Pytness
  6. // @match *://gamdom.com/*
  7. // @namespace https://greasyfork.org/scripts/35717-gamdom-notify/
  8. // @update https://greasyfork.org/scripts/35717-gamdom-notify/code/Gamdom%20Notify.user.js
  9. // @resource CoinAudioData https://raw.githubusercontent.com/Pytness/Gamdom-Notify/master/CoinSound.mp3
  10. // @run-at document-start
  11. // @grant GM_info
  12. // @grant GM_notification
  13. // @grant GM_getResourceURL
  14. // @grant unsafeWindow
  15. // @license Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
  16. // ==/UserScript==
  17.  
  18. (function (w) {
  19.  
  20. 'use strict';
  21.  
  22. const log = w.console.log.bind();
  23.  
  24. // NOTE: Creates a ascii box
  25. const box = (a, b = 0) => {
  26. let d, c = '';
  27. a.forEach(e => b = e.length > b ? e.length : b);
  28. d = '+'.padEnd(b, '=') + '+';
  29. a.forEach(e => c += '|' + e.padEnd(b - 1, ' ') + '|\n');
  30. return d + '\n' + c + d;
  31. };
  32.  
  33. ///////////////////////////////////////////////////////////////////////////
  34.  
  35. const initMessage = box([
  36. ' Gamdom Rain Notify:', '',
  37. ' Ver: ' + GM_info.script.version,
  38. ' By ' + GM_info.script.author, '',
  39. ], 40);
  40.  
  41. const NData = { // Notification data
  42. title: "Gamdom Rain Notify:",
  43. text: "its raining :D",
  44. highlight: true,
  45. timeout: 5000
  46. };
  47.  
  48. ///////////////////////////////////////////////////////////////////////////
  49.  
  50. const CoinAudioData = GM_getResourceURL('CoinAudioData')
  51. .replace('application', 'audio/mp3');
  52.  
  53. const CoinSound = new Audio(CoinAudioData); // Load Audio
  54.  
  55. const notificate = () => {
  56. CoinSound.play();
  57. GM_notification(NData);
  58. };
  59.  
  60. ///////////////////////////////////////////////////////////////////////////
  61.  
  62. const extractData = (a, b = false) => {
  63. try {
  64. b = JSON.parse(a.split(',').slice(1).join());
  65. } finally {
  66. return b;
  67. }
  68. };
  69.  
  70. const manageMessages = (a) => {
  71. var b = extractData(a.data);
  72. if(b[0] == 'activateRain') notificate();
  73. };
  74.  
  75. ///////////////////////////////////////////////////////////////////////////
  76.  
  77. /* NOTE: HijackWebsocket is imported (and modified)
  78. * from https://github.com/Pytness/Hijack-Websocket
  79. */
  80.  
  81. const HijackWebsocket = () => {
  82.  
  83. const WS = w.WebSocket;
  84. w.WebSocket = function (...argv) {
  85. let hws = new WS(...argv);
  86. hws.addEventListener('message', manageMessages);
  87. log('Intercepted new WebSocket conection', 'info');
  88. return hws;
  89. };
  90.  
  91. log('WebSocket constructor hijacked', 'ok');
  92.  
  93. w.WebSocket.prototype = WS.prototype;
  94. w.WebSocket.__proto__ = WS.__proto__;
  95.  
  96. w.WebSocket = Function.prototype.call.apply(Function.prototype.bind, [w.WebSocket]);
  97. log('Hijacked WebSocket secured', 'ok');
  98. log('Waiting for WebSocket creation...', 'info');
  99. };
  100.  
  101.  
  102. ///////////////////////////////////////////////////////////////////////////
  103.  
  104. const init = () => {
  105. // NOTE: Log on console Script info
  106. log(initMessage);
  107.  
  108. // NOTE: Hijack the WebSocket constructor
  109. HijackWebsocket();
  110. };
  111.  
  112. init();
  113.  
  114. }(unsafeWindow));