Benutzer:$traight-$hoota/js/botauftrag.js
Erscheinungsbild
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
//Dokumentation unter [[Benutzer:$traight-$hoota/js/bautauftrag]] <nowiki>
/*global mw: true */
(function($, mw){
var botauftrag = {
version: "0.1",
botPage: "Wikipedia:WikiProjekt Kategorien/Warteschlange",
debugMode: false
}
if(botauftrag.debugMode){
botauftrag.botPage = "Benutzer:$traight-$hoota/js/botauftrag/BotPage"
}
function onBotauftrag(e){
e.preventDefault();
var data = $(e.target).data();
data.reason = "erl";
reasons = {
"erl" : "erledigt",
"b": "bleibt",
"x": "gelöscht",
"sla": "schnellgelöscht",
"rev": "zurückgezogen",
"lae": "WP:LAE"
};
data.comment = "umgesetzt --~~~~";
data.editLink.match(/(\?|&)section=(\d+)/);
data.section = parseInt(RegExp.$2);
$.get(data.editLink + "&action=raw", function (raw) {
raw = $.trim(raw);
data.rawText = $.trim(raw.replace(/(=[=]+)\s*(.+)\s*=[=]+\s*/, ""));
data.titleDepth = RegExp.$1;
data.rawTitle = $.trim(RegExp.$2);
mw.loader.using('jquery.ui.dialog', function () {
mw.libs.schnark_dialog.show(
'Botauftrag erstellen',
[
{type: 'inputbox', name: 'command', text: "Bot-Befehl", focus: true, standard: data.rawTitle, enter: true},
{type: 'inputbox', name: 'comment', text: "Erledigt-Kommentar", standard: data.comment, enter: true},
],
function (a) {
data.command = a.command;
data.comment = a.comment;
applyChanges(data);
}
);
});
});
}
function applyChanges(data){
params = [
//params
{
title: botauftrag.botPage,
summary: "Bot: " + data.command,
section: "new",
change: function(text){
return createCodeForBotPage(data);
}
},{
summary: "/*" + data.title + "*/ " + data.reason,
section: data.section,
action: "wpSave", //alt:wpPreview
change: function(text){
return createCodeForDisussionPage(data)
}
}];
console.log(params);
mw.libs.autoedit.edit_series(params,
//autosave
[true, false],
//callback
function(a,b,c){
console.log(a)
console.log(b)
console.log(c)
},
//replace_last
true
)
}
function createCodeForBotPage(data){
if(! data.command.match(/(\((Artikel|Kategorie)\))?\[\[:Kategorie:.*\]\] nach \[\[:Kategorie:.*\]\](, \[\[:Kategorie:.*\]\])*|\[\[:Kategorie:.*\]\] leeren/)){
console.error("Invalid bot command: " + data.command);
return false;
}
page = mw.config.get("wgPageName");
page = page.replace(/ /g, ' ');
code = "[[" + page + "#" + data.title + "|Diskussion]] --~~~~";
console.log(code);
return code;
}
function createCodeForDisussionPage(data){
if(data.reason == "erl"){
data.reason = "";
}else if(data.reason != ""){
data.reason = "|" + data.reason;
}
erlTitle = "{{erl|" + data.rawTitle + data.reason + "}}";
erlTitle = data.titleDepth + " " + erlTitle + " " + data.titleDepth;
code = erlTitle + "\n" + data.rawText + "\n\n " + data.comment;
console.log(code);
return code;
}
function addLinks(){
mw.util.$content.find('h1,h2,h3,h4,h5,h6').each(function (i, h) {
var $h = $(h);
var $mwHeadline = $h.find('.mw-headline');
console.log($mwHeadline);
if(! $mwHeadline.length){
return;
}
var $editsection = $h.find('.mw-editsection'),
hash = $mwHeadline.attr('id') || '',
editLink = false,
title = $mwHeadline.text();
$editsection.find("a").each(function(){
$this = $(this);
if($this.text() == "Bearbeiten"){
editLink = $this.attr("href");
}
});
$link = $(mw.html.element('a', {
href: '#',
title: "Diesen Antrag auf die Kategorienwarteschlange einstellen"
}, "Bot beauftragen")).data({
"editLink": editLink,
"hash": hash,
"title": title
}).on("click", onBotauftrag);
$editsection.append(' <span class="mw-editsection-bracket">[</span>', $link, '<span class="mw-editsection-bracket">]</span>');
});
}
addLinks();
function init(){
var pageName = mw.config.get("wgPageName");
if(! botauftrag.debugMode){
if(! pageName.match(/Wikipedia:WikiProjekt_Kategorien\/Diskussionen\/(\d{4})\/(.+)\/(\d{1,2})/)){
return false;
}
}else{
if(! pageName.match(/Benutzer:$traight-$hoota\/js\/botauftrag\/Antrag/)){
return false;
}
}
/*var year = RegExp.$1;
var month = RegExp.$2;
var date = RegExp.$3;*/
$(addLinks);
}
init();
})(jQuery, mw);
//</nowiki>