Phenrei / Pixiv Recommended Hider

// ==UserScript==
// @name        Pixiv Recommended Hider
// @description Hides the "Recommended" sidebar elements on pixiv illustration pages for those that open far too many tabs from them, but adds button that toggles them on and off
// @namespace   Phenrei
// @include     *://*pixiv.net/member_illust.php?mode=medium&illust_id=*
// @version     1
// @grant       none
// ==/UserScript==

function inject(func)
{
	var script = document.createElement("script");
	script.setAttribute("type", "application/javascript");
	script.appendChild(document.createTextNode(func));
	document.body.appendChild(script);
}

function hideAll()
{
	document.getElementsByClassName("_image-items").item(0).setAttribute("hidden", "true");
}

function expandAll()
{
	var elem = document.getElementsByClassName("_image-items").item(0);
	if (elem.hasAttribute("hidden")) {
		elem.removeAttribute("hidden");
		elem.parentElement.firstChild.setAttribute("value", "Hide Recommended");
	} else {
		elem.setAttribute("hidden", "true");
		elem.parentElement.firstChild.setAttribute("value", "Show Recommended");
	}
}

function insertButton()
{
	var button = document.createElement("input");
	button.type = "button";
	button.value = 'Show Recommended';
	
	inject(expandAll);
	
	button.setAttribute("onclick", "expandAll()");
	
	recommended = document.getElementsByClassName("_unit").item(1);
	recommended.insertBefore(button, recommended.firstChild);
}

insertButton();
hideAll();