Uit Hack42
| Regel 51: | Regel 51: | ||
type: 'POST', | type: 'POST', | ||
success: function(data) { | success: function(data) { | ||
| − | location.reload() | + | //location.reload() |
}, | }, | ||
error: function(xhr) { | error: function(xhr) { | ||
Versie van 22 feb 2012 23:39
/* JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers */
function getEditToken() {
jQuery.getJSON(
wgScriptPath + '/api.php?',
{
action: 'query',
prop: 'info',
intoken: 'edit',
titles: 'Main Page',
indexpageids: '',
format: 'json'
},
function( data ) {
if ( data.query.pages && data.query.pageids ) {
var pageid = data.query.pageids[0];
wgEditToken = data.query.pages[pageid].edittoken;
}
}
)
}
jQuery().ready(function() {
getEditToken()
user = wgUserName;
if (user) {
titels = '#Ik_kom_wel,#Ik_kom_niet,#Animo,#Aanwezig,#Afwezig';
var user_is_al_in_lijst = jQuery(titels).parent().next().find('li a:contains("' + user + '")');
if (user_is_al_in_lijst.length) {
// user_is_al_in_lijst.parent().append('<input type="button" value="-"/>');
} else {
jQuery(titels).each(function(index, val) {
var ul = jQuery(val).parent().next()
var section_id = jQuery(val).parent().children('span').children('a').attr('href').match(/section=([0-9]+)/)[1]
var li = ul.append('<li><input type="button" value="' + user + '"/><input type="text" /></li>');
jQuery(li).find('input[type="button"]').click(function() {
var comment = " " + jQuery(this).next().attr('value')
if (!comment) comment = ''
jQuery.ajax({
url: wgScriptPath + '/api.php',
data: {
format: 'json',
action: 'edit',
title: wgPageName,
summary: 'naam toegevoegd via button',
section: section_id,
appendtext: '\n* ' + unescape('%7E%7E%7E') + comment,
token: wgEditToken
},
dataType: 'json',
type: 'POST',
success: function(data) {
//location.reload()
},
error: function(xhr) {
alert('Error: iets is mis gegaan, herlaad pagina en probeer opnieuw.');
}
});
});
});
}
}
})