Użytkownik:Frisk/common.js
Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.
- Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
- Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
- Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
- Opera: Naciśnij klawisze Ctrl+F5.
//mw.loader.load( '//commons.wikimedia.org/w/index.php?title=MediaWiki:Gadget-//HotCat.js&action=raw&ctype=text/javascript' );
//Fast edit reasons
setTimeout(function() {addSumButton ( 'nieuzasadniona edycja', 'nieuzasadniona edycja' );
addSumButton ( 'niepotrzebna edycja', 'niepotrzebna edycja' );
addSumButton ( 'nonsens', 'nonsens' );
addSumButton ( 'spam', 'spam' );}, 4000)
// Script created by Majr, http://minecraft.gamepedia.com/User:Majr/inputCounter.js
$( function() {
'use strict';
var events = [
'keypress',
'change',
'mouseenter',
'mouseup',
'cut',
'paste',
'focus',
'blur'
].join( '.inputCounter ' ) + '.inputCounter';
// Display the amount of chars left on inputs that have a maxlength parameter
$( '#mw-content-text' ).on( events, 'input', function() {
var $input = $( this );
if ( $input.prop( 'type' ) !== 'text' ) {
return;
};
var max = $input.data( 'maxlength' ) || $input.attr( 'maxLength' );
if ( !max ) {
return;
}
mw.loader.using( 'jquery.byteLength', function() {
var $number = $input.parent().children( '.chars' );
if ( !$number.length ) {
// Get rid of the jQuery.byteLimit on the summary preventing extra characters being entered
$( '#wpSummary' ).off( '.byteLimit' );
var refocus = $input.is( ':focus' );
var display = $input.css( 'display' );
if ( display !== 'block' ) {
display = 'inline-block';
}
var width = $input.outerWidth();
$input
.removeAttr( 'maxLength' )
.data( 'maxlength', max )
.css( {
width: width,
'-moz-box-sizing': 'border-box',
boxSizing: 'border-box',
// Set soon to be lost native styling
paddingTop: $input.css( 'padding-top' ),
paddingBottom: $input.css( 'padding-bottom' ),
paddingLeft: $input.css( 'padding-left' ),
paddingRight: $input.css( 'padding-right' )
} )
.wrap( $( '<span>' )
.addClass( 'input-counter' )
.css( {
position: 'relative',
display: display
} )
)
.parent().width( width );
$number = $( '<span>' )
.addClass( 'chars' )
.css( {
position: 'absolute',
top: $input.css( 'border-top-width' ),
right: $input.css( 'border-right-width' ),
paddingTop: parseFloat( $input.css( 'padding-top' ) ) || 1,
paddingRight: parseFloat( $input.css( 'padding-right' ) ) || 1,
lineHeight: $input.css( 'line-height' )
} )
.insertAfter( $input );
}
// Timeout allows the text as just entered to be retrieved, rather than the text just before
setTimeout( function() {
var length = $.byteLength( $input.val() ),
delta = max - length;
// Take into account the predefined reason length
var $reasonList = $( '#wpDeleteReasonList, #wpProtectReasonSelection' );
if ( $reasonList.length && $reasonList.val() !== 'other' ) {
delta -= $.byteLength( $reasonList.val() ) + 2;
}
$number.text( delta );
if ( delta < 0 ) {
$number.addClass( 'extra-chars' ).css( 'color', '#F00' );
} else {
$number.removeClass( 'extra-chars' ).css( 'color', '#AAA' );
}
// Prevent entered text from overlapping the number
$input.css( 'padding-right', $number.innerWidth() + 5 );
// Reset focus if it was lost
if ( refocus && !$input.is( ':focus' ) ) {
$input.focus();
}
}, 0 );
} );
} );
// Update char count when changing a pre-defined reason select box
$( '#wpDeleteReasonList, #wpProtectReasonSelection' ).change( function() {
$( '#wpReason, #mwProtect-reason' ).focus();
} );
// Prevent forms from submitting that have inputs with too many characters
$( '#mw-content-text' ).on( 'submit', 'form', function( e ) {
var $extraChars = $( this ).find( '.extra-chars' );
if ( !$extraChars.length ) {
return;
}
e.preventDefault();
// Scroll the first input field with too many chars into view if needed
if ( $extraChars.first().offset().top < $( window ).scrollTop() + 40 ) {
$( window ).scrollTop( $extraChars.first().offset().top - 40 );
}
// Flash the numbers to draw attention to them
var flashes = 0, flash = setInterval( function() {
if ( $extraChars.data( 'flash' ) ) {
$extraChars.data( 'flash', 0 ).css( {
backgroundColor: '',
color: '#F00'
} );
flashes++;
} else {
$extraChars.data( 'flash', 1 ).css( {
backgroundColor: '#F00',
color: '#FFF'
} );
}
if ( flashes === 4 ) {
clearInterval( flash );
if ( !$extraChars.hasClass( 'extra-chars' ) ) {
$extraChars.css( 'color', '#AAA' );
}
}
}, 500 );
} );
} );
mw.loader.using('mediawiki.api').then(function() {
if (mw.config.get("wgNamespaceNumber") != 202) return;
var user = mw.config.get("wgPageName").slice(12);
var a = new mw.Api();
var startDate = new Date(new Date().setFullYear(new Date().getFullYear() - 1)).toISOString();
var contribs = [];
var dateContribs = [];
var testDate = startDate;
while (testDate.slice(0,10) <= new Date().toISOString().slice(0,10)) {
dateContribs.push({date:testDate.slice(0,10),contribs:0});
testDate = new Date(new Date(testDate).getTime() + 86400000).toISOString();
}
function findIndex(date) {
for (var i in dateContribs) {
if (dateContribs[i].date == date) return i;
}
return -1;
}
function processData() {
for (var c in contribs) {
dateContribs[findIndex(contribs[c].timestamp.slice(0,10))].contribs++;
}
var numWeeks = dateContribs.length / 7;
var gridOutput = '<div style="display:grid; grid-gap:2px; grid-template: repeat(7,1fr) / repeat('+Math.ceil(numWeeks)+',1fr); width:100%; height:120px;">';
for (d=0;d<dateContribs.length;d++) {
da = dateContribs[d];
var dayNum = new Date(da.date).getUTCDay() + 1;
var weekNum = Math.ceil(((d+1)/dateContribs.length) * numWeeks);
var bgColor = "#9999997d";
if (da.contribs > 0) bgColor = "#F3B67D";
if (da.contribs > 10) bgColor = "#F3B679";
if (da.contribs > 20) bgColor = "#F39A48";
if (da.contribs > 30) bgColor = "#F37F20";
gridOutput += '<div style="background-color:'+bgColor+'; cursor:pointer; grid-area:'+dayNum+' / '+weekNum+' / '+(dayNum+1)+' / '+(weekNum+1)+';" data-date="'+da.date+'" data-contribs="'+da.contribs+'" title="'+da.date+': '+da.contribs+'" class="contribDate"></div>';
}
gridOutput += '</div>'
$(".curseprofile .activity").after('<div class="contribution-grid section"><h3>Contribution grid</h3>'+gridOutput+'</div>')
$(".curseprofile .contribution-grid .contribDate").click(function() {
location.href = '/index.php?title=Special%3AContributions&contribs=user&target='+encodeURIComponent(user.replace(/ /g,'_'))+'&start='+$(this).data("date")+'&end='+$(this).data("date");
});
}
function getData(uccontinue) {
params = {action:"query",list:"usercontribs",ucuser:user,ucend:startDate,uclimit:"max"};
if (uccontinue !== "") params.uccontinue = uccontinue;
a.get(params).done(function (data) {
contribs = contribs.concat(data.query.usercontribs);
if (data["continue"] !== undefined) {
if (data["continue"].uccontinue !== undefined) {
getData(data["continue"].uccontinue);
return;
}
}
processData();
});
}
getData("");
});