User:Manishearth/Scripts/Snippets: Difference between revisions

Content deleted Content added
No edit summary
m Replaced deprecated <source> tags with <syntaxhighlight>
 
(4 intermediate revisions by 2 users not shown)
Line 6:
Adds an extra search bar to the page, and a portlet of links, which scroll with you.
Links and Searchbox are minimizable. The third button next to the searchbox opens the page in a new tab.
<sourcesyntaxhighlight lang=javascript>
//toggletoggleM() to toggle an elements display attribute
function toggletoggleM(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
Line 19:
//Floating faithful search bar
addOnloadHook(function(){
document.getElementById("bodyContentmw-page-base").innerHTML+='<div id="p-search" style="display:inline;position:fixed;top:295px;left:0px;z-index:2"><div id="notifications"></div><span id="floatcont"><span><a onclick="toggletoggleM(\'xtrasearch\');this.innerHTML=(this.innerHTML==\'+\')?\'-\':\'+\';" style="cursor:pointer">-</a></span><span id="xtrasearch"><form action="/w/index.php" id="searchform2"><input type="hidden" name="title" value="Special:Search"><input type="submit" name="go" class="searchButton" id="searchGoButton" value="Go" title="Go to a page with this exact name if one exists"><input type="submit" name="fulltext" class="searchButton" id="mw-searchButton" value="Search" title="Search Wikipedia for this text"><button type="button" ONCLICK="window.open(mw.config.get("wgServer")+\'/wiki/\'+document.getElementById(\'searchInput2\').value)"><img src="http://bits.wikimedia.org/skins-1.5/common/images/magnify-clip.png"> </button><BR><input id="searchInput2" name="search" type="text" title="Search Wikipedia" value="" autocomplete="off" size=1910></form></span></span></div>';
document.getElementById("searchInput2").onkeyup=function (){document.getElementById("searchInput2Suggest").style.position="fixed"}
//And some nice little links
document.getElementById('floatcont').innerHTML+='<div id="p-personal2"><span><a onclick="toggletoggleM(\'xtraportlet\');this.innerHTML=(this.innerHTML==\'+\')?\'-\':\'+\';" style="cursor:pointer">+</a></span><ul lang="en" xml:lang="en" id="xtraportlet" style="display:none"></ul></div>'
addPortletLink("p-personal2",mw.config.get('wgServer')+"/wiki/Special:OldReviewedPages","Pending Changes");
addPortletLink("p-personal2",mw.config.get('wgServer')+"/wiki/Special:Watchlist","Watchlist");
addPortletLink("p-personal2",mw.config.get('wgServer')+"/wiki/User:"+mw.config.get('wgUserName'),mw.config.get('wgUserName'));
addPortletLink("p-personal2",mw.config.get('wgServer')+"/wiki/User_talk:"+mw.config.get('wgUserName'),"Talk");
addPortletLink("p-personal2",mw.config.get('wgServer')+"/wiki/Special:Preferences","Preferences");
addPortletLink("p-personal2",mw.config.get('wgServer')+"/wiki/Special:Contributions/"+mw.config.get('wgUserName'),"My contribs");
});
</syntaxhighlight>
</source>
One bug (minor) If you have already scrolled down, the first letter typed into the box will cause the suggestion menu to pop up elsewhere, but this is fixed by typing another letter.
Here is an add-on, to be put directly under above script. It allows you to add little notifications with an addNotification() method. Its argiments are:
Line 40:
*title-- The alt-text to show
The script adds a notification when you have new messages.
<sourcesyntaxhighlight lang=javascript>
function addNotification(link, image,title){
var src;
Line 62:
 
if(document.getElementById('mw-youhavenewmessages')){
addNotification("http://en.wikipedia.org/wiki/User_talk:"+mw.config.get('wgUserName'),"exclamation","You have new messages");
}
</syntaxhighlight>
</source>
 
==FlexiDiff==
<sourcesyntaxhighlight lang=javascript>
function getID(){
if(document.getElementById('t-permalink')){
Line 88:
}
)
</syntaxhighlight>
</source>
Add it to [[Special:Mypage/monobook.js|your monobook js page]] (go to vector.js if you use beta) and purge your cache. You'll get two new tabs (or links in your chosen portlet if you change the diffPortlet variable). In beta, the tabs will be hidden under a little down arrow next to the history tab and 'watch this page' star.<br />
To get a diff, first open the page you want on the left of the diff, and click ID. Copy the ID, and open the page you want on the right. Click the FlexDiff button (It should be right next to/under the ID tab), and it will ask for the ID that you copied. Paste it and click OK. The diff will open in the same window (no need for a new window as the script doesn't work on edit pages).