User:Gary/expand hidden templates.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Gary/expand hidden templates. |
/*
EXPAND HIDDEN TEMPLATES
Description: Expands and collapses hidden templates on a page.
Templates affected include {{hidden}}, {{hidden archive top}}, and their derivatives.
Documentation: [[Wikipedia:Expand Hidden Templates]]
*/
if (typeof(unsafeWindow) != 'undefined')
{
addPortletLink = mw.util.addPortletLink;
collapseTable = unsafeWindow.collapseTable;
expandHiddenTemplates = expandHiddenTemplates;
toggleNavigationBar = unsafeWindow.toggleNavigationBar;
wgAction = mw.config.get('wgAction')
}
if (typeof(expandHiddenTemplates) == 'undefined')
expandHiddenTemplates = {};
expandHiddenTemplatesMain = function()
{
var nodeText = document.getElementById('t-expand-hidden-templates').firstChild.firstChild.firstChild;
if (nodeText.nodeValue == 'Expand templates')
var action = 'expanding';
else
var action = 'collapsing';
// .collapseButton
var buttons = document.getElementsByClassName('collapseButton');
for (var i = 0; i < buttons.length; i++)
{
if (
(action == 'expanding' && buttons[i].childNodes[1].firstChild.nodeValue == 'show')
|| (action == 'collapsing' && buttons[i].childNodes[1].firstChild.nodeValue == 'hide')
)
buttons[i].childNodes[1].click(); // IE-only?
}
// .NavToggle
var toggles = document.getElementsByClassName('NavToggle');
for (var i = 0; i < toggles.length; i++)
{
if (
(action == 'expanding' && toggles[i].firstChild.nodeValue == '[show]')
|| (action == 'collapsing' && toggles[i].firstChild.nodeValue == '[hide]')
)
toggles[i].click(); // IE-only?
}
if (buttons.length == 0 && toggles.length == 0)
alert('There are no templates to expand on this page.');
else
{
if (action == 'expanding')
nodeText.nodeValue = 'Collapse templates';
else
nodeText.nodeValue = 'Expand templates';
}
}
expandHiddenTemplatesPortletLink = function()
{
var wgAction = mw.config.get('wgAction');
if ( mw.util.addPortletLink)
{
if ((wgAction != 'view' && wgAction != 'submit' && wgAction != 'edit' && wgAction != 'purge') || navigator.appName.indexOf('Microsoft Internet Explorer') == -1)
return;
var buttons = document.getElementsByClassName('collapseButton');
var toggles = document.getElementsByClassName('NavToggle');
if (buttons.length + toggles.length == 0)
return;
if (typeof(expandHiddenTemplates) == 'undefined')
expandHiddenTemplates = {};
if (typeof(expandHiddenTemplates.addTab) == 'undefined')
expandHiddenTemplates.addTab = false;
if (typeof(expandHiddenTemplates.addToNavigation) == 'undefined')
expandHiddenTemplates.addToNavigation = false;
if (expandHiddenTemplates.addTab)
mw.util.addPortletLink('p-cactions', 'javascript:expandHiddenTemplatesMain()', 'Expand templates', 't-expand-hidden-templates', 'Expands or hides all collapsible templates');
if (expandHiddenTemplates.addToNavigation)
mw.util.addPortletLink('p-navigation', 'javascript:expandHiddenTemplatesMain()', 'Expand templates', 't-expand-hidden-templates', 'Expands or hides all collapsible templates');
if (!expandHiddenTemplates.addTab && !expandHiddenTemplates.addToNavigation)
mw.util.addPortletLink('p-tb', 'javascript:expandHiddenTemplatesMain()', 'Expand templates', 't-expand-hidden-templates', 'Expands or hides all collapsible templates');
}
}
if (typeof(unsafeWindow) == 'undefined')
$(expandHiddenTemplatesPortletLink);
else
expandHiddenTemplatesPortletLink();
if (typeof(unsafeWindow) != 'undefined')
unsafeWindow.expandHiddenTemplatesMain = expandHiddenTemplatesMain;