Shadam's unlag FIXED

THIS IS NOT MY SCRIPT THIS IS JUST A FIXED VERSION OF SHADAM'S (SHADMAN CONTACT ME IF YOU WANT THIS TAKEN DOWN) ORIGINAL: https://greasyfork.org/en/scripts/420008-unlag

目前為 2022-09-05 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/450802/1090093/Shadam%27s%20unlag%20FIXED.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Shadam's unlag FIXED
// @version      0.0
// @description  THIS IS NOT MY SCRIPT THIS IS JUST A FIXED VERSION OF SHADAM'S (SHADMAN CONTACT ME IF YOU WANT THIS TAKEN DOWN) ORIGINAL: https://greasyfork.org/en/scripts/420008-unlag
// @author       Shädam
// @match        https://diep.io/*
// @grant        none
// @namespace    https://greasyfork.org/users/719520
// @run-at		document-start
// ==/UserScript==
var int = unsafeWindow.setInterval(function() {
	if(unsafeWindow.input != null) {
		unsafeWindow.clearInterval(int);
		onready();
	}
}, 100);

function onready() {
	let ping = false;
	let t;
	let samples = new Array(500);
	let m;
	let h = 0;
	function getMax() {
		let max = 0;
		for(let i = 0; i < 500; ++i) {
			if(samples[i] != null) {
				if(samples[i] > max) {
					max = samples[i];
				}
			} else {
				break;
			}
		}
		m = max;
	}
	function sleep(time) {
		return new Promise(function(resolve) {
			setTimeout(resolve, time);
		});
	}
	unsafeWindow.WebSocket = class extends WebSocket {
		constructor(ip) {
			super(ip);
			if(ip.match(/\.hiss\.io/) != null) {
				samples = new Array(500);
				h = 0;
				ping = false;
				this.send = new Proxy(this.send, {
					apply: function(to, what, args) {
					if(args[0].length == 1) {
						ping = true;
						t = new Date().getTime();
					}
					return to.apply(what, args);
				}
			});
			let a = unsafeWindow.setInterval(function() {
				if(this.onmessage != null) {
					unsafeWindow.clearInterval(a);
					this.onmessage = new Proxy(this.onmessage, {
						apply: function(to, what, args) {
							if(new Uint8Array(args[0].data).length == 1 && ping == true) {
								ping = false;
								samples[h] = new Date().getTime() - t;
								h = (h + 1) % 501;
								getMax();
							}
							return to.apply(what, args);
						}
					});
				}
			}.bind(this), 120);
			}
		}
	}
	unsafeWindow.powSolver = new Proxy(unsafeWindow.powSolver, {
		apply: function(to, what, args) {
			const time = new Date().getTime();
			const f = args[2];
			return to.apply(what, [args[0], args[1], async function(...g) {
				if(args[1] == 17 && 10000 - m * 3 - new Date().getTime() + time > 0) {
					await sleep(10000 - m * 3 - new Date().getTime() + time);
				}
			return f(...g);
			}]);
		}
	});
}