diff --git a/Perchance.js b/Perchance.js new file mode 100644 index 0000000..1303f7d --- /dev/null +++ b/Perchance.js @@ -0,0 +1,52 @@ +// ==UserScript== +// @name Perchance Stuff +// @namespace https://bullercodeworks.com +// @version 0.1 +// @description Perchance Modifications +// @author brian@bullercodeworks.com +// @match https://perchance.org/* +// @icon https://www.google.com/s2/favicons?sz=64&domain=perchance.org +// @grant none +// ==/UserScript== + +(function() { + 'use strict'; + + if(window.location.pathname == '/generators') { + handleGeneratorsPage(); + } else { + console.log('Not handling perchance page.'); + } + + function handleGeneratorsPage() { + console.log('Making Generators Page Sortable.'); + var allcards = document.querySelectorAll('table.generator-card'); + var bldCards = []; + for(i = 0; i < allcards.length; i++) { + var bldCard = { + 'card': allcards[i], + }; + if(allcards[i].classList.contains('external')) { + bldCard['score'] = -1; + bldCards = bldCards.concat(bldCard); + continue; + } + var scoreStr = allcards[1].children[0].children[0].children[1].innerText.split('\n')[0]; + if(scoreStr.includes('.')) { + scoreStr = scoreStr.replace('k','00'); + } else { + scoreStr = scoreStr.replace('k','00'); + } + scoreStr = scoreStr.replace('.',''); + bldCard['score'] = parseInt(scoreStr); + bldCards = bldCards.concat(bldCard); + } + bldCards.sort((a,b)=>a.score < b.score); + + var list = document.querySelector('#list'); + for(i = 0; i < bldCards.length; i++) { + list.prepend(bldCards[i]['card']); + } + } +})(); +