BetterDiscordAddons/Plugins/SteamProfileLink/SteamProfileLink.plugin.js

112 lines
4.2 KiB
JavaScript
Raw Normal View History

2020-02-27 08:44:03 +01:00
//META{"name":"SteamProfileLink","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/SteamProfileLink","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/SteamProfileLink/SteamProfileLink.plugin.js"}*//
2018-10-11 10:21:26 +02:00
2020-04-20 09:23:17 +02:00
var SteamProfileLink = (_ => {
2020-06-09 09:07:04 +02:00
var settings = {};
2020-04-20 09:23:17 +02:00
return class SteamProfileLink {
getName () {return "SteamProfileLink";}
2018-10-11 10:21:26 +02:00
2020-04-20 09:23:17 +02:00
getVersion () {return "1.0.9";}
2018-10-11 10:21:26 +02:00
2020-04-20 09:23:17 +02:00
getAuthor () {return "DevilBro";}
2018-10-11 10:21:26 +02:00
2020-04-20 09:23:17 +02:00
getDescription () {return "Opens any Steam links in Steam instead of your internet browser.";}
2019-01-17 23:48:29 +01:00
2020-04-20 09:23:17 +02:00
constructor () {
this.changelog = {
2020-04-20 09:23:37 +02:00
"improved":[["Support links","Also works for support links now"]]
2020-04-20 09:23:17 +02:00
};
}
2019-04-11 13:15:22 +02:00
2020-04-20 09:23:17 +02:00
initConstructor () {
this.defaults = {
settings: {
useChromium: {value:false, description:"Use inbuilt browser instead of default if fails to open Steam"}
}
};
}
2019-11-29 19:11:56 +01:00
2020-04-20 09:23:17 +02:00
getSettingsPanel () {
if (!window.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
let settings = BDFDB.DataUtils.get(this, "settings");
let settingsPanel, settingsItems = [];
settingsItems = settingsItems.concat(this.createSelects(false));
for (let key in settings) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
className: BDFDB.disCN.marginbottom8,
type: "Switch",
plugin: this,
keys: ["settings", key],
label: this.defaults.settings[key].description,
value: settings[key]
}));
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
}
2019-11-29 19:11:56 +01:00
2020-04-20 09:23:17 +02:00
// Legacy
load () {}
2018-10-11 10:21:26 +02:00
2020-04-20 09:23:17 +02:00
start () {
if (!window.BDFDB) window.BDFDB = {myPlugins:{}};
if (window.BDFDB && window.BDFDB.myPlugins && typeof window.BDFDB.myPlugins == "object") window.BDFDB.myPlugins[this.getName()] = this;
let libraryScript = document.querySelector("head script#BDFDBLibraryScript");
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("id", "BDFDBLibraryScript");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
libraryScript.setAttribute("date", performance.now());
libraryScript.addEventListener("load", _ => {this.initialize();});
document.head.appendChild(libraryScript);
}
else if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
this.startTimeout = setTimeout(_ => {
try {return this.initialize();}
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
}, 30000);
2019-05-26 13:55:26 +02:00
}
2018-10-11 10:21:26 +02:00
2020-04-20 09:23:17 +02:00
initialize () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
if (this.started) return;
BDFDB.PluginUtils.init(this);
2019-01-26 22:45:19 +01:00
2020-04-20 09:23:17 +02:00
BDFDB.ListenerUtils.add(this, document, "click", "a[href^='https://steamcommunity.'], a[href^='https://help.steampowered.'], a[href^='https://store.steampowered.'], a[href*='a.akamaihd.net/'][href*='steam']", e => {this.openInSteam(e, e.currentTarget.href);});
2020-06-09 09:07:04 +02:00
this.forceUpdateAll();
2020-04-20 09:23:17 +02:00
}
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
2018-10-11 10:21:26 +02:00
}
2020-04-20 09:23:17 +02:00
stop () {
if (window.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
this.stopping = true;
2019-10-22 11:37:23 +02:00
2020-04-20 09:23:17 +02:00
BDFDB.PluginUtils.clear(this);
}
2018-10-11 10:21:26 +02:00
}
2019-09-04 12:34:02 +02:00
2020-06-09 09:07:04 +02:00
onSettingsClosed () {
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.forceUpdateAll();
}
}
2020-04-20 09:23:17 +02:00
openInSteam (e, url) {
BDFDB.ListenerUtils.stopEvent(e);
BDFDB.LibraryRequires.request(url, (error, response, body) => {
if (BDFDB.LibraryRequires.electron.shell.openExternal("steam://openurl/" + response.request.href));
2020-06-09 09:07:04 +02:00
else BDFDB.DiscordUtils.openLink(response.request.href, settings.useChromium);
2020-04-20 09:23:17 +02:00
});
}
2020-06-09 09:07:04 +02:00
forceUpdateAll () {
settings = BDFDB.DataUtils.get(this, "settings");
}
2019-04-11 13:15:22 +02:00
}
2020-04-20 09:23:17 +02:00
})();