Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replace steam links to run in the Steam Client. (Better Discord Plugin)
//META{"name": "SteamOpenurl", "source": "https://github.com/S4WA/steam-openurl", "follow": "https://twitter.com/AkibaKaede", "author": "drip"}*//
/* BD Functions */
class SteamOpenurl {
start() {
steamLinkUpdate();
}
load() {
steamLinkUpdate();
}
unload() {
steamSchemeReset();
}
stop() {
steamSchemeReset();
}
onSwitch() {
setInterval(() => { steamLinkUpdate(); }, 50);
}
onMessage() {
steamLinkUpdate();
}
getName() {
return "Steam Open URL";
}
getDescription() {
return "Replace steam links with a scheme";
}
getVersion() {
return "1.0.2";
}
getAuthor() {
return "DripNyan";
}
}
/* Functions */
function steamLinkUpdate() {
var links = $("a");
for (var i = 0; i < links.length; i++) {
var url = links[i].href;
if (isSteamLink(url)) links[i].href = scheme + url;
}
}
function steamSchemeReset() {
var links = $("a");
for (var i = 0; i < links.length; i++) {
var url = links[i].href;
if (hasSteamScheme(url)) links[i].href.replace(scheme, "");
}
}
/* Utils */
function isSteamLink(url) {
var result = false;
for (var i in steamLink) {
if (url.startsWith( "https://" + steamLink[i] ) || url.startsWith( "http://" + steamLink[i] )) {
result = true;
}
}
return !hasSteamScheme(url) && result;
}
function hasSteamScheme(url) {
return url.startsWith(scheme);
}
var steamLink = ["steamcommunity.com", "store.steampowered.com", "steampowered.com"], scheme = "steam://openurl/";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.