User:BryghtShadow/common.js

( function {	// When the page is loaded with window width <= 720px	// an inline style "position: relative" is added to "div#mw-panel"	// and that breaks the sidebar from returning to the side	// during resize when window width > 720px.	// This code attempts to fix that.

// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver#Example var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; // Select the node that will be observed for mutations var targetNode = document.getElementById('mw-panel'); // Options for the observer (which mutations to observe) var config = { attributes: true }; // Callback function to execute when mutations are observed var callback = function(mutationsList, observer) { for(var mutation of mutationsList) { if (mutation.type == 'attributes') { if ($(targetNode).css("position") === "relative") { $(targetNode).css("position", ""); console.log(`Removed inline "position: relative" from #mw-panel.`); if ($(targetNode).attr("style") === "") { $(targetNode).removeAttr("style"); console.log("Removed empty style attribute from #mw-panel."); }	       	}	        }	    }		// Later, you can stop observing observer.disconnect; };	// Create an observer instance linked to the callback function var observer = new MutationObserver(callback); // Start observing the target node for configured mutations observer.observe(targetNode, config); } );