User:Emma/ModifySidebar.js

// MODIFY SIDEBAR function ModifySidebar(action, section, name, link, text) { try { switch (section) { case "languages": var target = "p-lang"; break; case "toolbox": var target = "p-tb"; break; case "navigation": var target = "p-navigation"; break; case "personal": var target = "p-personal"; default: var target = "p-" + section; break; }       var tip = text if (action == "add") { addPortletLink(target, link, name, "pt-" +name, tip);

}       if (action == "remove") { var list = document.getElementById(target) .getElementsByTagName('div')[0] .getElementsByTagName('ul')[0]; var listelements = list.getElementsByTagName('li'); for (var i = 0; i < listelements.length; i++) { if (listelements[i].getElementsByTagName('a')[0].innerHTML == name ||                   listelements[i].getElementsByTagName('a')[0].href == link) { list.removeChild(listelements[i]); }           }        }    } catch(e) { // lets just ignore what's happened return; } } //

// // NewSidebar // Creates a new section in the sidebar. It will be blank, so use the ModifySidebar function to add links in it. // // id = The id of the section to create. Writing "p-" in the beginning is not required // name = The displayed name of the section. Automatically lowercase'd // placeafter = The id of the section you want to place your new section under. To place it at the top, type "logo" or "personal". Writing "p-" in the beginning is not required //

function NewSidebar(id, name, placeafter) { var newdiv = document.createElement('div'); var olddiv = document.getElementById('p-' + Section(placeafter)) var divIdName = 'p-' + id; newdiv.setAttribute('id',divIdName); newdiv.setAttribute('class','portlet'); newdiv.innerHTML = ' ' + name + '  '; document.getElementById("column-one").insertBefore(newdiv, olddiv.nextSibling) }

// // RemoveSidebar // Removes a section from the sidebar. Writing "p-" in the beginning is not required //

function RemoveSidebar(id) { var del = document.getElementById('p-' + Section(id)); del.parentNode.removeChild(del); }

// // Section // Runs the variable and returns the proper id //

function Section (sec) { switch (sec) { case "languages": return "lang"; case "toolbox": return "tb"; case "navigation": return "navigation"; case "personal": return "personal"; default: return sec; } }

function load { RemoveSidebar("Community") RemoveSidebar("The_Masterminds")

NewSidebar("custom1", "New", "toolbox") NewSidebar("custom2", "Attention needed", "custom1") NewSidebar("custom3", "Uncategorized", "custom2")

ModifySidebar("add", "personal", "my scripts", "/User:" + encodeURIComponent(wgUserName) + "/monobook.js", "My personal user scripts"); ModifySidebar("add", "custom1", "My Sandbox", "/User:" + encodeURIComponent(wgUserName) + "/Sandbox", ""); ModifySidebar("add", "custom1", "New pages", "/Special:Newestpages", ""); ModifySidebar("add", "custom1", "Gallery of new files", "/Special:NewImages", ""); ModifySidebar("add", "custom1", "File List", "/Special:ListFiles", "");

ModifySidebar("add", "custom2", "Articles with Image(s) Requested", "/Category:Articles_with_image(s)_requested", ""); ModifySidebar("add", "custom2", "Unused Files", "/Special:UnusedImages", ""); ModifySidebar("add", "custom2", "Short Pages", "/Special:ShortPages", ""); ModifySidebar("add", "custom2", "Pages needing attention", "/Category:Articles_needing_attention", ""); ModifySidebar("add", "custom2", "Wanted Pages", "/Special:WantedPages", ""); ModifySidebar("add", "custom2", "Broken Redirects", "/Special:BrokenRedirects", ""); ModifySidebar("add", "custom2", "Double Redirects", "/Special:DoubleRedirects", "");

ModifySidebar("add", "custom3", "Uncategorized Pages", "/Special:UncategorizedPages", ""); ModifySidebar("add", "custom3", "Uncategorized Files", "/Special:UncategorizedFiles", ""); ModifySidebar("add", "custom3", "Uncategorized Templates", "/Special:UncategorizedTemplates", ""); ModifySidebar("add", "custom3", "Uncategorized Categories", "/Special:UncategorizedCategories", ""); } addOnloadHook(load);

//