Created
April 11, 2022 07:40
-
-
Save arctic-hen7/f0110791162c765032ad66c3c95c621c to your computer and use it in GitHub Desktop.
A simple JS script to extract server loads from ProtonVPN's website. This is designed to be run a DevTools console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// RUN THIS AT <https://protonvpn.com/vpn-servers/> | |
SELECTOR = "#collapseNLfree > div:nth-child(1) > ul:nth-child(1) > .list-group-item"; // Change this to change the servers listed, this defaults to the Netherlands free servers | |
// As Proton change their website design, this will likely need to be changed | |
freeServers = document.querySelectorAll(SELECTOR); | |
loads = Array.from(freeServers).map(elem => { | |
const [name, load] = elem.innerText.split("Load "); | |
return name.trim() + ": " + load.trim(); | |
}); | |
// This just sorts the servers numerically | |
ordered = loads.sort((a, b) => { | |
// We extract the server number from between the `#` and the `:` (as in `NL-FREE#33: 71%`) | |
const numA = a.substring(a.indexOf("#") + 1, a.indexOf(":")); | |
const numB = b.substring(b.indexOf("#") + 1, b.indexOf(":")); | |
return numA - numB; | |
}); | |
list = ordered.join("\n"); | |
// Get the fastest server by load | |
// We set an initial value of 200% to make sure we get something | |
// If all servers have the same load, this will just return the first server in the list | |
fastest = loads.reduce(([lowestLoadServer, lowestLoadVal], curr) => { | |
const currLoadVal = parseInt(curr.substring(curr.indexOf(": ") + 2, curr.length - 1)); | |
const currLoadServer = curr.substring(0, curr.indexOf(":")); | |
return currLoadVal < lowestLoadVal ? [currLoadServer, currLoadVal] : [lowestLoadServer, lowestLoadVal]; | |
}, [null, 200]); | |
fastestMsg = `Fastest server is '${fastest[0]}' with a load of ${fastest[1]}%.`; | |
// --- OUTPUTS --- | |
// `fastest`: array with two elements (fastest server name, fastest server load as a percentage) | |
// `fastestMsg`: information about the fastest server, formatted for human reading | |
// `list`: a human-readable list of all servers and their loads |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment