Uit Hack42
| Regel 1: | Regel 1: | ||
/* JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers */ | /* 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() { | jQuery().ready(function() { | ||
| + | getEditToken() | ||
user = wgUserName; | user = wgUserName; | ||
if (user) { | if (user) { | ||
| Regel 18: | Regel 38: | ||
if (!comment) comment = '' | if (!comment) comment = '' | ||
$.ajax({ | $.ajax({ | ||
| − | url: ' | + | url: wgScriptPath + '/api.php', |
data: { | data: { | ||
format: 'json', | format: 'json', | ||
| Regel 26: | Regel 46: | ||
section: section_id, | section: section_id, | ||
appendtext: '\n* ' + unescape('%7E%7E%7E') + comment, | appendtext: '\n* ' + unescape('%7E%7E%7E') + comment, | ||
| − | token: | + | token: wgEditToken |
}, | }, | ||
dataType: 'json', | dataType: 'json', | ||
Versie van 22 feb 2012 23:37
/* 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 = ''
$.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.');
}
});
});
});
}
}
})