Jump to content

User:Proteins/hottext.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre>
// Inspired by HotCat, this script tries to make paragraph editing easy.
// After clicking once, it adds a "(+)" symbol before every paragraph and "(±)(-)" symbols to each existing paragraph
 
// 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_HotText = false;
var hot_text_string = "¶";
 
function hotTextPopup() {
	window.alert("Once this function is written, you'll enter new text here\n");
} // closes hotTextPopup() 


function hotText() {
	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 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 paragraph 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];

		parent_node = temp_paragraph.parentNode;
		if (!parent_node) { continue; } // check for null parent node

		hot_text = document.createTextNode("(+¶)");
		hot_typeface = document.createElement("B");
		hot_typeface.appendChild(hot_text);
 
		hot_link = document.createElement("A");
		hot_link.className = "hottext";
		hot_link.title = "Click to add text here.";
		hot_link.appendChild(hot_typeface);
		hot_link.onclick = function () { 
			hotTextPopup();
 			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 paragraphs.";
	window.alert(alert_string);

} // closes function hotText()

$(function () {
            mw.util.addPortletLink('p-cactions', 'javascript:hotText()', hot_text_string, 'ca-hottext', 'Symbols for adding text', '', '');
});
 
//</pre>