User:Proteins/hotimages.js

// // Inspired by HotCat, this script tries to make image editing easy. // After clicking once, it adds a "(+)" symbol before every paragraph and "(±)(-)" symbols to each existing image // This script should have two states: add paragraph symbols, or remove them. Clicking twice should not add the paragraph symbols twice. // Global variables var show_HotImages = false; var hot_image_string = "images"; function hotImagePopup { window.alert("Once this function is written, you'll choose a new image here\n"); } // closes hotImagePopup

function hotImages { var alert_string = ""; var on_main_page = false; var using_Internet_Explorer = false;

var paragraphs; var temp_paragraph; var num_paragraphs = 0; var paragraph_index = 0;

var child_node; var parent_node;

var hot_node; var hot_link; var hot_text; var hot_typeface; var num_hot_links_added = 0;

// Check whether we're on the Main Page on_main_page = false; if (document.getElementById("mp-topbanner")) { on_main_page = true; window.alert("Sorry, this script is intended for regular articles, not the Main Page."); return; } // closes check whether we're on the Main Page // check for Internet Explorer browser using_Internet_Explorer = false; if (navigator.userAgent.indexOf("MSIE") > -1) { using_Internet_Explorer = true; }

// add the image symbols num_hot_links_added = 0; paragraphs = document.getElementById('bodyContent').getElementsByTagName("P"); num_paragraphs = paragraphs.length; for (paragraph_index=0; paragraph_index<num_paragraphs; paragraph_index++) { temp_paragraph = paragraphs[paragraph_index];

child_node = temp_paragraph.firstChild; if ((child_node.nodeName == "A") && (child_node.name)) { continue; } // skip anchors parent_node = temp_paragraph.parentNode; if (!parent_node) { continue; } // check for null parent node

hot_text = document.createTextNode("(+) Add image here."); hot_typeface = document.createElement("I"); hot_typeface.appendChild(hot_text); hot_link = document.createElement("A"); hot_link.className = "hotimage"; hot_link.title = "Click to add an image here."; hot_link.appendChild(hot_typeface); hot_link.onclick = function { hotImagePopup; return; }		parent_node.insertBefore(hot_link, temp_paragraph); num_hot_links_added++; } // closes loop over paragraphs

// Acknowledgment alert_string = "Added " + num_hot_links_added + " symbols for new images."; window.alert(alert_string);

} // closes function hotImages

$(function {            mw.util.addPortletLink('p-cactions', 'javascript:hotImages', hot_image_string, 'ca-hotimages', 'Symbols for adding images', , ); }); //