Last active
May 20, 2023 17:30
-
-
Save shdwmtr/fad262feeccc2b578b9c3a6898ea6fed to your computer and use it in GitHub Desktop.
check when new game is clicked / loaded into view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//TIPS | |
//by the time this script is injected, the dom MAY be loaded | |
//alert function breaks CEF | |
console.log('hello from patcher current page -> ' + document.title); | |
function game_selected(name, appid) | |
{ | |
console.log(`game: ${name}, appid: ${appid}`) | |
} | |
function is_ready() | |
{ | |
targetElement = document.querySelector('[class*="library_MainPanel_"]'); | |
var observerCallback = function(mutations) | |
{ | |
mutations.forEach(function(mutation) | |
{ | |
if (mutation.addedNodes[0] != null && mutation.addedNodes[0].classList.contains("appdetailsoverview_ColumnContainer_OhSdL")) | |
{ | |
const title = document.querySelector('[class*="gamelistentry_Selected_"]').children[0].textContent | |
const appid = document.querySelector(`[class*="library_MainPanel_"] [class*="libraryassetimage_Container_"] img`).src | |
game_selected(title, appid.match(/\/(\d+)_/)[1]); | |
} | |
}); | |
}; | |
var observer = new MutationObserver(observerCallback); | |
observer.observe(targetElement, { childList: true, subtree: true }); | |
} | |
var observerCallback = function(mutations) { | |
mutations.forEach(function(mutation) { | |
if (mutation.type === 'childList') { | |
mutation.addedNodes.forEach(function(addedNode) { | |
if (addedNode.classList && addedNode.classList.contains('library_Container_3xRRJ')) | |
is_ready();//dont close observer in case library is reloaded | |
}); | |
} | |
}); | |
}; | |
var observer = new MutationObserver(observerCallback); | |
observer.observe(document.body, { childList: true, subtree: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment