User:Interstatefive/common.js
Appearance
(Redirected from User:InterstateFive/common.js)
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. |
The accompanying .css page for this skin can be added at User:Interstatefive/common.css. |
$(document).ready(function()
{
/*** Start editing here ***/
// When you want to end your break?
// no leading zeroes. (example: 9 - correct, 09 - incorrect)
var date = { year: 2023, month: 4, day: 15};
var time = { hours: 18, minutes: 30, seconds: 0 };
/*** Stop editing here ***/
var currentDate = new Date();
var enforcedBreakEnd = new Date(
date.year,date.month-1,date.day,time.hours,time.minutes,time.seconds);
if (currentDate <= enforcedBreakEnd)
{
alert("Enforced wikibreak until "+enforcedBreakEnd.toLocaleString()
+ "\n(now is "+currentDate.toLocaleString()+")\n\nBye!");
mw.loader.using(["mediawiki.api", "mediawiki.user"]).then(function ()
{
new mw.Api().post(
{
action: 'logout',
token: mw.user.tokens.get('csrfToken')
}).done(function (data)
{
location = "//" + location.host + "/w/index.php?title="
+ "Special:Userlogin&returnto=Main_Page";
}).fail(function ()
{
console.log("logout failed")
});
});
}
});
importScript('User:Jackmcbarn/editProtectedHelper.js'); // Linkback: [[User:Jackmcbarn/editProtectedHelper.js]]
window.editProtectedHelperReloadAfter = true;
function markBlocked( container ) {
var ipv6Regex = /^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i;
// Collect all the links in the page's content
var contentLinks = $( container ).find( 'a' );
var mbTooltip = window.mbTooltip || '; blocked ($1) by $2: $3 ($4 ago)';
// Get all aliases for user: & user_talk:
var userNS = [];
for ( var ns in mw.config.get( 'wgNamespaceIds' ) ) {
if ( mw.config.get( 'wgNamespaceIds' )[ns] == 2 || mw.config.get( 'wgNamespaceIds' )[ns] == 3 ) {
userNS.push( mw.util.escapeRegExp(ns.replace( /_/g, ' ' )) + ':' );
}
}
// Let wikis that are importing this gadget specify the local alias of Special:Contributions
if ( window.markblocked_contributions === undefined ) {
window.markblocked_contributions = 'Special:Contributions';
}
// RegExp for all titles that are User:| User_talk: | Special:Contributions/ (for userscripts)
var userTitleRX = new RegExp( '^(' + userNS.join( '|' ) + '|' + window.markblocked_contributions + '\\/)+([^\\/#]+)$', 'i' );
// RegExp for links
// articleRX also matches external links in order to support the noping template
var articleRX = new RegExp( mw.config.get( 'wgArticlePath' ).replace('$1', '') + '([^#]+)' );
var scriptRX = new RegExp( '^' + mw.config.get( 'wgScript' ) + '\\?title=([^#&]+)' );
var userLinks = {};
var user, url, ma, pgTitle;
// Find all "user" links and save them in userLinks : { 'users': [<link1>, <link2>, ...], 'user2': [<link3>, <link3>, ...], ... }
contentLinks.each( function( i, lnk ) {
if( $( lnk ).hasClass("mw-changeslist-date") || $( lnk ).parent("span").hasClass("mw-history-undo") || $(lnk).parent("span").hasClass("mw-rollback-link") )
{
return;
}
url = $( lnk ).attr( 'href' );
if ( !url ) {
return;
}
if ( ma = articleRX.exec( url ) ) {
pgTitle = ma[1];
} else if ( ma = scriptRX.exec( url ) ) {
pgTitle = ma[1];
} else {
return;
}
pgTitle = decodeURIComponent( pgTitle ).replace( /_/g, ' ' );
user = userTitleRX.exec( pgTitle );
if ( !user ) {
return;
}
user = user[2];
if( ipv6Regex.test(user) ) user = user.toUpperCase();
$( lnk ).addClass( 'userlink' );
if ( !userLinks[user] ) {
userLinks[user] = [];
}
userLinks[user].push (lnk );
} );
// Convert users into array
var users = [];
for ( var u in userLinks ) {
users.push( u );
}
if ( users.length === 0 ) {
return;
}
// API request
var serverTime, apiRequests = 0;
container.addClass( 'markblocked-loading' );
while ( users.length > 0 ) {
apiRequests++;
$.post(
mw.util.wikiScript( 'api' ) + '?format=json&action=query',
{
list: 'blocks',
bklimit: 100,
bkusers: users.splice( 0, 50 ).join( '|' ),
bkprop: 'user|by|timestamp|expiry|reason|restrictions'
// no need for 'id|flags'
},
markLinks
);
}
return; // the end
// Callback: receive data and mark links
function markLinks( resp, status, xhr ) {
serverTime = new Date( xhr.getResponseHeader('Date') );
var list, blk, tip, links, lnk;
if ( !resp || !( list = resp.query ) || !( list = list.blocks ) ) {
return;
}
for ( var i = 0; i < list.length; i++ ) {
blk = list[i];
var partial = blk.restrictions && !Array.isArray(blk.restrictions); //Partial block
if ( /^in/.test( blk.expiry ) ) {
clss = partial ? 'user-blocked-partial' : 'user-blocked-indef';
blTime = blk.expiry;
} else {
clss = partial ? 'user-blocked-partial' : 'user-blocked-temp';
blTime = inHours ( parseTS( blk.expiry ) - parseTS( blk.timestamp ) );
}
tip = mbTooltip;
if (partial) {
tip = tip.replace( 'blocked', 'partially blocked' );
}
tip = tip.replace( '$1', blTime )
.replace( '$2', blk.by )
.replace( '$3', blk.reason )
.replace( '$4', inHours ( serverTime - parseTS( blk.timestamp ) ) );
links = userLinks[blk.user];
for ( var k = 0; links && k < links.length; k++ ) {
lnk = $( links[k] );
lnk = lnk.addClass( clss );
if ( window.mbTipBox ) {
$( '<span class=user-blocked-tipbox>#</span>' ).attr( 'title', tip ).insertBefore( lnk );
} else {
lnk.attr( 'title', lnk.attr( 'title' ) + tip );
}
}
}
if ( --apiRequests === 0 ) { // last response
container.removeClass( 'markblocked-loading' );
$( '#ca-showblocks' ).parent().remove(); // remove added portlet link
}
}
// --------AUX functions
// 20081226220605 or 2008-01-26T06:34:19Z -> date
function parseTS( ts ) {
var m = ts.replace( /\D/g, '' ).match( /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/ );
return new Date ( Date.UTC( m[1], m[2]-1, m[3], m[4], m[5], m[6] ) );
}
function inHours( ms ) { // milliseconds -> "2:30" or 5,06d or 21d
var mm = Math.floor( ms / 60000 );
if ( !mm ) {
return Math.floor( ms / 1000 ) + 's';
}
var hh = Math.floor( mm / 60 );
mm = mm % 60;
var dd = Math.floor( hh / 24 );
hh = hh % 24;
if ( dd ) {
return dd + ( dd < 10 ? '.' + zz( hh ) : '' ) + 'd';
}
return hh + ':' + zz( mm );
}
function zz( v ) { // 6 -> '06'
if ( v <= 9 ) {
v = '0' + v;
}
return v;
}
}// -- end of main function
// Start on some pages
switch ( mw.config.get( 'wgAction' ) ) {
case 'edit':
case 'submit':
break;
default: // 'view', 'history', 'purge', ...
var maybeAutostart = $.Deferred();
if ( window.mbNoAutoStart ) {
var portletLink = mw.util.addPortletLink( 'p-cactions', '', 'XX', 'ca-showblocks' );
$( portletLink ).click( function ( e ) {
e.preventDefault();
maybeAutostart.resolve();
} );
} else {
maybeAutostart.resolve();
}
$.when( $.ready, mw.loader.using( 'mediawiki.util' ), maybeAutostart ).then( function() {
var firstTime = true;
mw.hook( 'wikipage.content' ).add( function ( container ) {
// On the first call after initial page load, container is mw.util.$content
// Used to limit mainspace activity to just the diff definitions
if ( mw.config.get( 'wgAction' ) === 'view' && mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
container = container.find( '.diff-title' );
}
if ( firstTime ) {
firstTime = false;
// On page load, also update the namespace tab
container = container.add( '#ca-nstab-user' );
mw.util.addCSS('\
.markblocked-loading a.userlink {opacity:' + ( window.mbLoadingOpacity || 0.85 ) + '}\
a.user-blocked-temp {' + ( window.mbTempStyle || 'opacity: 0.7; text-decoration: line-through' ) + '}\
a.user-blocked-indef {' + ( window.mbIndefStyle || 'opacity: 0.4; font-style: italic; text-decoration: line-through' ) + '}\
a.user-blocked-partial {' + ( window.mbPartialStyle || 'text-decoration: underline; text-decoration-style: dotted' ) + '}\
.user-blocked-tipbox {' + ( window.mbTipBoxStyle || 'font-size:smaller; background:#FFFFF0; border:1px solid #FEA; padding:0 0.3em; color:#AAA' ) + '}\
');
}
markBlocked( container );
} );
} );
}
/**
* Script for the Birthday Committee
* Rip-off from Twinkle's Welcome module ([[MediaWiki:Gadget-friendlywelcome.js]])
*/
// <nowiki>
$.when(
mw.loader.using('ext.gadget.morebits'),
$.ready
).then(function() {
if (!mw.config.get('wgRelevantUserName')) {
return;
}
var Wish = {};
window.Wish = Wish;
Wish.advert = ' ([[User:SD0001/BDCS|BDCS]])';
var li = mw.util.addPortletLink('p-cactions', '#', 'BDC wish', 'p-wish', 'Wish user');
li.addEventListener('click', function() {
Wish.callback(mw.config.get('wgRelevantUserName'));
});
Wish.callback = function (uid) {
if (uid === mw.config.get('wgUserName') && !confirm('Are you really sure you want to wish yourself?...')) {
return;
}
Morebits.wiki.api.setApiUserAgent('[[w:User:SD0001/BDCS.js]]');
var Window = new Morebits.simpleWindow(600, 420);
Window.setTitle('Wish user');
Window.addFooterLink('Birthday Committee', 'WP:BDC');
var form = new Morebits.quickForm(Wish.callback.evaluate);
form.append({
type: 'select',
name: 'type',
label: 'Type of wish: ',
event: Wish.populateWishList,
list: [
{ type: 'option', value: 'birthday', label: 'Happy Birthday', selected: true },
{ type: 'option', value: 'firsteditday', label: 'Happy First Edit Day' },
{ type: 'option', value: 'anniv', label: 'Happy Adminship Anniversary' }
].concat(
window.BDCS_CustomTemplates && window.BDCS_CustomTemplates.length ?
[ { type: 'option', value: 'custom', label: 'Custom templates' } ] : []
)
});
form.append({
type: 'div',
id: 'wishWorkArea'
});
form.append({
type: 'input',
name: 'heading',
label: 'Section heading: ',
value: 'Happy Birthday!'
});
var previewlink = document.createElement('a');
$(previewlink).click(function() {
Wish.callbacks.preview(result); // |result| is defined below
});
previewlink.style.cursor = 'pointer';
previewlink.textContent = 'Preview';
form.append({ type: 'div', id: 'wishpreview', label: [ previewlink ] });
form.append({ type: 'div', id: 'wish-previewbox', style: 'display: none' });
form.append({ type: 'submit' });
var result = form.render();
Window.setContent(result);
Window.display();
result.previewer = new Morebits.wiki.preview($('#wish-previewbox').last()[0]);
// initialize the wish list
var evt = document.createEvent('Event');
evt.initEvent('change', true, true);
result.type.dispatchEvent(evt);
};
Wish.populateWishList = function(e) {
var type = e.target.value;
var form = e.target.form;
var container = new Morebits.quickForm.element({ type: 'fragment' });
var appendTemplates = function(list) {
container.append({
type: 'radio',
name: 'template',
list: list.map(function(obj) {
return {
value: obj,
label: '{{' + obj + '}}'
}
})
});
};
switch (type) {
case 'birthday':
form.heading.value = 'Happy Birthday!';
appendTemplates([
'Happy Birthday',
'Happy Birthday 2',
'Happy Birthday 3',
'Happy Birthday 4',
'Happy Birthday 5',
'Happy Birthday 6',
'Happy Birthday 7',
'Happy Birthday 8',
'Happy Birthday 9',
'Happy Birthday 10',
'Happy Birthday 11',
'Happy Birthday 12',
'Happy Birthday 13'
]);
break;
case 'firsteditday':
form.heading.value = 'Happy First Edit Day!';
appendTemplates([
'First Edit Day',
'First Edit Day 2',
'First Edit Day 3',
'First Edit Day 4',
'First Edit Day 5',
]);
break;
case 'anniv':
form.heading.value = 'Happy Adminship Anniversary!';
appendTemplates([
'Happy Adminship',
'Happy Adminship 2',
'Happy Adminship 3',
'Happy Adminship 4',
'Happy Adminship 5',
'Happy Adminship 6',
'Happy Adminship 7',
'Happy Bureaucratship',
'Happy Bureaucratship 2',
'Happy Bureaucratship 3',
'Birthday Committee/Inactive'
]);
break;
case 'custom':
form.heading.value = '';
appendTemplates(window.BDCS_CustomTemplates);
break;
default:
container.append({ type: 'div', label: 'Wish.populateWishList: something went wrong' });
break;
}
var rendered = container.render();
$('#wishWorkArea').empty().append(rendered);
var firstRadio = form.template[0] || form.template;
firstRadio.checked = true;
};
Wish.getTemplateWikitext = function(template, heading) {
return '==' + heading + '==\n{{subst:' + template + '}}';
};
Wish.callbacks = {
preview: function(form) {
form.previewer.beginRender(Wish.getTemplateWikitext(form.getChecked('template'), form.heading.value), 'User talk:' + mw.config.get('wgRelevantUserName'));
},
main: function(pageobj) {
var params = pageobj.getCallbackParameters();
var text = pageobj.getPageText();
var wishText = Wish.getTemplateWikitext(params.value, params.heading);
text += '\n' + wishText;
summaryText = (params.heading ? ('/* ' + params.heading + ' */ ') : '') + 'new section';
pageobj.setPageText(text);
pageobj.setEditSummary(summaryText + Wish.advert);
pageobj.setCreateOption('nocreate');
pageobj.save();
}
};
Wish.callback.evaluate = function wishEvaluate(e) {
var form = e.target;
var params = {
value: form.getChecked('template'),
heading: form.heading.value
};
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init(form);
var userTalkPage = mw.config.get('wgFormattedNamespaces')[3] + ':' + mw.config.get('wgRelevantUserName');
Morebits.wiki.actionCompleted.redirect = userTalkPage;
Morebits.wiki.actionCompleted.notice = 'Wishing complete, reloading talk page in a few seconds';
var wikipedia_page = new Morebits.wiki.page(userTalkPage, 'User talk page modification');
wikipedia_page.setFollowRedirect(true);
wikipedia_page.setCallbackParameters(params);
wikipedia_page.load(Wish.callbacks.main);
};
});
// </nowiki>
importScript( 'User:Danski454/stubsearch.js' ); // Backlink: [[User:Danski454/stubsearch.js]]
mw.loader.load( '/w/index.php?title=User:Evad37/MoveToDraft.js&action=raw&ctype=text/javascript' ); // Backlink: [[User:Evad37/MoveToDraft.js]]
importScript('User:Evad37/rater.js'); // Backlink: [[User:Evad37/rater.js]]
importScript('User:PleaseStand/userinfo.js'); // Backlink: [[User:PleaseStand/userinfo.js]]
importScript('User:Ingenuity/AntiVandal.js'); // Backlink: [[User:Ingenuity/AntiVandal.js]]
importScript('User:Novem Linguae/Scripts/NPPLinks.js'); // Backlink: [[User:Novem Linguae/Scripts/NPPLinks.js]]
importScript('User:Shubinator/DYKcheck.js'); // Backlink: [[User:Shubinator/DYKcheck.js]]
importScript('User:MusikAnimal/responseHelper.js'); // Backlink: [[User:MusikAnimal/responseHelper.js]]
importScript('User:Nageh/rollbackSum.js'); // Backlink: [[User:Nageh/rollbackSum.js]]
importScript('User:Kangaroopower/MRollback.js'); // Backlink: [[User:Kangaroopower/MRollback.js]]
importScript('User:Headbomb/unreliable.js'); // Backlink: [[User:Headbomb/unreliable.js]]
importScript('User:Novem Linguae/Scripts/VisualEditorEverywhere.js'); // Backlink: [[User:Novem Linguae/Scripts/VisualEditorEverywhere.js]]
mw.loader.load( '/w/index.php?title=User:Joeytje50/JWB.js/load.js&action=raw&ctype=text/javascript' ); // Backlink: [[User:Joeytje50/JWB.js/load.js]]
importScript('User:Writ Keeper/Scripts/massRollback.js'); // Backlink: [[User:Writ Keeper/Scripts/massRollback.js]]
importScript('User:RedWarn/.js'); // Backlink: [[User:RedWarn/.js]]