User:PleaseStand/highlight-comments.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. |
![]() | This user script seems to have a documentation page at User:PleaseStand/highlight-comments. |
//<pre><nowiki>
// highlight-comments.js - written by PleaseStand, 2010.
// Source: http://en.wikipedia.org/wiki/User:PleaseStand/highlight-comments.js
// NOTE: This script is in the public domain (not copyrighted). For details, see
// http://en.wikipedia.org/wiki/Template:PD-self
// DESCRIPTION: Highlights your posts to discussion pages
// (at least a significant part). This is just the JS part; you need a
// corresponding CSS line to actually affect text color. An example:
// .mycomment { background: #ff9; }
/*global window, document, jQuery, wgFormattedNamespaces, wgUserName,
HighlightCommentsJsDescription, importScriptURI, hookEvent, addPortletLink*/
// Function names
var HighlightCommentsJsHighlight, HighlightCommentsJsUnhighlight;
// Global variables
var HighlightCommentsJsWrapped = false, HighlightCommentsJsTries = 40,
HighlightCommentsJsSwitch;
HighlightCommentsJsHighlight = function(){
// Lists the tags that can contain comments/indented text respectively.
var commentTags = "dd,li,p";
var indentTags = "dl,ol,ul";
if(!HighlightCommentsJsWrapped) {
// Do the work, adding span wrappers
jQuery("a[title=\"" + (wgFormattedNamespaces[2] + ":" +
wgUserName).replace(/"/g, "\\\"") + "\"]").closest(commentTags).
contents().not(indentTags).
wrap(jQuery("<span class=\"mycomment\"/>"));
// Set the flag that wrapping is done
HighlightCommentsJsWrapped = true;
} else {
// Just change the classes
jQuery(".mycomment-off").removeClass("mycomment-off").
addClass("mycomment");
}
var ns = HighlightCommentsJsSwitch.nextSibling;
HighlightCommentsJsSwitch.parentNode.removeChild(HighlightCommentsJsSwitch);
HighlightCommentsJsSwitch = addPortletLink("p-cactions",
"javascript:HighlightCommentsJsUnhighlight()", "Unhighlight",
"ca-highlightcomments",
"Enable highlighting of your own comments on this page", null, ns);
};
HighlightCommentsJsUnhighlight = function(){
// Change the classes
jQuery(".mycomment").removeClass("mycomment").addClass("mycomment-off");
var ns = HighlightCommentsJsSwitch.nextSibling;
HighlightCommentsJsSwitch.parentNode.removeChild(HighlightCommentsJsSwitch);
HighlightCommentsJsSwitch = addPortletLink("p-cactions",
"javascript:HighlightCommentsJsHighlight()", "Highlight",
"ca-highlightcomments",
"Disable highlighting of your own comments on this page", null, ns);
};
function HighlightCommentsJsLoaded() {
var desc;
if(typeof HighlightCommentsJsDescription == "undefined") {
// Default toolbox link text
desc = "Toggle comment highlighting";
} else {
// User-defined toolbox link text
desc = HighlightCommentsJsDescription;
}
// Create and add the menu item or tab
HighlightCommentsJsSwitch = addPortletLink("p-cactions",
"javascript:HighlightCommentsJsHighlight()", "Highlight",
"ca-highlightcomments",
"Enable highlighting of your own comments on this page");
}
function HighlightCommentsJsWaitForJquery() {
// We use globals since in Internet Explorer, we cannot pass
// function arguments through setTimeout.
if(typeof jQuery == "undefined" && HighlightCommentsJsTries) {
HighlightCommentsJsTries--;
return window.setTimeout(HighlightCommentsJsWaitForJquery, 250);
}
if(typeof jQuery == "function") {
HighlightCommentsJsLoaded();
return true;
}
return false;
}
// Monobook skin, unlike the newer Vector skin, doesn't load jQuery :(
if(typeof jQuery == "undefined") {
importScriptURI("http://bits.wikimedia.org/skins-1.5/common/jquery.min.js");
}
hookEvent("load", HighlightCommentsJsWaitForJquery);
//</nowiki></pre>