// ==UserScript==
// @name KraXen's Krunker Utils
// @namespace Violentmonkey Scripts
// @include https://krunker.io/*
// @grant none
// @version 3.0
// @author KraXen72
// @grant GM_registerMenuCommand
// @grant GM_xmlhttpRequest
// @description various utilities to get data for krunker client development
// @license MIT
// ==/UserScript==
const log = console.log.bind(console)
// i found no good way to keep this updated programatically
const regionMappings = {
"de-fra": {c:"FRA", off: 2},
"us-ca-sv": {c:"SV", off: -7},
"au-syd": {c:"SYD", off: 10},
"jb-hnd": {c:"TOK", off: 9},
"us-fl": {c:"MIA", off: -4},
"sgp": {c:"SIN", off: 8},
"us-nj": {c:"NY", off: -4},
"as-mb": {c:"MBI", off: 5.5},
"us-tx": {c:"DAL", off: -5},
"brz": {c:"BRZ", off: -3}, // approx, BRT
"me-bhn": {c:"BHN", off: 3}, // approx, Saudi arabia
"af-ct": {c:"AFR", off: 2} // approx SAST
}
function getGamemodes() {
showWindow(42)
openHostWindow(false, 0)
windows[7].switchTab(1)
const wrap = document.querySelector('.hostTb1 > div[style*="margin"]:has(.hostOpt)')
const gamemodes = [...wrap.children].map((item, i) => {
const name = item.querySelector('.optName').textContent
return name
})
log(gamemodes)
}
function getRegions() {
GM_xmlhttpRequest({
url: "https://matchmaker.krunker.io/game-list?hostname=krunker.io",
responseType: 'json',
onload: (data) => {
const regionsWithDuplicates = data.response.games
.map(game => game[0].split(":")[0])
const regions = [...new Set(regionsWithDuplicates)]
log(regions)
}
})
}
function getRegionsSetting() {
showWindow(1)
const options = [...document.querySelectorAll('.settName[title$="specific region"] > select.inputGrey2[onchange*="defaultRegion"] option')]
const regions = options.map(opt => ({ name: opt.textContent, id: opt.value, code: regionMappings[opt.value].c, offset: regionMappings[opt.value]?.off ?? 0 }))
// found in matchmaker, but not region picker
regions.push({ "name": "London (hidden)", "id": '', "code": "LON", "offset": 1 })
regions.push({ "name": "China (hidden)", "id": '', "code": "CHI", "offset": 8 }) // approx, Beijing
regions.push({ "name": "Seattle (hidden)", "id": '', "code": "STL", "offset": -7 })
regions.push({ "name": "Mexico (hidden)", "id": '', "code": "MX", "offset": -6 })
log(regions)
log(regions.map(reg => reg.code))
}
GM_registerMenuCommand("log gamemodes to console", getGamemodes)
GM_registerMenuCommand("fetch all regions (3-letter shortcuts)", getRegions)
GM_registerMenuCommand("fetch all regions (full objects)", getRegionsSetting)