53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
// ==UserScript==
|
|
// @name Perchance Stuff
|
|
// @namespace https://bullercodeworks.com
|
|
// @version 0.2
|
|
// @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(var 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(var i = 0; i < bldCards.length; i++) {
|
|
list.prepend(bldCards[i]['card']);
|
|
}
|
|
}
|
|
})();
|
|
|