MediaWiki:Common.js: verschil tussen versies
Uit Dorpsbelang Den Hout
Regel 5: | Regel 5: | ||
var domein = ""; | var domein = ""; | ||
var parameters = ""; | var parameters = ""; | ||
+ | var multiparameters = {}; | ||
var inputs = el.closest('form').querySelectorAll('textarea, input:not([name="mwreturn"] ):not([name="mwdb"] ):not([name="mwtoken"] ):not([type="file"])'), i; | var inputs = el.closest('form').querySelectorAll('textarea, input:not([name="mwreturn"] ):not([name="mwdb"] ):not([name="mwtoken"] ):not([type="file"])'), i; | ||
for(i = 0; i < inputs.length; ++i){ | for(i = 0; i < inputs.length; ++i){ | ||
if(inputs[i].name == "Titel"){titel = inputs[i].value}; | if(inputs[i].name == "Titel"){titel = inputs[i].value}; | ||
if(inputs[i].name == "Domein"){domein = inputs[i].value}; | if(inputs[i].name == "Domein"){domein = inputs[i].value}; | ||
+ | if(inputs[i].name.includes("[]")){ | ||
+ | multiparameters[inputs[i].name.replace('[]', '')] = []; | ||
+ | multiparameters[inputs[i].name.replace('[]', '')].push(inputs[i].value); | ||
+ | }else{ | ||
parameters += '|'+inputs[i].name+'='+inputs[i].value; | parameters += '|'+inputs[i].name+'='+inputs[i].value; | ||
} | } | ||
− | var url = domein.replace('.','-')+'/'+titel.replace(' ', '-') | + | var url = domein.replace('.','-')+'/'+titel.replace(' ', '-'); |
+ | |||
+ | var multi = ""; | ||
+ | for(i = 0; i < multiparameters.length; ++i){ | ||
+ | multi += '|'+Object.keys(multiparameters)[i]+'='+multiparameters[i]; | ||
+ | } | ||
+ | |||
var wikitext = '{{'+template+parameters+'}}' | var wikitext = '{{'+template+parameters+'}}' | ||
− | + | console.log(wikitext) | |
var params = { | var params = { | ||
action: 'edit', | action: 'edit', | ||
Regel 22: | Regel 33: | ||
api = new mw.Api(); | api = new mw.Api(); | ||
− | + | // api.postWithToken( 'csrf', params ).done( function ( html ) { | |
− | + | // window.location = url; | |
− | + | // }) | |
} | } |
Versie van 18 aug 2020 13:36
// JavaScript die hier wordt geplaatst heeft invloed op alle pagina's voor alle gebruikers <script> function postBericht(el, template){ var titel = ""; var domein = ""; var parameters = ""; var multiparameters = {}; var inputs = el.closest('form').querySelectorAll('textarea, input:not([name="mwreturn"] ):not([name="mwdb"] ):not([name="mwtoken"] ):not([type="file"])'), i; for(i = 0; i < inputs.length; ++i){ if(inputs[i].name == "Titel"){titel = inputs[i].value}; if(inputs[i].name == "Domein"){domein = inputs[i].value}; if(inputs[i].name.includes("[]")){ multiparameters[inputs[i].name.replace('[]', '')] = []; multiparameters[inputs[i].name.replace('[]', '')].push(inputs[i].value); }else{ parameters += '|'+inputs[i].name+'='+inputs[i].value; } var url = domein.replace('.','-')+'/'+titel.replace(' ', '-'); var multi = ""; for(i = 0; i < multiparameters.length; ++i){ multi += '|'+Object.keys(multiparameters)[i]+'='+multiparameters[i]; } var wikitext = '{{'+template+parameters+'}}' console.log(wikitext) var params = { action: 'edit', title: url, text: wikitext, format: 'json' }, api = new mw.Api(); // api.postWithToken( 'csrf', params ).done( function ( html ) { // window.location = url; // }) }