Skip to content

Instantly share code, notes, and snippets.

@IA21
Last active April 5, 2022 01:23
Show Gist options
  • Save IA21/866c8c380165adf2caac7a421f608342 to your computer and use it in GitHub Desktop.
Save IA21/866c8c380165adf2caac7a421f608342 to your computer and use it in GitHub Desktop.
picks random anime/manga from your MAL animelist/mangalist pages
// ==UserScript==
// @name MAL random
// @version 4
// @description picks random anime/manga from your MAL animelist/mangalist pages
// @author IA21
// @match https://myanimelist.net/mangalist/*
// @match https://myanimelist.net/animelist/*
// @grant none
// ==/UserScript==
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function getRandomLink() {
var data = JSON.parse(document.getElementsByTagName("table")[0].dataset.items);
if(document.body.dataset.work === "anime")
{ return "https://myanimelist.net" + data[getRandomInt(0, data.length)].anime_url; }
else if(document.body.dataset.work === "manga")
{ return "https://myanimelist.net" + data[getRandomInt(0, data.length)].manga_url; }
}
(function() {
'use strict';
var container = document.createElement("div");
var rand_link = document.createElement("a");
rand_link.innerHTML = "<i class='fa fa-random'></i> random";
rand_link.style.marginLeft = "15px";
rand_link.style.color = "white";
rand_link.target = "_blank";
rand_link.href = getRandomLink();
container.style.lineHeight = "38px";
container.style.position = "absolute";
container.appendChild(rand_link);
var text = document.getElementsByClassName("text")[10];
document.getElementsByClassName("list-status-title")[0].insertBefore(container, text);
rand_link.onmouseup = function(e) {
rand_link.href = getRandomLink();
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment