Skip to content

Commit

Permalink
Run global steamdb script at document start and wait for dom to load …
Browse files Browse the repository at this point in the history
…before sending message
  • Loading branch information
xPaw committed Oct 4, 2024
1 parent c8daae4 commit 1c4c4d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"content_scripts":
[
{
"run_at": "document_start",
"matches":
[
"https://steamdb.info/*"
Expand Down
46 changes: 30 additions & 16 deletions scripts/steamdb/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,40 @@ GetOption( { 'steamdb-highlight': true }, ( items ) =>
contentScriptQuery: 'FetchSteamUserData',
}, ( response ) =>
{
if( response.error )
console.log( document.readyState );

const OnPageLoaded = () =>
{
WriteLog( 'Failed to load userdata', response.error );
if( response.error )
{
WriteLog( 'Failed to load userdata', response.error );

window.postMessage( {
version: EXTENSION_INTEROP_VERSION,
type: 'steamdb:extension-error',
error: `Failed to load your games. ${response.error}`,
}, GetHomepage() );
}
window.postMessage( {
version: EXTENSION_INTEROP_VERSION,
type: 'steamdb:extension-error',
error: `Failed to load your games. ${response.error}`,
}, GetHomepage() );
}

if( response.data )
{
window.postMessage( {
version: EXTENSION_INTEROP_VERSION,
type: 'steamdb:extension-loaded',
data: response.data,
}, GetHomepage() );
if( response.data )
{
window.postMessage( {
version: EXTENSION_INTEROP_VERSION,
type: 'steamdb:extension-loaded',
data: response.data,
}, GetHomepage() );

WriteLog( 'Userdata loaded', `Packages: ${response.data.rgOwnedPackages.length}` );
WriteLog( 'Userdata loaded', `Packages: ${response.data.rgOwnedPackages.length}` );
}
};

if( document.readyState === 'loading' )
{
document.addEventListener( 'DOMContentLoaded', OnPageLoaded, { once: true } );
}
else
{
OnPageLoaded();
}
} );
} );

0 comments on commit 1c4c4d5

Please sign in to comment.