User:Manishearth/Scripts/Snippets: Difference between revisions

Content deleted Content added
No edit summary
m Replaced deprecated <source> tags with <syntaxhighlight>
 
(13 intermediate revisions by 2 users not shown)
Line 1:
This page contains snippets which are not worthy to become scripts but are sometimes useful.<br />
Usually these are scripts which I made in response to a request at [[WP:VPT]] or [[WP:US/R]]. They don't take much time to make but are sometimes useful.
If you think that a snippet should be promoted to a script (with its own page, documentation, etc), please post an RfS (Request for ScriptShip :P) on my talk page.
==Extra floating search bar==
Adds an extra search bar to the page, which scrolls with you.
<source lang=javascript>
addOnloadHook(function(){
document.getElementById((skin=="vector")?"panel":"content").innerHTML+='<div id="p-search" style="display:block;position:fixed;top:295px;left:0px;z-index:2"><span id="floatcont"><span><a onclick="toggle(\'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(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=19></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="toggle(\'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",wgServer+"/wiki/User:"+wgUserName,wgUserName);
addPortletLink("p-personal2",wgServer+"/wiki/User_talk:"+wgUserName,"Talk");
addPortletLink("p-personal2",wgServer+"/wiki/Special:Watchlist","Watchlist");
addPortletLink("p-personal2",wgServer+"/wiki/Special:Preferences","Preferences");
addPortletLink("p-personal2",wgServer+"/wiki/Special:Contributions/"+wgUserName,"My contribs");
addPortletLink("p-personal2",wgServer+"/wiki/User:Manishearth/Mylinks","My links");
});
 
==Extra floating search bar==
function toggle(obj) {
Adds an extra search bar to the page, and a portlet of links, which scrollsscroll with you.
Links and Searchbox are minimizable. The third button next to the searchbox opens the page in a new tab.
<sourcesyntaxhighlight lang=javascript>
//toggleM() to toggle an elements display attribute
function toggletoggleM(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
Line 27 ⟶ 17:
}
}
//Floating faithful search bar
</source>
addOnloadHook(function(){
document.getElementById((skin=="vector")?"panel":"contentmw-page-base").innerHTML+='<div id="p-search" style="display:blockinline;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/UserSpecial:Manishearth/MylinksOldReviewedPages","MyPending linksChanges");
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>
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:
*link-- What to link to (whole url, please)
*image-- The url of the image to display. If this param is 'info', 'exclamation', or 'stophand', it will show the standard wikipedia notification images (The ones from the vandalism templates.)
*title-- The alt-text to show
The script adds a notification when you have new messages.
<syntaxhighlight lang=javascript>
function addNotification(link, image,title){
var src;
switch(image){
case 'exclamation':
src='http://upload.wikimedia.org/wikipedia/commons/thumb/f/f7/Nuvola_apps_important.svg/25px-Nuvola_apps_important.svg.png';
break;
case 'stophand':
src='http://upload.wikimedia.org/wikipedia/en/thumb/f/f1/Stop_hand_nuvola.svg/30px-Stop_hand_nuvola.svg.png';
break;
case 'info':
src='http://upload.wikimedia.org/wikipedia/commons/thumb/2/28/Information.svg/25px-Information.svg.png';
break;
default:
src=image;
}
document.getElementById('notifications').innerHTML+='<a href="'+link+'"><img src="'+src+'" title="'+title+'"/></a>'
}
 
if(document.getElementById('mw-youhavenewmessages')){
addNotification("http://en.wikipedia.org/wiki/User_talk:"+mw.config.get('wgUserName'),"exclamation","You have new messages");
}
</syntaxhighlight>
 
==FlexiDiff==
<sourcesyntaxhighlight lang=javascript>
function getID(){
if(document.getElementById('t-permalink')){
Line 52 ⟶ 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).