User:Phlip/cologneblue.js
From Homestar Runner Wiki
< User:Phlip(Difference between revisions)
m (%2F is bad too) |
|||
| (includes 20 intermediate revisions) | |||
| Line 1: | Line 1: | ||
| - | + | // Automatically clean up links without titles from #HRWiki-RC for great copy/paste justice | |
| + | if (document.location.pathname == "/w/index.php" && document.location.search.indexOf("title=") < 0) | ||
{ | { | ||
| - | + | newsearch = "?title=" + encodeURIComponent(wgPageName).replace("%3A",":").replace("%2F","/"); | |
| - | + | if (document.location.search) | |
| - | + | newsearch += "&" + document.location.search.substring(1); | |
| - | + | document.location.search = newsearch | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
} | } | ||
| + | |||
| + | // include utility functions | ||
| + | document.write('<script type="text/javascript" src="/index.php?title=User:Phlip/utilities.js&action=raw&ctype=text/javascript&dontcountme=s"></script>'); | ||
function dostuff() | function dostuff() | ||
{ | { | ||
| - | + | with (utilities) | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
{ | { | ||
| - | if ( | + | if (cologneBlueNewMessages()) |
{ | { | ||
| - | + | var div = document.createElement("div") | |
| - | + | div.className = "newmessagesbox"; // intentionally not "usermessages" - take that, fake message boxes! | |
| - | + | div.appendChild(document.createTextNode("You have ")); | |
| - | + | var a = document.createElement("a") | |
| + | a.href = localurl("Phlip", 3); | ||
| + | a.appendChild(document.createTextNode("new messages")); | ||
| + | div.appendChild(a); | ||
| + | div.appendChild(document.createTextNode(" (")); | ||
| + | a = document.createElement("a") | ||
| + | a.href = localurl("Phlip", 3, "diff=cur"); | ||
| + | a.appendChild(document.createTextNode("diff")); | ||
| + | div.appendChild(a); | ||
| + | div.appendChild(document.createTextNode(") (")); | ||
| + | a = document.createElement("a") | ||
| + | a.href = localurl("Phlip", 3, "action=history"); | ||
| + | a.appendChild(document.createTextNode("history")); | ||
| + | div.appendChild(a); | ||
| + | div.appendChild(document.createTextNode(").")); | ||
| + | |||
| + | var article = document.getElementById('article'); | ||
| + | article.insertBefore(div, article.firstChild); | ||
} | } | ||
| - | |||
| - | + | if (getArticleNamespace() == 2 || getArticleNamespace() == 3) | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
{ | { | ||
| - | + | var username = getArticleTitle(); | |
| - | + | var i = username.indexOf('/') | |
| - | + | if (i >= 0) | |
| + | username = username.substr(0, i); | ||
| + | var link = addCologneBlueQuickbarLink(localurl(username, 2), username, "Context"); | ||
| + | if (link) | ||
| + | link.parentNode.insertBefore(document.createElement('hr'), link); | ||
| + | addCologneBlueQuickbarLink(localurl(username, 3), username + " talk", "Context"); | ||
| + | addCologneBlueQuickbarLink(localurl("Contributions/" + username, -1), "Contribs", "Context"); | ||
| + | addCologneBlueQuickbarLink(localurl("Log", -1, "user=" + username), "Show Logs (user)", "Context"); | ||
| + | addCologneBlueQuickbarLink(localurl("Log", -1, "page=User:" + username), "Show Logs (target)", "Context"); | ||
| + | addCologneBlueQuickbarLink(localurl("Countedits/" + username, -1), "Count edits", "Context"); | ||
} | } | ||
| - | + | addCologneBlueQuickbarLink("http://www.homestarrunner.com/", "H*R", "External"); | |
| + | addCologneBlueQuickbarLink("http://validator.w3.org/check?uri=" + encodeURIComponent(getArticleURL()), "Validate", "External"); | ||
| + | |||
| + | var ns = getArticleNamespace(); | ||
| + | var t = getArticleTitle(); | ||
| + | if (talknamespace[ns]) | ||
{ | { | ||
| - | + | var talklink = addCologneBlueSubtopbarLink(localurl(t, talknamespace [ns]), namespacedescription[talknamespace [ns]], true); | |
| - | + | if (talknamespace[ns] == ns) | |
| - | + | talklink.style.fontWeight = "bold"; | |
} | } | ||
| - | + | var pagelink = addCologneBlueSubtopbarLink(localurl(t, articlenamespace[ns]), namespacedescription[articlenamespace[ns]], true); | |
| - | + | if (articlenamespace[ns] == ns) | |
| - | + | pagelink.style.fontWeight = "bold"; | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | // highlight IP addresses (eg in Recent Changes) | |
| - | + | links = document.getElementsByTagName("a"); | |
| - | + | regex = /Special:Contributions(\/|&target=)[\d.]+$/; | |
| - | + | for (i = 0; i < links.length; i++) | |
| - | + | if (regex.test(links[i].href)) | |
| - | + | links[i].className += " ipcontribs"; | |
| - | + | // copy the serve time comment into visibility | |
| - | + | var a = document.body.lastChild; | |
| - | + | while (a && a.nodeType != a.COMMENT_NODE) | |
| - | + | a = a.previousSibling; | |
| - | + | if (a.nodeType == a.COMMENT_NODE) | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
{ | { | ||
| - | + | var div = document.createElement("div"); | |
| - | + | div.appendChild(document.createTextNode("<!--" + a.nodeValue + "-->")); | |
| - | + | div.className = "servetime"; | |
| - | + | document.body.appendChild(div); | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
} | } | ||
} | } | ||
| - | + | a = document.getElementsByTagName("a") | |
| - | + | regex = /http:\/\/(www\.)?homestarrunner\.com\/(.*)/; | |
| - | ///// | + | for (i = 0; i < a.length; i++) |
| - | + | ||
| - | + | ||
| - | + | ||
{ | { | ||
| - | + | matches = a[i].href.match(regex); | |
| - | + | if (matches) a[i].href = "http://localhost/hr/" + matches[2]; | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | if ( | + | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
} | } | ||
| - | + | wpPreview = document.getElementById('wpPreview'); | |
| - | + | if (wpPreview) | |
| - | + | ||
| - | + | ||
{ | { | ||
| + | previewinmonobook = document.createElement('button'); | ||
| + | previewinmonobook.textContent = "Preview in Monobook"; | ||
| + | wpPreview.parentNode.insertBefore(previewinmonobook,wpPreview.nextSibling); | ||
| + | wpPreview.parentNode.insertBefore(document.createTextNode(' '),wpPreview.nextSibling); | ||
| + | previewinmonobook.addEventListener('click', function(){ | ||
| + | useskin = document.createElement('input'); | ||
| + | useskin.name='useskin'; | ||
| + | useskin.type='hidden'; | ||
| + | useskin.value='monobook'; | ||
| + | wpPreview.parentNode.appendChild(useskin); | ||
| + | wpPreview.click(); | ||
| + | },false); | ||
} | } | ||
} | } | ||
| - | |||
// these two lines stolen from [[User:Tom/monobook.js]] | // these two lines stolen from [[User:Tom/monobook.js]] | ||
if (window.addEventListener) window.addEventListener("load",dostuff,false); | if (window.addEventListener) window.addEventListener("load",dostuff,false); | ||
else if (window.attachEvent) window.attachEvent("onload",dostuff); | else if (window.attachEvent) window.attachEvent("onload",dostuff); | ||
| + | |||
| + | mwCustomEditButtons = [ | ||
| + | { | ||
| + | imageId: "mw-editbutton-test", | ||
| + | imageFile: "http://forum.hrwiki.org/images/smilies/emofrown.gif", | ||
| + | speedTip: "Adds test notice", | ||
| + | tagOpen: "{"+"{subst:test|subst=subst:|diff1=[", | ||
| + | tagClose: "]}"+"} ~~"+"~~", | ||
| + | sampleText: "" | ||
| + | }, | ||
| + | { | ||
| + | imageId: "mw-editbutton-blockwarning", | ||
| + | imageFile: "http://forum.hrwiki.org/images/smilies/emomad.gif", | ||
| + | speedTip: "Adds block warning", | ||
| + | tagOpen: "{"+"{subst:blockwarning|subst=subst:}"+"} ~~"+"~~", | ||
| + | tagClose: "", | ||
| + | sampleText: "" | ||
| + | } | ||
| + | ]; | ||
Current revision as of 16:05, 20 June 2009
// Automatically clean up links without titles from #HRWiki-RC for great copy/paste justice
if (document.location.pathname == "/w/index.php" && document.location.search.indexOf("title=") < 0)
{
newsearch = "?title=" + encodeURIComponent(wgPageName).replace("%3A",":").replace("%2F","/");
if (document.location.search)
newsearch += "&" + document.location.search.substring(1);
document.location.search = newsearch
}
// include utility functions
document.write('<script type="text/javascript" src="/index.php?title=User:Phlip/utilities.js&action=raw&ctype=text/javascript&dontcountme=s"></script>');
function dostuff()
{
with (utilities)
{
if (cologneBlueNewMessages())
{
var div = document.createElement("div")
div.className = "newmessagesbox"; // intentionally not "usermessages" - take that, fake message boxes!
div.appendChild(document.createTextNode("You have "));
var a = document.createElement("a")
a.href = localurl("Phlip", 3);
a.appendChild(document.createTextNode("new messages"));
div.appendChild(a);
div.appendChild(document.createTextNode(" ("));
a = document.createElement("a")
a.href = localurl("Phlip", 3, "diff=cur");
a.appendChild(document.createTextNode("diff"));
div.appendChild(a);
div.appendChild(document.createTextNode(") ("));
a = document.createElement("a")
a.href = localurl("Phlip", 3, "action=history");
a.appendChild(document.createTextNode("history"));
div.appendChild(a);
div.appendChild(document.createTextNode(")."));
var article = document.getElementById('article');
article.insertBefore(div, article.firstChild);
}
if (getArticleNamespace() == 2 || getArticleNamespace() == 3)
{
var username = getArticleTitle();
var i = username.indexOf('/')
if (i >= 0)
username = username.substr(0, i);
var link = addCologneBlueQuickbarLink(localurl(username, 2), username, "Context");
if (link)
link.parentNode.insertBefore(document.createElement('hr'), link);
addCologneBlueQuickbarLink(localurl(username, 3), username + " talk", "Context");
addCologneBlueQuickbarLink(localurl("Contributions/" + username, -1), "Contribs", "Context");
addCologneBlueQuickbarLink(localurl("Log", -1, "user=" + username), "Show Logs (user)", "Context");
addCologneBlueQuickbarLink(localurl("Log", -1, "page=User:" + username), "Show Logs (target)", "Context");
addCologneBlueQuickbarLink(localurl("Countedits/" + username, -1), "Count edits", "Context");
}
addCologneBlueQuickbarLink("http://www.homestarrunner.com/", "H*R", "External");
addCologneBlueQuickbarLink("http://validator.w3.org/check?uri=" + encodeURIComponent(getArticleURL()), "Validate", "External");
var ns = getArticleNamespace();
var t = getArticleTitle();
if (talknamespace[ns])
{
var talklink = addCologneBlueSubtopbarLink(localurl(t, talknamespace [ns]), namespacedescription[talknamespace [ns]], true);
if (talknamespace[ns] == ns)
talklink.style.fontWeight = "bold";
}
var pagelink = addCologneBlueSubtopbarLink(localurl(t, articlenamespace[ns]), namespacedescription[articlenamespace[ns]], true);
if (articlenamespace[ns] == ns)
pagelink.style.fontWeight = "bold";
// highlight IP addresses (eg in Recent Changes)
links = document.getElementsByTagName("a");
regex = /Special:Contributions(\/|&target=)[\d.]+$/;
for (i = 0; i < links.length; i++)
if (regex.test(links[i].href))
links[i].className += " ipcontribs";
// copy the serve time comment into visibility
var a = document.body.lastChild;
while (a && a.nodeType != a.COMMENT_NODE)
a = a.previousSibling;
if (a.nodeType == a.COMMENT_NODE)
{
var div = document.createElement("div");
div.appendChild(document.createTextNode("<!--" + a.nodeValue + "-->"));
div.className = "servetime";
document.body.appendChild(div);
}
}
a = document.getElementsByTagName("a")
regex = /http:\/\/(www\.)?homestarrunner\.com\/(.*)/;
for (i = 0; i < a.length; i++)
{
matches = a[i].href.match(regex);
if (matches) a[i].href = "http://localhost/hr/" + matches[2];
}
wpPreview = document.getElementById('wpPreview');
if (wpPreview)
{
previewinmonobook = document.createElement('button');
previewinmonobook.textContent = "Preview in Monobook";
wpPreview.parentNode.insertBefore(previewinmonobook,wpPreview.nextSibling);
wpPreview.parentNode.insertBefore(document.createTextNode(' '),wpPreview.nextSibling);
previewinmonobook.addEventListener('click', function(){
useskin = document.createElement('input');
useskin.name='useskin';
useskin.type='hidden';
useskin.value='monobook';
wpPreview.parentNode.appendChild(useskin);
wpPreview.click();
},false);
}
}
// these two lines stolen from [[User:Tom/monobook.js]]
if (window.addEventListener) window.addEventListener("load",dostuff,false);
else if (window.attachEvent) window.attachEvent("onload",dostuff);
mwCustomEditButtons = [
{
imageId: "mw-editbutton-test",
imageFile: "http://forum.hrwiki.org/images/smilies/emofrown.gif",
speedTip: "Adds test notice",
tagOpen: "{"+"{subst:test|subst=subst:|diff1=[",
tagClose: "]}"+"} ~~"+"~~",
sampleText: ""
},
{
imageId: "mw-editbutton-blockwarning",
imageFile: "http://forum.hrwiki.org/images/smilies/emomad.gif",
speedTip: "Adds block warning",
tagOpen: "{"+"{subst:blockwarning|subst=subst:}"+"} ~~"+"~~",
tagClose: "",
sampleText: ""
}
];
