User:Elli/common.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
The accompanying .css page for this skin can be added at User:Elli/common.css. |
// Enable caching for resource loads, see [[User:SD0001/Making_user_scripts_load_faster]]
function loadResource(page, sitename, ctype) {
return $.get(
'https://' + sitename + '/w/api.php?titles=' + encodeURIComponent(page) +
'&origin=*&format=json&formatversion=2&uselang=content&maxage=86400&smaxage=86400' +
'&action=query&prop=revisions|info&rvprop=content&rvlimit=1'
).then(function(apiResponse) {
var apiPage = apiResponse.query.pages[0];
if (apiPage.missing) return;
var content = apiPage.revisions[0].content;
if ((!ctype || ctype === 'text/javascript') && apiPage.contentmodel === 'javascript') {
eval(content); // jshint ignore:line
} else if (ctype === 'text/css' && apiPage.contentmodel === 'css') {
mw.loader.addStyleTag(content);
} else {
return $.Deferred().reject('Refused to load "' + page + '"@' + sitename + ': content type mismatch');
}
});
}
window.importScript = function(page) {
loadResource(page, mw.config.get('wgServerName'), 'text/javascript');
};
window.importStyleSheet = function(page) {
loadResource(page, mw.config.get('wgServerName'), 'text/css');
};
function getSiteTitle(url) {
var siteRgx = /^(?:(?:https:)?\/\/(.*))?\/w\/index.php/.exec(url),
titleRgx = /\btitle=([^=?&]*)/.exec(url);
if (siteRgx && titleRgx && /\baction=raw\b/.test(url) && /\bctype=/.test(url)) {
return [titleRgx[1], siteRgx[1] || mw.config.get('wgServerName')];
} else return null;
}
var oldMwLoaderLoad = mw.loader.load;
var oldMwLoaderGetScript = mw.loader.getScript;
mw.loader.load = function(url, type) {
var linkParts = getSiteTitle(url);
if (linkParts) {
loadResource(linkParts[0], linkParts[1], type);
} else {
oldMwLoaderLoad.apply(mw.loader, Array.prototype.slice.call(arguments));
}
};
mw.loader.getScript = function(url) {
var linkParts = getSiteTitle(url);
if (linkParts) {
return loadResource(linkParts[0], linkParts[1], 'text/javascript');
} else {
return oldMwLoaderGetScript.apply(mw.loader, Array.prototype.slice.call(arguments));
}
};
window.AjaxDeleteExtraButtons = [
{
'label': 'Speedy Selfie/F10',
'tag': '{'+'{SD|F10}}',
'img_summary': 'Requesting speedy deletion: [[COM:CSD#F10|CSD F10]] (personal photos by non-contributors)',
'talk_tag': '{'+'{subst:speedynote|1=%FILE%|2=[[COM:CSD#F10|CSD F10]] (personal photos by non-contributors)}}',
'talk_summary': 'Notification of possible speedy deletion for %FILE% due to [[COM:CSD#F10|CSD F10]] (personal photos by non-contributors)',
}, {
'label': 'Speedy Advert/G10',
'tag': '{'+'{SD|G10}}',
'img_summary': 'Requesting speedy deletion: [[COM:CSD#G10|CSD G10]] (files and pages created as advertisements)',
'talk_tag': '{'+'{subst:speedynote|1=%FILE%|2=[[COM:CSD#G10|CSD G10]] (files and pages created as advertisements)}}',
'talk_summary': 'Notification of possible speedy deletion for %FILE% due to [[COM:CSD#G10|CSD G10]] (files and pages created as advertisements)',
}, {
'label': 'Dupe',
'tag': '{' + '{duplicate|1=%PARAMETER%|user=%USER%}}',
'img_summary': 'Tagging as duplicate of [[%PARAMETER%]]',
'prompt_text': 'Which file is this a duplicate of?',
'optin_notify': 1
}, {
'label': 'Speedy Test/G1',
'tag': '{' + '{SD|1=G1}}',
'img_summary': 'Requesting speedy deletion: [[COM:CSD#G1|CSD G1]] (test page, accidental creation, or page containing nonsense or no valid content)',
'talk_tag': '{'+'{subst:speedynote|1=%FILE%|2=[[COM:CSD#G1|CSD G1]] (files and pages created as tests)}}',
'talk_summary': 'Notification of possible speedy deletion for %FILE% due to [[COM:CSD#G1|CSD G1]] (files and pages created as tests)',
},
];
// for more see [[Help:QuickDelete]]
importScript('User:Elli/userinfo.js');
importScript('User:Perhelion/massrename.js');
importScript('User:Elli/massRollback.js');