User:Proteins/highlightpageelements.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. |
Documentation for this user script can be added at User:Proteins/highlightpageelements. |
//<pre>
// This script highlights elements on a page, for tutorials.
// Offers slightly more flexibility and speed than editing monobook.css
//
// To use this script, add "importScript('User:Proteins/highlightpageelements.js');" to your monobook.js subpage
// under your user page, as you can see at User:Proteins/monobook.js
function highlightPageElements() {
var error_string = "";
var alert_string = "";
var prompt_string = "";
var default_string = "";
var target_element;
var element_name = "";
var subelements;
var temp_subelement;
var num_subelements = 0;
var subelement_index = 0;
var highlight_DIV_subelements = true;
// Input the user's target element
default_string = "p-cactions";
prompt_string = "Which element would you like to highlight? Enter \"help\" for a list of common choices.";
element_name = window.prompt(prompt_string, default_string);
// Check for help request
if ((element_name.match(/^help$/ig)) || (element_name.match(/^list$/ig))) {
alert_string = "\"p-personal\" Personal user commands at the upper right.\n";
alert_string += "\"p-cactions\" User tabs at the top of the article.\n";
alert_string += "\"p-logo\" Wikipedia logo at the top of the left-hand column.\n";
alert_string += "\"p-navigation\" Navigation portlet in the left-hand column.\n";
alert_string += "\"p-search\" Search box in the left-hand column.\n";
alert_string += "\"p-interaction\" Interaction portlet in the left-hand column.\n";
alert_string += "\"p-tb\" Toolbox portlet in the left-hand column.\n";
alert_string += "\"p-lang\" Interwiki portlet in the left-hand column.\n";
alert_string += "\"p-footer\" Footer at the bottom of the page.\n";
window.alert(alert_string);
return;
}
// Identify the target element
target_element = document.getElementById(element_name);
// Highlight the target element
if (target_element) {
target_element.style.cssText = "background-color:yellow";
if (highlight_DIV_subelements == true) {
subelements = target_element.getElementsByTagName("DIV");
if (subelements) {
num_subelements = subelements.length;
for (subelement_index=0; subelement_index<num_subelements; subelement_index++) {
temp_subelement = subelements[subelement_index];
if (!temp_subelement) { continue; }
temp_subelement.style.cssText = "background-color:yellow";
} // closes loop over the DIV subelements
} // closes check for DIV subelements
alert_string = "Highlighted " + num_subelements + " sub-elements of " + element_name + ".\n";
window.alert(alert_string);
} // closes check whether to highlight DIV subelements
} else {
error_string = "Element " + element_name + " was not found on this page.\n";
window.alert(error_string);
} // closes check for the target element
} // closes function highlightPageElements()
addOnloadHook(function () {
mw.util.addPortletLink('p-navigation', 'javascript:highlightPageElements()', 'Highlight', 'ca-highlight', 'Highlights page elements at will', '', '');
});
//</pre>