Hi, I'm new here. After looking at the mascot changer for the site I wanted to add images to the list with a GM script but ended up rewriting the whole thing due to it using cookies, not being written very well, etc. My script uses HTML5 localStorage and includes a link. It changes the background color too. Just figured I put it here so others could use it or maybe it could be used on the site. Copyright is in the public domain. Just plop it into a GM script and include it at root "www.e621.net/".
var CoolMascot = {
bg_imgs_key: "e621bgimgs",
bg_img_index_key: "e621bgimgindex",
container: document.getElementById("content2"),
default_bgcolor: document.body.style.backgroundColor,init: function() {
// Uncomment to reset then comment again.
//localStorage.removeItem(this.bg_imgs_key);
var bg_imgs_str = localStorage.getItem(this.bg_imgs_key);
var bg_img_index_str = localStorage.getItem(this.bg_img_index_key);
if(bg_imgs_str && bg_img_index_str) {
this.bg_imgs = JSON.parse(bg_imgs_str);
this.bg_img_index = JSON.parse(bg_img_index_str);
} else {
this.first_init();
}
var citation = document.createElement("div");
citation.setAttribute("id", "citation");
citation.textContent = "Credit: ";
this.container.appendChild(citation);this.setBgImg(this.bg_img_index);
},first_init: function() {
var bg_imgs = new Array();
// default
bg_imgs.push(["22762", "data/4e/43/4e436a63e85b3996f1d5599bfb76bdce.png"]);
// site
bg_imgs.push(["109434", "esix1.jpg"]);
bg_imgs.push(["63467", "esix2.jpg"]);
bg_imgs.push(["63403", "raptor1.jpg"]);
bg_imgs.push(["109196", "background_mascot2.gif"]);
bg_imgs.push(["124413", "hexerade.jpg"]);
// tag rave
bg_imgs.push(["71140", "data/38/80/3880d7da9df16ac14a45284b9d5a44d8.jpg"]);
bg_imgs.push(["68922", "data/c6/fe/c6fe9f063cb1aa8dd459ac0189634941.png", "#000000"]);
bg_imgs.push(["68746", "data/78/62/786271e02539cdc631293e27fe9192fe.png", "#000000"]);
bg_imgs.push(["19965", "data/0d/e0/0de0606cef07635514ab00cb10737116.jpg", "#0D2569"]);
bg_imgs.push(["22780", "data/08/96/089676a44fabad20cd44e302ce4edade.jpg"]);
bg_imgs.push(["29024", "data/9f/0a/9f0acf7e44d0608d58fe63cb81eafaee.jpg", "#240B06"]);
bg_imgs.push(["22762", "data/4e/43/4e436a63e85b3996f1d5599bfb76bdce.png"]);
bg_imgs.push(["652", "data/90/d7/90d733ee77960e26090926885c3bdc63.jpg", "#240623"]);
bg_imgs.push(["92534", "data/8c/15/8c15ce857fba0d4687d13051ad825a92.jpg"]);
bg_imgs.push(["92535", "data/7e/b1/7eb13c0d3fadd958a380059aaf652ab4.jpg"]);
bg_imgs.push(["93303", "data/57/f9/57f91314519dba3240ee2925409c1bdc.jpg", "#000000"]);
bg_imgs.push(["96693", "data/7c/15/7c153a6e27c5c6a0b1467d5651bfc50a.png", "#000000"]);
bg_imgs.push(["118875", "data/ee/c3/eec36c6d74061d63ea0e0cec7abbb4d6.jpg", "#000000"]);
bg_imgs.push(["130408", "data/cb/18/cb187938e37f1164ec06a773d0c97119.jpg"]);
bg_imgs.push(["136394", "data/fd/48/fd48250faaab9622c0271c16ecec67db.jpg"]);
bg_imgs.push(["8967", "data/cd/4b/cd4bf0cc64f687b8b4b1296a4f38b78f.jpg"]);
bg_imgs.push(["28959", "data/ce/4f/ce4f49e823c4fb5703993ce72cf86a07.jpg", "#000000"]);
bg_imgs.push(["29023", "data/cf/d4/cfd4a6b7b7930b1ad11add514a6ee952.jpg", "#000000"]);
bg_imgs.push(["30096", "data/ab/ec/abec1a5b55eabe30f93b8129a5f369da.jpg", "#000000"]);
// Add more here. bg_imgs.push([id, url, color]);
// Don't forget to reset after adding.localStorage.setItem(this.bg_imgs_key, JSON.stringify(bg_imgs));
this.bg_imgs = bg_imgs;
this.bg_img_index = 0;
localStorage.setItem(this.bg_img_index_key, JSON.stringify(this.bg_img_index));
},setBgImg: function(index) {
var [post_id, URL, color] = this.bg_imgs[index];
document.body.style.backgroundImage = "url(" + URL + ")";
document.body.style.backgroundPosition = "center";
document.body.style.backgroundSize = "contain";
if(color) { document.body.style.backgroundColor = color;
} else { document.body.style.backgroundColor = this.default_bgcolor; };
var post_url = "post/show/" + post_id + "/";
var link = document.createElement("a");
link.textContent = "Link";
link.href = post_url;
var citation = document.getElementById("citation");
var old_link = citation.getElementsByTagName("a")[0];
if(old_link) {
citation.replaceChild(link, citation.getElementsByTagName("a")[0]);
} else {
citation.appendChild(link);
}
},shiftBgImg: function() {
this.bg_img_index++;
if(this.bg_img_index == this.bg_imgs.length) this.bg_img_index = 0;
this.setBgImg(this.bg_img_index);
localStorage.setItem(this.bg_img_index_key, this.bg_img_index);
}
};
window.addEventListener("load", function() {
CoolMascot.init();
unsafeWindow.bgChange = function() {CoolMascot.shiftBgImg();};
}, false);
Updated