0% found this document useful (0 votes)
55 views2 pages

Script

The document contains code to hijack websockets and listen for messages to trigger a notification. It defines functions to create an ASCII box, extract data from messages, play a sound, and display notifications. The code hijacks the WebSocket constructor to intercept new connections, listen for "activateRain" messages, play a sound, and display a notification with sample text and settings.

Uploaded by

simo mühler
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
55 views2 pages

Script

The document contains code to hijack websockets and listen for messages to trigger a notification. It defines functions to create an ASCII box, extract data from messages, play a sound, and display notifications. The code hijacks the WebSocket constructor to intercept new connections, listen for "activateRain" messages, play a sound, and display a notification with sample text and settings.

Uploaded by

simo mühler
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 2

(function (w) {

'use strict';

const log = w.console.log.bind();

// NOTE: Creates a ascii box


const box = (a, b = 0) => {
let d, c = '';
a.forEach(e => b = e.length > b ? e.length : b);
d = '+'.padEnd(b, '=') + '+';
a.forEach(e => c += '|' + e.padEnd(b - 1, ' ') + '|\n');
return d + '\n' + c + d;
};

///////////////////////////////////////////////////////////////////////////

const initMessage = box([


' Gamdom Rain Notify:', '',
' Ver: ' + GM_info.script.version,
' By ' + GM_info.script.author, '',
], 40);

const NData = { // Notification data


title: "Gamdom Rain Notify:",
text: "its raining :D",
highlight: true,
timeout: 5000
};

///////////////////////////////////////////////////////////////////////////

const CoinAudioData = GM_getResourceURL('CoinAudioData')


.replace('application', 'audio/mp3');

const CoinSound = new Audio(CoinAudioData); // Load Audio

const notificate = () => {


CoinSound.play();
GM_notification(NData);
};

///////////////////////////////////////////////////////////////////////////

const extractData = (a, b = false) => {


try {
b = JSON.parse(a.split(',').slice(1).join());
} finally {
return b;
}
};

const manageMessages = (a) => {


var b = extractData(a.data);
if(b[0] == 'activateRain') notificate();
};

///////////////////////////////////////////////////////////////////////////
/* NOTE: HijackWebsocket is imported (and modified)
* from https://github.com/Pytness/Hijack-Websocket
*/

const HijackWebsocket = () => {

const WS = w.WebSocket;
w.WebSocket = function (...argv) {
let hws = new WS(...argv);
hws.addEventListener('message', manageMessages);
log('Intercepted new WebSocket conection', 'info');
return hws;
};

log('WebSocket constructor hijacked', 'ok');

w.WebSocket.prototype = WS.prototype;
w.WebSocket.__proto__ = WS.__proto__;

w.WebSocket = Function.prototype.call.apply(Function.prototype.bind,
[w.WebSocket]);

log('Hijacked WebSocket secured', 'ok');


log('Waiting for WebSocket creation...', 'info');
};

///////////////////////////////////////////////////////////////////////////

const init = () => {


// NOTE: Log on console Script info
log(initMessage);

// NOTE: Hijack the WebSocket constructor


HijackWebsocket();
};

init();

}(unsafeWindow));

You might also like