Greasy Fork is available in English.

Diep.io Party link Copier

[ Press Ctrl + C to copy link ] Gets and logs the party link to the console, this script is mostly a heavily modified and stripped down version of DiepTool

اعتبارا من 15-07-2020. شاهد أحدث إصدار.

// ==UserScript==
// @name         Diep.io Party link Copier
// @version      1.0.1
// @description  [ Press Ctrl + C to copy link ] Gets and logs the party link to the console, this script is mostly a heavily modified and stripped down version of DiepTool
// @author       Cazka and CX's code, modified by Excigma to carry out a different function
// @match        https://diep.io/*
// @namespace    https://diep.io/*
// @grant        none
// ==/UserScript==

// Note: This may not work with other scripts that hijack the websocket

// Most of this script is from other sources, which are marked
// My own code is minimal, as I said MOST of the script is from other people's work
// This is mostly just reusing other people's code and changing/simplifying it for another propose

(function () {
	'use strict';

	// Most of this script's code is from (an older version of) DiepTool, written by Cazka
	// unless marked otherwise

	// It can be found here: https://greasyfork.org/en/scripts/401910-diep-io-tool

	const wsInstances = new Set()

	// Lines of code written by Excigma
	let partyLink;
	// End lines of code written by Excigma


	// Cazka's code from DiepTool
	window.WebSocket.prototype._send = window.WebSocket.prototype.send
	window.WebSocket.prototype.send = function (data) {
		this._send(data)

		// Still Cazka's code from DiepTool
		if (this.url.match(/s.m28n.net/)) {
			if (!wsInstances.has(this)) {
				wsInstances.add(this)

				// Still Cazka's code from DiepTool
				this._onmessage = this.onmessage
				this.onmessage = function (event) {
					this._onmessage(event)

					// Still Cazka's code from DiepTool
					const data = new Uint8Array(event.data)
					if (data[0] == 6) {
						let party = ''
						for (let i = 1; i < data.byteLength; i++) {
							let byte = data[i].toString(16).split('')
							if (byte.length === 1) {
								party += (byte[0] + '0')
							} else {
								party += (byte[1] + byte[0])
							}
						}


						// Lines of code written by Excigma
						partyLink = getLink(this.url, party)
						console.log(`Party: ${party}`)
						console.log(`Server ID: ${this.url}`)
						console.log(`Server link: ${getLink(this.url)}`)
						console.log(`Party link: ${partyLink}`)
						// End lines of code written by Excigma
					}
					// ...Other irrelevant code has been removed/shortened
				}
			}
		}
	}
	// End of code from DiepTool

	// This is found from DiepSocket, also written by Cazka
	// https://github.com/Cazka/diepsocket/blob/master/DiepSocket.js#L294

	// This code resembles code by CX though may not be
	// The code carries out the same functions so may be the same, though different people have written it
	// Similar code: https://github.com/cx88/diepssect/blob/master/diep-bot/main.js#L341

	function getLink(wsURL, party = '') {
		const match = wsURL.match(/(?<=wss:\/\/).[0-9a-z]{3}(?=.s.m28n.net\/)|^[0-9a-z]{4}$/)
		if (!match) throw new Error('Invalid wsURL: wrong format:', wsURL)
		let serverid = match[0]
		const link = 'https://diep.io/#'
		serverid = serverid
			.split('')
			.map(char =>
				char
					.charCodeAt(0)
					.toString(16)
					.split('')
					.reverse()
					.join('')
			)
			.join('')
		return link + (serverid + '00' + party).toUpperCase()
	}


	// I'm honestly tired, I know I can do this myself but why when I have stackoverflow..
	// https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript



	function copy(text) {
		let textArea = document.createElement("textarea");
		textArea.value = text;

		// Avoid scrolling to bottom
		textArea.style.top = "0";
		textArea.style.left = "0";
		textArea.style.position = "fixed";

		document.body.appendChild(textArea);
		textArea.focus();
		textArea.select();

		try {
			var successful = document.execCommand('copy');
			var msg = successful ? 'successful' : 'unsuccessful';
			console.log('Copying text command was ' + msg);
		} catch(er) {
			//
		}

		document.body.removeChild(textArea);
	}


	// The rest of the code from here is written by Excigma
	document.addEventListener("keydown", (event) => {
		if (event.key.toLowerCase() == "c" && event.ctrlKey) {
			copy(partyLink)
			console.log(`Party link: ${partyLink}`)
		}
	})
})();