Skip to content

Instantly share code, notes, and snippets.

@OJ7
Created June 10, 2020 17:30
Show Gist options
  • Save OJ7/73cab19d8f06ce6d9c80ed42565fd5c6 to your computer and use it in GitHub Desktop.
Save OJ7/73cab19d8f06ce6d9c80ed42565fd5c6 to your computer and use it in GitHub Desktop.
Parse Xbox GamePass availability and display on DekuDeals
/* XBOX GAME PASS LIST PAGE
https://www.xbox.com/en-US/xbox-game-pass/games
*/
// Scrape XBGP Data (run on each page)
var titles = [...document.getElementsByClassName("x1GameName")].map(a => a.innerText.replace(/( - Windows 10 Edition)|( - Xbox One Edition)|( - Windows 10)|( for Windows 10)|( \(Windows\))/, ''));
var availability = [...[...[...document.getElementsByClassName("availability")]].map(a => a.getElementsByClassName("c-glyph"))].map(a => [...a].map(b => b.ariaLabel));
var gpMap = JSON.parse(window.localStorage.getItem("xbgp", gpMap) || '{}');
for(var i = 0; i < titles.length; i++) {
if(gpMap[titles[i]]) {
gpMap[titles[i]] = gpMap[titles[i]].concat(availability[i]);
} else {
gpMap[titles[i]] = availability[i];
}
}
window.localStorage.setItem("xbgp", JSON.stringify(gpMap))
/* DEKUDEALS GAME PAGE
e.g. https://www.dekudeals.com/items/ori-and-the-blind-forest-de
*/
// Calculate data
var gpMap = JSON.parse(window.localStorage.getItem("xbgp", gpMap) || '{}'); // not stored cross site
var title = [...document.getElementsByClassName("display-5")][0].innerText;
var availability = gpMap[title] || '';
// Insert XBGP element
[...document.getElementsByClassName("details list-group")][0].insertAdjacentHTML('afterBegin', `<li class="list-group-item"><strong>GamePass Availability:</strong>[` + availability + `]</li>`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment