Skip to content

Instantly share code, notes, and snippets.

@molly
Last active February 26, 2022 06:13
Show Gist options
  • Save molly/60960bd99bb4897ad96151bdd88478a1 to your computer and use it in GitHub Desktop.
Save molly/60960bd99bb4897ad96151bdd88478a1 to your computer and use it in GitHub Desktop.
Pixeldex
// ==UserScript==
// @name Pixeldex
// @namespace https://www.mollywhite.net/
// @version 0.1
// @description Gawk at Pixelmon's funny new NFTs
// @author Molly White
// @match *://pixelmon.club/experience/*
// ==/UserScript==
(function() {
function getIsHatched() {
var nextData = document.querySelector('#__NEXT_DATA__').innerHTML
var json = JSON.parse(nextData);
return json.props.pageProps.routeInfo.modelName !== "Unhatched"
}
function getNextPixelmon() {
var splitCurrentLocation = window.location.href.split('/')
var currentId = parseInt(splitCurrentLocation[splitCurrentLocation.length - 1], 10)
var nextId = currentId + 1;
window.location = 'https://pixelmon.club/experience/' + nextId
}
function onReady() {
if (!getIsHatched()) {
getNextPixelmon();
}
// Add button to go to next
var nextButton = document.createElement('button')
nextButton.innerHTML = "Next Pixelmon"
nextButton.style.cssText = 'position:fixed;right:200px;top:5px;'
document.querySelector('body').append(nextButton);
nextButton.addEventListener('click', function (evt) {
evt.preventDefault();
getNextPixelmon();
})
}
var interval = setInterval(function() {
var elems = document.querySelectorAll('#__NEXT_DATA__')
if (elems.length < 1) {
return false;
} else {
clearInterval(interval);
onReady();
}
}, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment