User:Proteins/hottext.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/hottext. |
//<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>