I don't like web development, javascript and all these things, but I wanted that feature for so long, I finally made it myself (IMG:[
invalid]
style_emoticons/default/anime_cry.gif)
Hopefully, I didn't screw anything in HTML, javascript, or tampermonkey (that's what I made this in, in case it's incompatible with other scripts enabling thingies), but it worked for me.
Not a good presentation:
- I wanted to put the button next to the others next to the search bar, but it's all inside a form that cause the page to reload, and it was too much of a pain for me to try to get around this stuff if it's even possible
- <br> is overkill, but styling already drive me crazy enough when I have to customize that damn Firefox, won't try.
Hopefully, even if some parts suck, it can be a base for others to make something better thanks to part of the job being done.
Anyway, here's the code:
CODE
// ==UserScript==
// @name Random button for e-hentai
// @namespace uareader_random_button
// @version 1.2
// @description *fap* *fap* *fap*
// @author uareader
// @match https://e-hentai.org/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var buttonRandom;
var galleries = document.getElementsByClassName("gl1t");
var galleriesLength = galleries.length;
var galleriesContainer;
// create a button
if(galleriesLength > 1) {
let buttonRandom_insertion_area = document.querySelector("form[action='" + window.location.origin + window.location.pathname + "']");
if(buttonRandom_insertion_area != null) {
buttonRandom_insertion_area = buttonRandom_insertion_area.parentElement;
buttonRandom = document.createElement("input");
buttonRandom.value = "Randomize";
buttonRandom.type = "button";
buttonRandom.addEventListener('click',randomizeSearchResults,false);
buttonRandom_insertion_area.appendChild(document.createElement("br"));
buttonRandom_insertion_area.appendChild(buttonRandom);
galleriesContainer = galleries[0].parentElement;
}
}
// function that randomize the galleries results
function randomizeSearchResults(click_event) {
buttonRandom.removeEventListener('click',randomizeSearchResults,false);
var indexesList = [];
var tempValue;
var randomIndex;
// create an array of indexes
for(let i = 0; i < galleriesLength; i++) {
indexesList.push(i);
}
// swap each index with another from after within the array
for(let i= 0; i < galleriesLength - 1; i++) {
tempValue = indexesList[i];
randomIndex = Math.floor(Math.random() * (galleriesLength - (i+1)) + (i+1));
indexesList[i] = indexesList[randomIndex];
indexesList[randomIndex] = tempValue;
}
// swap the last index with another from before within the array
tempValue = indexesList[galleriesLength-1];
randomIndex = Math.floor(Math.random() * (galleriesLength-1));
indexesList[galleriesLength-1] = indexesList[randomIndex];
indexesList[randomIndex] = tempValue;
// finally randomize the galleries
for(let i= 0; i < galleriesLength; i++) {
galleriesContainer.insertBefore(galleriesContainer.childNodes[i], galleriesContainer.childNodes[indexesList[i]]);
}
buttonRandom.addEventListener('click',randomizeSearchResults,false);
}
})();
edit: changed code to version 1.1 to handle favorites (more important than normal search actually)
I do think I screwed up somewhere and it's not as random as it should (IMG:[
invalid]
style_emoticons/default/unsure.gif)
edit: changed code to version 1.2
This post has been edited by uareader: Dec 5 2021, 11:05