florr.io | Server Switcher

Read title

当前为 2024-09-16 提交的版本,查看 最新版本

// ==UserScript==
// @name         florr.io | Server Switcher
// @namespace    https://github.com/Samer-Kizi
// @version      2.0
// @description  Read title
// @author       Furaken
// @license      MIT
// @match        https://florr.io/*
// @grant        unsafeWindow
// ==/UserScript==

var totalServers = 7,
    position = "-100px"

let url;
const nativeWebSocket = unsafeWindow.WebSocket;
unsafeWindow.WebSocket = function(...args) {
    const socket = new nativeWebSocket(...args);
    url = socket.url
    return socket;
};

let cp6 = unsafeWindow.cp6

function updateServers() {
    for (let i = 0; i <= 5; i++) {
        fetch(`https://api.n.m28.io/endpoint/florrio-map-${i}-green/findEach/`).then((response) => response.json()).then((data) => {
            if (servers[matrixs[i]] == null) {
                servers[matrixs[i]] = {
                    NA: {},
                    EU: {},
                    AS: {}
                }
            }
            servers[matrixs[i]].NA[data.servers["vultr-miami"].id] = Math.floor(Date.now() / 1000)
            servers[matrixs[i]].EU[data.servers["vultr-frankfurt"].id] = Math.floor(Date.now() / 1000)
            servers[matrixs[i]].AS[data.servers["vultr-tokyo"].id] = Math.floor(Date.now() / 1000)
        });
    }
    for (const [keyMatrix, valueMatrix] of Object.entries(servers)) {
        for (const [keyServer, valueServer] of Object.entries(valueMatrix)) {
            for (const [keyId, valueId] of Object.entries(valueServer)) {
                if (Math.floor(Date.now() / 1000) - valueId > 5 * 60) delete servers[keyMatrix][keyServer][keyId]
            }
        }
    }
}
var servers = {},
    matrixs = ["Garden", "Desert", "Ocean", "Jungle", "Ant Hell", "Hel", "Sewers"]
updateServers()
setInterval(() => {
    updateServers()
}, 5 * 1000)

var container = document.createElement('div')
container.style = `
    width: 700px;
    height: auto;
    z-index: 1;
    background: rgba(0, 0, 0, 0.5);
    position: relative;
    border-radius: 50px;
    margin: 0 auto;
    color: white;
    text-align: center;
    font-family: 'Ubuntu';
    padding: 12px;
    text-shadow: rgb(0 0 0) 2px 0px 0px, rgb(0 0 0) 1.75517px 0.958851px 0px, rgb(0 0 0) 1.0806px 1.68294px 0px, rgb(0 0 0) 0.141474px 1.99499px 0px, rgb(0 0 0) -0.832294px 1.81859px 0px, rgb(0 0 0) -1.60229px 1.19694px 0px, rgb(0 0 0) -1.97998px 0.28224px 0px, rgb(0 0 0) -1.87291px -0.701566px 0px, rgb(0 0 0) -1.30729px -1.5136px 0px, rgb(0 0 0) -0.421592px -1.95506px 0px, rgb(0 0 0) 0.567324px -1.91785px 0px, rgb(0 0 0) 1.41734px -1.41108px 0px, rgb(0 0 0) 1.92034px -0.558831px 0px;
    top: ${position};
    cursor: default;
    transition: all 1s ease-in-out;
`
container.innerHTML = "Fetching..."
document.querySelector('body').appendChild(container)

var autoToggle = true

document.documentElement.addEventListener("keydown", function (e) {
    if (event.keyCode == "9") {
        if (autoToggle) {
            autoToggle = false
            container.style.top = "0px"
        } else {
            autoToggle = true
            container.style.top = position
        }
    }
});

String.prototype.replaceLast = function (what, replacement) {
    var pcs = this.split(what);
    var lastPc = pcs.pop();
    return pcs.join(what) + replacement + lastPc;
};

function getServerId() {
    var thisCp6Id = url.match(/wss:\/\/([a-z0-9]*).s.m28n.net\//)[1]
    for (const [biome, serversObj] of Object.entries(servers)) {
        for (const [server, obj] of Object.entries(serversObj)) {
            if (Object.keys(obj).includes(thisCp6Id)) container.innerHTML = `${server} - ${biome}<br>${Object.keys(obj).map(x => `<w style="cursor: pointer; color: #fff" onclick="cp6.forceServerID('${x}')">${x}</w>`).join(" - ").replaceLast(thisCp6Id, `<w style="color:#29ffa3">${thisCp6Id}</w>`)}`
        }
    }
}

var wssArr = []
setInterval(() => {
    wssArr.unshift(url)
    if (wssArr.length > 2) wssArr.splice(2)
    if (wssArr[wssArr.length - 1] != wssArr[0]) {
        getServerId()
        if (autoToggle) {
            container.style.top = "0px"
            var autoHide = setTimeout(function() {
                container.style.top = position
                document.getElementById('allServersContainer').style.display = "none"
                clearTimeout(autoHide)
            }, 3000);
        }
    }
}, 1000)

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址