Jump to content

User:Chaotic Enby/blur.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.
function initializeBlur(e, f) {
	var blur = (sessionStorage.getItem('blur') == "true");
	images = $('.mw-file-element');
	if(blur){
	  images.css('filter', 'blur(30px)');
	} else {
	  images.css('filter', 'blur(0px)');
	}
}

function switchBlur(e) {
	var blur = (sessionStorage.getItem('blur') == "true");
	images = $('.mw-file-element');
	if(blur){
	  images.css('filter', 'blur(0px)');
	  $('#pt-blur').find("span").html('Blur images');
	  blur = false;
	} else {
	  images.css('filter', 'blur(30px)');
	  $('#pt-blur').find("span").html('Show images');
	  blur = true;
	}
	sessionStorage.setItem('blur', (blur?"true":"false"));
}

function buildMenu() {
  mw.util.addPortlet('p-imgs', 'Images', '#p-interaction');
  mw.util.addPortletLink ( 'p-imgs', '#', 'Show images', 'pt-blur', 'Show/blur images' );
  $('#pt-blur').click(switchBlur);
  initializeBlur(null);
  const observer = new MutationObserver(initializeBlur);
  const config = { attributes: true, childList: true, subtree: true };
  observer.observe($('#content'), config);
}

$(document).ready(buildMenu);