User:Erutuon/scripts/editTop.js
< User:Erutuon | scripts
Note – after saving, you may have to bypass your browser’s cache to see the changes.
- Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
- Konqueror and Chrome: click Reload or press F5;
- Opera: clear the cache in Tools → Preferences;
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.
- This script lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • redirects • your own
// From [[w:MediaWiki:Gadget-edittop.js]], with some modifications
var namespaceNumber = mw.config.get( "wgNamespaceNumber" );
var pageName = mw.config.get( "wgPageName" );
if ( [ "view", "purge" ].indexOf( mw.config.get( "wgAction" ) ) !== -1
&& [ 0, 1, 2, 3, 4, 5, 10, 100 ].indexOf( mw.config.get( "wgNamespaceNumber" ) ) !== -1 ) {
$(function edittop_hook () {
var localtitles = {
en: "Edit lead section",
};
var our_content = $("#content, #mw_content").first();
var span1 = our_content
.find("span.mw-editsection:not(.plainlinks):not(.anchor-gadget-link)")
.first();
if (!span1.length) {
return;
}
var span0 = span1.clone().prop("contenteditable", "false");
$("#mw_header h1, #content h1").first().append(span0);
span0.find("a").each(function (idx) {
var a = $(this);
a.attr("title", localtitles.en);
var href = a.attr( "href" );
if (!href)
return;
a.attr("href",
// not transcluded
!/&(ve|)section=T/.test( href ) ? href.replace( /&(ve|)section=\d+/, "&$1section=0&summary=/*%20top%20*/%20" )
// transcluded, VE
: /&vesection=/.test( href ) ? mw.util.getUrl( pageName, { veaction: "edit", vesection: 0, summary: "/* top */ " } )
: mw.util.getUrl( pageName, { action: "edit", section: "0", summary: "/* top */ " } ) );
});
});
}