Wikipedia:User scripts/Guide: Difference between revisions
Content deleted Content added
→Textarea with article wikicode: updated link to jquery.textSelection doc |
Element10101 (talk | contribs) →Editing: how to semi-automatically edit a page! |
||
Line 442:
==== Edittools ====
There is another edit panel under textarea. Usually it is generated from [[MediaWiki:Edittools]] by [[mw:Extension:CharInsert|Extension:CharInsert]] and consists of a lot of JavaScript links. In the English Wikipedia, this approach was replaced by [[MediaWiki:Gadget-charinsert.js]] and [[MediaWiki:Gadget-charinsert-core.js]].
==== Automatic and semi-automatic editing ====
You can automate the editing of a page using the following code template:
<syntaxhighlight lang="javascript" copy style="min-width:fit-content; max-width:40%;">
mw.loader.using("mediawiki.user", () => {
$.post( mw.config.get('wgScriptPath') + '/api.php', {
action: 'edit',
title: "[Page title]",
text: "[Text]",
summary: "[Edit summary]",
token: mw.user.tokens.get('csrfToken'), // This is the user token required to authorize the edit.
format: 'json'
}).then(function(r){
if (r.error) {
mw.notify(r.error.info, {type: 'error', title: 'error.'}); // Sends an error message if unable to edit the page.
}
});
});
</syntaxhighlight>
=== Doing something after another user script ===
|