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
class SteamProfileLink {
getName ( ) { return "SteamProfileLink" ; }
2019-11-29 19:11:56 +01:00
getVersion ( ) { return "1.0.8" ; }
2018-10-11 10:21:26 +02:00
getAuthor ( ) { return "DevilBro" ; }
2019-01-17 23:48:29 +01:00
getDescription ( ) { return "Opens any Steam links in Steam instead of your internet browser." ; }
2019-09-04 12:34:02 +02:00
constructor ( ) {
2019-04-11 13:15:22 +02:00
this . changelog = {
2019-11-29 19:11:56 +01:00
"improved" : [ [ "Inbuilt Window" , "Option to use an inbuilt browser instead of the default OS browser" ] , [ "New Library Structure & React" , "Restructured my Library and switched to React rendering instead of DOM manipulation" ] ]
2019-04-11 13:15:22 +02:00
} ;
}
2019-11-29 19:11:56 +01:00
initConstructor ( ) {
this . defaults = {
settings : {
useChromium : { value : false , description : "Use inbuilt browser instead of default if fails to open Steam" }
}
} ;
}
getSettingsPanel ( ) {
2020-01-17 19:50:31 +01:00
if ( ! window . BDFDB || typeof BDFDB != "object" || ! BDFDB . loaded || ! this . started ) return ;
2019-11-29 19:11:56 +01:00
let settings = BDFDB . DataUtils . get ( this , "settings" ) ;
2020-03-28 07:55:39 +01:00
let settingsPanel , settingsItems = [ ] ;
2019-11-29 19:11:56 +01:00
2020-03-28 07:55:39 +01:00
settingsItems = settingsItems . concat ( this . createSelects ( false ) ) ;
2019-11-29 19:11:56 +01:00
2020-03-28 07:55:39 +01:00
for ( let key in settings ) settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
2019-11-29 19:11:56 +01:00
className : BDFDB . disCN . marginbottom8 ,
type : "Switch" ,
plugin : this ,
keys : [ "settings" , key ] ,
label : this . defaults . settings [ key ] . description ,
value : settings [ key ]
} ) ) ;
2020-03-28 07:55:39 +01:00
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , settingsItems ) ;
2019-11-29 19:11:56 +01:00
}
2018-10-11 10:21:26 +02:00
//legacy
load ( ) { }
start ( ) {
2020-01-17 19:50:31 +01:00
if ( ! window . BDFDB ) window . BDFDB = { myPlugins : { } } ;
if ( window . BDFDB && window . BDFDB . myPlugins && typeof window . BDFDB . myPlugins == "object" ) window . BDFDB . myPlugins [ this . getName ( ) ] = this ;
2020-01-21 12:56:26 +01:00
let libraryScript = document . querySelector ( "head script#BDFDBLibraryScript" ) ;
2019-05-26 13:55:26 +02:00
if ( ! libraryScript || ( performance . now ( ) - libraryScript . getAttribute ( "date" ) ) > 600000 ) {
2018-10-11 10:21:26 +02:00
if ( libraryScript ) libraryScript . remove ( ) ;
libraryScript = document . createElement ( "script" ) ;
2019-05-26 13:55:26 +02:00
libraryScript . setAttribute ( "id" , "BDFDBLibraryScript" ) ;
2018-10-11 10:21:26 +02:00
libraryScript . setAttribute ( "type" , "text/javascript" ) ;
2019-10-18 10:56:41 +02:00
libraryScript . setAttribute ( "src" , "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js" ) ;
2019-01-17 23:48:29 +01:00
libraryScript . setAttribute ( "date" , performance . now ( ) ) ;
2020-01-14 00:06:07 +01:00
libraryScript . addEventListener ( "load" , _ => { this . initialize ( ) ; } ) ;
2018-10-11 10:21:26 +02:00
document . head . appendChild ( libraryScript ) ;
2019-05-26 13:55:26 +02:00
}
2020-01-17 19:50:31 +01:00
else if ( window . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) this . initialize ( ) ;
2020-01-14 00:06:07 +01:00
this . startTimeout = setTimeout ( _ => {
2019-11-01 10:27:07 +01:00
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 ) ;
2018-10-11 10:21:26 +02:00
}
initialize ( ) {
2020-01-17 19:50:31 +01:00
if ( window . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2019-01-22 11:05:54 +01:00
if ( this . started ) return ;
2019-10-22 18:55:25 +02:00
BDFDB . PluginUtils . init ( this ) ;
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . add ( this , document , "click" , "a[href^='https://steamcommunity.'], a[href^='https://store.steampowered.'], a[href*='a.akamaihd.net/'][href*='steam']" , e => { this . openInSteam ( e , e . currentTarget . href ) ; } ) ;
2018-10-11 10:21:26 +02:00
}
2019-11-01 10:14:50 +01: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
}
stop ( ) {
2020-01-17 19:50:31 +01:00
if ( window . BDFDB && typeof BDFDB === "object" && BDFDB . loaded ) {
2019-10-22 11:37:23 +02:00
this . stopping = true ;
2019-10-22 18:55:25 +02:00
BDFDB . PluginUtils . clear ( this ) ;
2018-10-11 10:21:26 +02:00
}
}
2019-09-04 12:34:02 +02:00
2019-04-11 13:15:22 +02:00
openInSteam ( e , url ) {
2019-10-22 18:55:25 +02:00
BDFDB . ListenerUtils . stopEvent ( e ) ;
2019-09-11 12:14:43 +02:00
BDFDB . LibraryRequires . request ( url , ( error , response , body ) => {
if ( BDFDB . LibraryRequires . electron . shell . openExternal ( "steam://openurl/" + response . request . href ) ) ;
2019-11-29 19:11:56 +01:00
else BDFDB . DiscordUtils . openLink ( response . request . href , BDFDB . DataUtils . get ( this , "settings" , "useChromium" ) ) ;
2019-04-11 13:15:22 +02:00
} ) ;
}
2018-10-11 10:21:26 +02:00
}