Adding Perchance Script
This commit is contained in:
parent
e51b0e7b1a
commit
a6c1a61f4a
52
Perchance.js
Normal file
52
Perchance.js
Normal file
@ -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']);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
Loading…
x
Reference in New Issue
Block a user