User:Bosco-bot/common.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// JWB
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js&action=raw&ctype=text/javascript');
// MarkRights-zh
importScript('User:Bosco/MediaWiki:Gadget-MarkRights.js'); // Backlink: [[User:Bosco/MediaWiki:Gadget-MarkRights.js]]
// Mass block
mw.loader.load('//en.wikipedia.org/w/index.php?title=User:Timotheus_Canens/massblock.js&action=raw&ctype=text/javascript');
// AdvancedRollback
mw.loader.load('//dev.miraheze.org/w/index.php?title=User:PB2008/AdvancedRollback/auto.js&action=raw&ctype=text/javascript');
// Diffedit
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=User:Jon_Harald_Søby/diffedit.js&action=raw&ctype=text/javascript' );
// Edit count
(function(editCount) {
if (editCount !== null) mw.loader.addStyleTag('#pt-mycontris>a::after, .menu__item--userContributions>span>span::after, #mw-mf-page-left .menu__item--userContributions>span::after {content: " (' + editCount + ')"}')
})(mw.config.get('wgUserEditCount'));
//
/**
* MediaWiki JS helper: Add {{delete|reason}} template
* Adds a "Request deletion" tab to the page toolbar that prompts for a reason
* and inserts {{delete|reason}} at the top of the wikitext.
*/
mw.loader.using('mediawiki.util', function () {
// Add a new portlet link (tab) to the page
mw.util.addPortletLink(
'p-cactions', // actions menu
'#', // href
'Request deletion', // link text
'ca-delete', // id
'Requesting deletion' // tooltip
);
// Attach click handler
$('#ca-delete').on('click', function (e) {
e.preventDefault();
// Prompt user for reason
var reason = prompt('Enter reason for deletion:');
if (!reason) {
return; // cancelled
}
// Load the current page content
new mw.Api().get({
action: 'query',
prop: 'revisions',
rvprop: 'content',
titles: mw.config.get('wgPageName')
}).done(function (data) {
var pages = data.query.pages;
var pageId = Object.keys(pages)[0];
var content = pages[pageId].revisions[0]['*'];
// Prepend the delete template
var newContent = '{{delete|' + reason + '}}\n' + content;
// Save the page with fixed summary
new mw.Api().postWithToken('csrf', {
action: 'edit',
title: mw.config.get('wgPageName'),
text: newContent,
summary: 'Requesting deletion'
}).done(function () {
location.reload(); // reload to show template
}).fail(function (err) {
alert('Error saving page: ' + err);
});
});
});
});