Jump to content

User:JJPMaster/wallpaper.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var portlet = mw.util.addPortletLink('p-cactions', '#', 'Change wallpaper', 'p-wallp', 'Change the wallpaper for this page');
let bgImage = localStorage.getItem("wp-wallpaper");
mw.loader.load( '/w/index.php?title=User:JJPMaster/wallpaper.css&action=raw&ctype=text/css', 'text/css' ); // Backlink: [[User:JJPMaster/wallpaper.css]]
function setWallpaper(url) {
	$("body").css({
		"background-image": `url(${url})`,
		"background-size": "cover",
		"background-attachment": "fixed",
	});
	$(".mw-body").css({"background-color": "rgba(255, 255, 255, 0.8)"});
	// $("#mw-page-base").css({"background-color": "rgba(255, 255, 255, 0.8) !important"});
}
function setInverted() {
	if (localStorage.getItem("wp-inverted") == "true") {
		$("#mw-panel .mw-list-item, #footer-info, #footer-places").css({
			"filter": "invert(1)",
		});
		$(".mw-body").css({"background-color": "rgba(255, 255, 255, 0.8)"});
	}
	return;
}
setWallpaper(bgImage);
setInverted();
$(portlet).click(() => {
	bgImage = prompt("What would you like to change the wallpaper to? Please enter a URL.", localStorage.getItem("wp-wallpaper"));
	if(bgImage) {
		localStorage.setItem("wp-wallpaper", bgImage);
		var inverted = confirm("Should the color of the text be inverted?");
		localStorage.setItem("wp-inverted", String(inverted));
		setInverted();
		setWallpaper(bgImage);
	}
});