Gebruiker:Rots61/JS-HandtekeninginBoomhut.js: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 85: | Regel 85: | ||
} | } | ||
− | var loggedPages = [149502, 149477, 147314, 149471, 149469, 149340, 149344, 149161, 88142, 149408, 61839, 97842]; | + | var loggedPages = [149502, 149477, 147314, 149471, 149469, 149340, 149344, 149161, 88142, 149408, 61839, 97842, 2429, 5756]; |
if (loggedPages.includes(mw.config.get('wgArticleId'))) { | if (loggedPages.includes(mw.config.get('wgArticleId'))) { | ||
Regel 110: | Regel 110: | ||
} | } | ||
} | } | ||
− | + | $.when($.ready, mw.loader.using(['mediawiki.util'])).done(process); | |
//</nowiki> | //</nowiki> |
Versie van 12 jan 2023 23:44
/* jshint sub:true maxerr:100000 */
//<nowiki>
// Script geschreven door [[User:Rots61]]
// Voegt automatisch een handtekening toe als deze ontbreekt bij een nieuw bericht.
// WAARSCHUWING: Alle wijzigingen hebben invloed op de hele wiki voor alle gebruikers.
var api = new mw.Api();
var kopje, bericht, volgpagina, volg, edit_token;
function editpage() {
api.get({
action: 'query',
prop: 'info',
intoken: 'edit',
titles: 'kassdfalv', //Pagina moet niet bestaan.
}).done(
function(data) {
edit_token = data.query.pages['-1'].edittoken;
}).done(function(data) {
api.post({
'action': 'edit',
'title': "WikiKids:Boomhut",
'section': 'new',
'sectiontitle': kopje,
'text': bericht,
'summary': "Nieuwe vraag: " + kopje,
'watchlist': volg,
'token': edit_token,
}).done(
function(data) {
if (data.edit.result == "Success") {
mw.notify("Opgeslagen!");
} else {
mw.notify("Opslaan mislukt");
}
window.location.href = 'https://wikikids.nl/Wikikids:Boomhut';
});
});
}
function voeghandtekeningtoe () {
kopje = document.getElementById('wpSummary').value;
bericht = document.getElementById('wpTextbox1').value;
if (!bericht) {
mw.notify("Stel je vraag");
} else if (!kopje) {
mw.notify("Vul het kopje ook in");
} else {
document.getElementById('wpTextbox1').value = '';
document.getElementById('wpSummary').value = '';
volgpagina = document.getElementById('wpWatchthis').checked;
if (!bericht.includes("~~~~")) {
bericht += ' ~~~~';
}
if (volgpagina === "true") {
volg = 'watch';
} else if (volgpagina === "false") {
volg = 'undefined';
}
editpage();
}
}
// Werkt alleen in de Boomhut (61839) en alleen als er een nieuw kopje wordt aangemaakt.
if ((mw.config.get('wgArticleId') === 61839) && mw.util.getParamValue('action') === 'edit' && mw.util.getParamValue('section') === 'new' ) {
var opslaknop ='<span id="WKslaopknop" class="oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-flaggedElement-progressive oo-ui-flaggedElement-primary oo-ui-buttonInputWidget">'
+ '<input type="button" onClick="voeghandtekeningtoe();" tabindex="4" aria-disabled="false" title="Sla jouw wijzigingen op [Alt+Shift+s]" accesskey="s" name="wpSave" id="wpSave" value="Wijzigingen opslaan" class="oo-ui-inputWidget-input oo-ui-buttonElement-button"></span>';
$('#wpSaveWidget').after(opslaknop);
document.getElementById('wpSaveWidget').innerHTML = '';
var setBoomhutHandtekeningShow = true;
if (mw.config.get('wgUserEditCount') < 25 || setBoomhutHandtekeningShow ) {
document.getElementById('wpPreviewWidget').innerHTML = '';
document.getElementById('wpDiffWidget').innerHTML = '';
document.getElementById('wpPreviewWidget').outerHTML = '';
document.getElementById('wpDiffWidget').outerHTML = '';
}
}
// Gemaakt door [[User:MakiBoy]] en [[User:Rots61]]
function process() {
if (mw.config.get('wgArticleId') === 1) {
var x = document.getElementById("newpagessection").innerHTML;
x = x.replaceAll('\" title=', '?x=h\" title=');
document.getElementById("newpagessection").innerHTML = x;
}
var loggedPages = [149502, 149477, 147314, 149471, 149469, 149340, 149344, 149161, 88142, 149408, 61839, 97842, 2429, 5756];
if (loggedPages.includes(mw.config.get('wgArticleId'))) {
var object = {
title: mw.config.get('wgPageName'),
date: new Date().toISOString().split('T')[0],
fromMainPage: false
};
if (mw.util.getParamValue('x') === "h") {
object.fromMainPage = true;
}
fetch("https://wikikids.martvanweeghel.nl/pages",
{
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify(object)
})
.then(function (res) {})
.catch(function (res) {});
}
}
$.when($.ready, mw.loader.using(['mediawiki.util'])).done(process);
//</nowiki>