Jump to content

User:Terasail/ReferenceHider.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.
let reflists = $('.reflist');
if (reflists.length > 0) {
	for (let i = 0; i < reflists.length; i++) {
		reflists[i].id = "CollapsibleSection" + i;
		let section = $('#CollapsibleSection' + i)[0];
		let sectionList = section.children[0];
		sectionList.style = "display:none;";
		$(section).prepend('<span style="font-size: 1.25rem; padding-left: 25px; background: url(https://upload.wikimedia.org/wikipedia/commons/3/34/OOjs_UI_icon_bookmark-rtl-progressive.svg) left center no-repeat;"></span><span style="font-size:1.25rem"><a href="" id="listToggle' + i + '">Open</a> reference list</span>');
		let toggleButton = $('#listToggle' + i)[0];
		$(toggleButton).on('click', function (e) {
			e.preventDefault();
			if (toggleButton.innerHTML == "Open") {
				sectionList.style = "";
				toggleButton.innerHTML = "Close";
			} else {
				sectionList.style = "display:none;";
				toggleButton.innerHTML = "Open";
			}
		});
	}
}