Użytkownik:Polskacafe/fastSDU.js: Różnice pomiędzy wersjami

Z Nonsensopedii, polskiej encyklopedii humoru
Linia 35: Linia 35:
if($('#ca-edit')[0]) {$(document).ready(initButton);}
if($('#ca-edit')[0]) {$(document).ready(initButton);}
// function sdupage() {
// var reason = prompt('Podaj powód SDU (jeśli nie wpiszesz nic, zostanie użyty powód „Marne”):'); // wywołuje okno dialogowe
// if (reason == null) {
// return;
// }
// if (typeof reason == "undefined" || reason == '' || reason == ' ') {
// var reason = 'Marne';
// }


function sdupage(powod, strona) {
// var actualYear = (new Date).getFullYear();
// var actualMonth = (new Date).getMonth() + 1;
var currentYear = (new Date()).getFullYear();
// var actualDay = (new Date).getDate();
var currentMonth = (new Date()).getMonth() + 1;
var currentDay = (new Date()).getDate();
// if (actualMonth < 10) {
var currentdate = currentYear + '-' + (currentMonth<=9 ? '0' + currentMonth : currentMonth) + '-' + (currentDay<=9 ? '0' + currentDay : currentDay);
// actualMonth = actualMonth.toString();
(new mw.Api()).post({
// actualMonth = '0' + actualMonth;
format: 'json',
// }
action: 'edit',
// if (actualDay < 10) {
title: mw.config.get('wgPageName'),
// actualDay = actualDay.toString();
prependtext: '{{subst:SDU}}\n',
// actualDay = '0' + actualDay;
token: mw.user.tokens.get('editToken'),
// }
summary: 'Dodano szablon SDU' /* wstaw własny powód edycji */
// var actualdate = actualYear + '-' + actualMonth + '-' + actualDay;
})
// var secondApi = new mw.Api();
// secondApi.post({
(new mw.Api()).post({
// format: 'json',
// action: 'edit',
format: 'json',
action: 'edit',
// title: mw.config.get('wgPageName'),
title: 'Nonsensopedia:SDU/' + currentdate + '/' + mw.config.get('wgPageName'),
// prependtext: '{{subst:SDU}}\n',
prependtext: '{{subst:SDU-nowe|powód=' + powod + '|podpis=~~~|strona=' + strona + '}}', //jak kopiujesz, to najprawdopodobniej musisz zmienić ~~~ na ~~~~
// token: mw.user.tokens.get('editToken'),
token: mw.user.tokens.get('editToken'),
// summary: 'Dodano szablon SDU' /* wstaw własny powód edycji */
summary: 'Wystawiono głosowanie na SDU' /* wstaw własny powód edycji */
// })
})

.done( function (data) {
// var api = new mw.Api();
window.location.reload();
// api.post({
})
// format: 'json',
.fail( function(error) {
// action: 'edit',
console.log(error);
// title: 'Nonsensopedia:SDU/' + actualdate + '/' + mw.config.get('wgPageName'),
});
// prependtext: '{{subst:SDU-nowe|powód=' + reason + '|podpis=~~~|strona=za}}', //jak kopiujesz, to najprawdopodobniej musisz zmienić ~~~ na ~~~~
}
// token: mw.user.tokens.get('editToken'),
// summary: 'Wystawiono głosowanie na SDU' /* wstaw własny powód edycji */
// })
// .done( function (data) {
// window.location.reload()
// })
// .fail( function(error) {
// console.log(error);
// });
// }
//</nowiki></pre>
//</nowiki></pre>

Wersja z 16:11, 29 cze 2019

//<pre><nowiki>
/**
 * Wystawianie SDU jednym kliknięciem (no dobra, więcej niż jednym, ale to taka nazwa)
 * Autor: Polskacafe
 * Używać na własną odpowiedzialność!
 * W przypadku kopiowania, proszę, skopiuj również komentarze, w tym autora.
 **/

function initButton() {
	let namespace = mw.config.get("wgNamespaceNumber");
	if (namespace !== -1 && namespace % 2 === 0 && [14, 110, 2].indexOf(wgNamespaceNumber) == -1) {
		$('#p-views.vectorTabs > ul').prepend('<li id="ca-sdu" class="collapsible"><span><a title="Szybkie wystawianie SDU" data-id="fastSDU">SDU</a></span></li>');
		$("a[data-id='fastSDU']").click(openWindow);
	}
}

function openWindow() {
	$('<div title="Zgłoszenie strony na SDU" id="sdu-window"><b>Podaj uzasadnienie zgłoszenia:</b><br /><input type="text" name="sduReason"/>')
		.css({textAlign:"center"})
		.dialog({
			open: function(event, ui) {$(event.target).dialog('widget').css({ position: 'fixed' }).position({ my: 'center', at: 'center', of: window });},
			close:function(){},
			minHeight:"auto",
			minWidth: 500,
			resizable:false,
			buttons:[
				{text:"Anuluj", click:function(){$( this ).dialog( "close" );}},
				{text:"Przeciw", click:function(){$(this).dialog("close");}},
				{text:"Wstrzymuję się", click:function(){$(this).dialog("close");}},
				{text:"Za", click:function(){$(this).dialog("close");}}
			]
		}
	);
}
 
if($('#ca-edit')[0]) {$(document).ready(initButton);}

function sdupage(powod, strona) {
	var currentYear = (new Date()).getFullYear();
	var currentMonth = (new Date()).getMonth() + 1; 
	var currentDay = (new Date()).getDate();
	var currentdate = currentYear + '-' + (currentMonth<=9 ? '0' + currentMonth : currentMonth) + '-' + (currentDay<=9 ? '0' + currentDay : currentDay);
	(new mw.Api()).post({
		format: 'json',
		action: 'edit',
		title: mw.config.get('wgPageName'),
		prependtext: '{{subst:SDU}}\n', 
		token: mw.user.tokens.get('editToken'),
		summary: 'Dodano szablon SDU' /* wstaw własny powód edycji */
	})
	
	(new mw.Api()).post({
		format: 'json',
		action: 'edit',
		title: 'Nonsensopedia:SDU/' + currentdate + '/' + mw.config.get('wgPageName'),
		prependtext: '{{subst:SDU-nowe|powód=' + powod + '|podpis=~~~|strona=' + strona + '}}', //jak kopiujesz, to najprawdopodobniej musisz zmienić ~~~ na ~~~~ 
		token: mw.user.tokens.get('editToken'),
		summary: 'Wystawiono głosowanie na SDU' /* wstaw własny powód edycji */
	})
	.done( function (data) {
		window.location.reload();
	})
	.fail( function(error) {
		console.log(error);
	});
}
//</nowiki></pre>