User:Proteins/highlightpageelements.js

// // 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', , ); }); //