Gamdom Notify

Rain Notifications

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name           Gamdom Notify
// @description    Rain Notifications
// @version        2.4
// @author         Pytness
// @match          *://gamdom.com/*
// @namespace      https://greasyfork.org/scripts/35717-gamdom-notify/
// @update         https://greasyfork.org/scripts/35717-gamdom-notify/code/Gamdom%20Notify.user.js
// @resource       CoinAudioData https://raw.githubusercontent.com/Pytness/Gamdom-Notify/master/CoinSound.mp3
// @run-at         document-start
// @grant          GM_info
// @grant          GM_notification
// @grant          GM_getResourceURL
// @grant          unsafeWindow
// @license        Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
// ==/UserScript==

(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));