User:Novem Linguae/Scripts/VisualEditorEverywhere.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. |
![]() | This user script seems to have a documentation page at User:Novem Linguae/Scripts/VisualEditorEverywhere. |
//<nowiki>
/*
PURPOSE:
- Displays the Visual Editor "Edit" tab and "Edit" section link in Talk, Wikipedia, and Template namespaces.
TO INSTALL:
- Copy paste the below into your User:YourUserName/common.js file
importScript('User:Novem Linguae/Scripts/VisualEditorEverywhere.js'); // Backlink: [[User:Novem Linguae/Scripts/VisualEditorEverywhere.js]]
TEST PAGES:
- Regular page - https://en.wikipedia.org/wiki/Lauren_Chamberlain
- Wikipedia namespace - https://en.wikipedia.org/wiki/Wikipedia:Notability
- Wikipedia namespace, fully protected - https://en.wikipedia.org/wiki/Wikipedia:Wiki_Ed/tour/example_bio_template
- Template namespace - https://en.wikipedia.org/wiki/Template:Noticeboard_links
- Template talk namespace (good for testing section links) - https://en.wikipedia.org/wiki/Template_talk:Noticeboard_links
TODO:
- restore the section [ edit | ] link as well
*/
if( jQuery !== undefined && mediaWiki !== undefined ) {
let currNamespace = mw.config.get('wgNamespaceNumber');
let articleName = mw.config.get('wgPageName');
let buttonIsPresent = $('#ca-ve-edit').length;
// let namespaceNeedsButton = ( currNamespace == 4 || currNamespace == 5 || currNamespace == 10 || currNamespace == 11 || currNamespace == 3 );
console.log('currNamespace: ' + currNamespace);
let blacklistedNamespaces = [-2, -1, 6]; // media, special, file
let blacklistedNamespace = blacklistedNamespaces.includes(currNamespace);
if ( ! buttonIsPresent && ! blacklistedNamespace ) {
// Insert Edit tab at top of page
let htmlToInsert = '<li id="ca-ve-edit" class="collapsible"><a href="/w/index.php?title='+articleName+'&veaction=edit" title="Edit this page [alt-shift-v]" accesskey="v">Edit</a></li>';
$('#ca-edit').before(htmlToInsert);
$('#ca-ve-edit').show();
// Insert [ edit ] by each section
$('.mw-editsection').each(function(i, obj) {
htmlToInsert = '<a href="/w/index.php?title='+articleName+'&veaction=edit&section='+(i+1)+'" class="mw-editsection-visualeditor">edit</a> <span class="mw-editsection-divider"> | </span>';
$('.mw-editsection').eq(i).children('span:first-of-type').after(htmlToInsert); // Inline tags such as <span> do not work with :nth-child, .before(), etc. Must use :first-of-type.
});
$('.mw-editsection-visualeditor, .mw-editsection-divider').show();
}
}
//</nowiki>