User:Sverdrup/monobook.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. |
![]() | The accompanying .css page for this skin is at User:Sverdrup/monobook.css. |
// Live Preview customization,
// edit this to your own liking.
wpUserName = 'Sverdrup'; // User name to display in signatures
wpShowImages = true; // Enable downloading and displaying of images
// Include Live Preview...
document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Pilaf/livepreview.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
// Now set everything up
window.onload = Main;
function Main()
{
LivePreviewInstall();
// You may include here other "extensions"
replaceGoogle();
smileys();
}
/* This is to keep track of who is using the Live Preview: [[User:Pilaf/livepreview.js]] */
// -- end Live Preview
// Google search code
function replaceGoogle() {
var googlePlaceholder = document.getElementById('google-search');
googlePlaceholder.innerHTML = '<form method="GET" action="http://www.google.com/search"> <input type="hidden" name="ie" value="UTF-8"> <input type="hidden" name="oe" value="UTF-8"> <table bgcolor="#FFFFFF"><tr><td> <a href="http://www.google.com/"> <img src="http://www.google.com/logos/Logo_40wht.gif" border="0" alt="Google" align="absmiddle"></a> <input type="text" name="q" size="25" maxlength="255" value=""> <input type="submit" name="btnG" value="Google Search"> </td></tr></table> </form>';
}
/* Top edit link */
function editTopLink() {
// if this is preview page or generated page, stop
if(document.getElementById("wikiPreview") || self.location.pathname.indexOf("Special:") !== -1 || self.location.search.indexOf("title=Special") !== -1) return;
// get the page title
var pageTitle = document.title.split(" - ")[0].replace(" ", "_");
// create div and set innerHTML to link
var divContainer = document.createElement("div");
divContainer.innerHTML = '<div class="editsection" style="float:right;margin-left:5px;margin-top:3px;">[<a href="/w/index.php?title='+pageTitle+'&action=edit§ion=0" title="'+document.title.split(" - ")[0]+'">edit top</a>]</div>';
// this is a hack so I can refer to the h1 by an id
document.getElementsByTagName("h1")[0].id = "f1r5tH34d1ng";
var theH1 = document.getElementById("f1r5tH34d1ng");
// insert divContainer into the DOM before the h1
document.getElementById("content").insertBefore(divContainer, theH1);
}
// setTimeout does not need a string reference to work
setTimeout(editTopLink, 0) // this is equivalent of onload
// crazy code
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag)
{
// the highlightStartTag and highlightEndTag parameters are optional
if ((!highlightStartTag) || (!highlightEndTag)) {
highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
highlightEndTag = "</font>";
}
// find all occurences of the search term in the given text,
// and add some "highlight" tags to them (we're not using a
// regular expression search, because we want to filter out
// matches that occur within HTML tags and script blocks, so
// we have to do a little extra validation)
var newText = "";
var i = -1;
var lcSearchTerm = searchTerm.toLowerCase();
var lcBodyText = bodyText.toLowerCase();
while (bodyText.length > 0) {
i = lcBodyText.indexOf(lcSearchTerm, i+1);
if (i < 0) {
newText += bodyText;
bodyText = "";
} else {
// skip anything inside an HTML tag
if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
// skip anything inside a <script> block
if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
bodyText = bodyText.substr(i + searchTerm.length);
lcBodyText = bodyText.toLowerCase();
i = -1;
}
}
}
}
return newText;
}
function doReplace(bodyText, searchTerm, insertText)
{
// find all occurences of the search term in the given text,
// and add some "highlight" tags to them (we're not using a
// regular expression search, because we want to filter out
// matches that occur within HTML tags and script blocks, so
// we have to do a little extra validation)
var newText = "";
var i = -1;
var lcSearchTerm = searchTerm.toLowerCase();
var lcBodyText = bodyText.toLowerCase();
while (bodyText.length > 0) {
i = lcBodyText.indexOf(lcSearchTerm, i+1);
if (i < 0) {
newText += bodyText;
bodyText = "";
} else {
// skip anything inside an HTML tag
if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
// skip anything inside a <script> block
if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
newText += bodyText.substring(0, i) + insertText;
bodyText = bodyText.substr(i + searchTerm.length);
lcBodyText = bodyText.toLowerCase();
i = -1;
} else if (lcBodyText.lastIndexOf("/form>", i) >= lcBodyText.lastIndexOf("<form", i)) {
newText += bodyText.substring(0, i) + insertText;
bodyText = bodyText.substr(i + searchTerm.length);
lcBodyText = bodyText.toLowerCase();
i = -1;
}
}
}
}
return newText;
}
function smileys() {
var body = document.getElementById("bodyContent");
var editform = document.getElementById("editform");
var edittext = editform.innerHTML;
var newText = body.innerHTML;
// :)
newText = doReplace(newText, ":)", "<img src='/media/wikipedia/commons/2/26/Smile.png' alt-text=':)' title=':)'>");
newText = doReplace(newText, ":-)", "<img src='/media/wikipedia/commons/2/26/Smile.png' alt-text=':-)' title=':-)'>");
// ;)
newText = doReplace(newText, ";)", "<img src='/media/wikipedia/commons/9/94/Smile_eye.png' alt-text=';)' title=';)'>");
newText = doReplace(newText, ";-)", "<img src='/media/wikipedia/commons/9/94/Smile_eye.png' alt-text=';)' title=';)'>");
// :D
newText = doReplace(newText, ":D", "<img src='/media/wikipedia/commons/7/72/Teeth.png' alt-text=':D' title=':D'>");
newText = doReplace(newText, ":-D", "<img src='/media/wikipedia/commons/7/72/Teeth.png' alt-text=':D' title=':D'>");
body.innerHTML = newText;
editform = document.getElementById("editform");
editform.innerHTML = edittext;
}