-
Notifications
You must be signed in to change notification settings - Fork 0
/
SteamAppLinks.plugin.js
59 lines (51 loc) · 1.84 KB
/
SteamAppLinks.plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @name SteamAppLinks
* @author Oni-Chan-inc
* @version 0.0.1
* @description Opens Steam Links from people's Profiles and in discord in Steam app
* @website https://nuggy.space
* @source https://github.com/Oni-Chan-inc/SteamAppLinks
*/
module.exports = (_ => {
const config = {
"info": {
"name": "SteamAppLinks",
"author": "Oni-Chan-inc",
"version": "0.0.1",
"description": "Opens Steam Links from people's Profiles and in discord in Steam app"
}
};
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
getName () {return config.info.name;}
getAuthor () {return config.info.author;}
getVersion () {return config.info.version;}
} : (([Plugin, BDFDB]) => {
const urls = {
steam: ["https://steamcommunity.", "https://help.steampowered.", "https://store.steampowered.", "a.akamaihd.net/"]
};
return class SteamAppLinks extends Plugin {
onLoad () {}
onStart () {
for (let key in urls) BDFDB.ListenerUtils.add(this, document, "click", urls[key].map(url => url.indexOf("http") == 0 ? `a[href^="${url}"]` : `a[href*="${url}"][href*="${key}"]`).join(", "), e => {
this.openIn(e, key, e.currentTarget.href);
});
}
onStop () {}
openIn (e, key, url) {
let platform = BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(key);
if (typeof this[`openIn${platform}`] == "function") {
BDFDB.ListenerUtils.stopEvent(e);
this[`openIn${platform}`](url);
return true;
}
return false;
}
openInSteam (url) {
BDFDB.LibraryRequires.request(url, (error, response, body) => {
if (BDFDB.LibraryRequires.electron.shell.openExternal("steam://openurl/" + response.request.href));
else BDFDB.DiscordUtils.openLink(response.request.href);
});
}
};
})(window.BDFDB_Global.PluginUtils.buildPlugin(config));
})();