Benutzer:A0815/unsigned.js

aus Wikipedia, der freien Enzyklopädie

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
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
/* ******** unsigned.js ******** */
// based on [[User:Olliminatore/unsigned.js]]
// updated/changed by [[Benutzer:Lustiger seth|seth]]
//
// MARK AUTOMATICALLY UNSIGNED COMMENTS ON TALK PAGES:
//<pre><nowiki>
// Below (unsigned2.js version 1.3,) by Invitatious. Dual-licensed under the terms of the GFDL v1.2 or the GPL v2.
// New features in this version: you can now choose an edit from the last 36.
// [[User:Olliminatore/unsigned.js]] (suggested), converted/ localized for de:
 
function is_elem_of_arr(elem, arr){
	for(var i=0;i<arr.length;++i){
		if(arr[i]==elem)
			return 1;
	}
	return 0;
}
 
function get_all_sig_dates_from_textarea(){
	var sigs = new Array();
	if(document.editform){
		var txtarea = document.editform.wpTextbox1.value;
		sigs = txtarea.match(/\d\d[:.]\d\d, \d?\d\. (?:jan|feb|mär|apr|mai|jun|jul|aug|sep|okt|nov|dez)\.? 2\d{3}(?: \(CES?T\))?|2\d{3}-\d\d-\d\d[T ]?\d\d:\d\d(?:Z|[-+]\d\d:\d\d)?/gi);
	}
	return(sigs==null)? new Array() : sigs;
}
 
function sig2ms(sigs){
	var sigs_ms = new Array();
	var months = new Object();
	months["jan"] = 1;
	months["feb"] = 2;
	months["mär"] = 3;
	months["apr"] = 4;
	months["mai"] = 5;
	months["jun"] = 6;
	months["jul"] = 7;
	months["aug"] = 8;
	months["sep"] = 9;
	months["okt"] = 10;
	months["nov"] = 11;
	months["dez"] = 12;
	var re_normal = /(\d\d)[:.](\d\d), (\d?\d)\. (jan|feb|mär|apr|mai|jun|jul|aug|sep|okt|nov|dez)\.? (2\d{3})((?: \(CES?T\))?)/i;
	var re_iso = /(2\d{3})-(\d\d)-(\d\d)[T ]?(\d\d):(\d\d)((?:Z|[-+]\d\d:\d\d)?)/;
	var year, month, day, h, min, date_obj, offset;
	for(var i=0;i<sigs.length;++i){
		if(re_normal.exec(sigs[i])){
			h = RegExp.$1;
			min = RegExp.$2;
			day = RegExp.$3;
			month = RegExp.$4;
			month = months[month.toLowerCase()];
			year = RegExp.$5;
			offset = RegExp.$6;
			offset = (offset==' (CEST)')? 2 : ((offset==' (CET)')? 1 : '?');
		}else if(re_iso.exec(sigs[i])){
			year = RegExp.$1;
			month = RegExp.$2;
			day = RegExp.$3;
			h = RegExp.$4;
			min = RegExp.$5;
			offset = RegExp.$6;
			offset = (offset=='Z')? 0 : ((offset=='')? '?': ((offset.substr(0,1)=='-')? -1:1)*((1*offset.substr(1,2))+(offset.substr(4,2)/60)));
		}
		date_obj = new Date(year, month-1, day, h, min, 0);
		if(offset=='?'){
			sigs_ms.push(date_obj.getTime() - 1*60*60*1000);
			sigs_ms.push(date_obj.getTime() - 2*60*60*1000);
		}else
			sigs_ms.push(date_obj.getTime() - offset*60*60*1000);
	}
	return sigs_ms;
}
 
function timestamp2ms(t){
	var year = t.substring(0, 4);
	var month = t.substring(4, 6);
	var day = (t.substring(6, 8) - 0);
	var hours = parseInt(t.substring(8, 10), 10);
	var min = parseInt(t.substring(10, 12), 10);
	// Add Timezone offset
	// get UTC time in msec
	// using timezone offset
	ms = new Date(year, month-1, day, hours, min, 0).getTime();
//	ms += 3600000*fetchTimezoneBackup().substring(0,2);
	return ms;
}
 
function addSigWikiCode(){
	// From revision 28011729 of [[:en:Wikipedia:WikiProject_User_scripts/Scripts/Get_tidy_title]]
	function aswcGet_tidy_title(){ // Get's the URL version of the page title.
	 var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
	 // cut everything up to "title=" from the start and everything past "&action=edit" from the end
	 editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit'));
	 return editlk // The result from this function might be needed unescape()ed
	};
  // LOCALIZABLE STRINGS START.
  var lsMonth_names = ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
   lsConflict = "Edit-Konflikt.",
   lsDialog1 = "Bitte wähle einen Edit unten:\n\n",
   lsDialog2 = "Unsigned Edit-Nummer:",
   lsInvalid1 = "Bitte eine gültige Zahl eintragen oder diese Operation annullieren.",
   lsInvalid2 = "Dieser Edit ist eine sogenannte Kleine Änderung. Trotzdem wählen?", // Minoredit
   lsNoRev = "Keine Veränderung gefunden. Besteht die Seite?",
   lsNoXMLHTTP = "Couldn't get XMLHTTP!",
   lsMinor = "K ";
  // LOCALIZABLE STRINGS END
 
  var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : false; // Try to use native XMLHTTP
  if(!xmlhttp && window.ActiveXObject){ // ActiveX XMLHTTP
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    if(!xmlhttp) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
 
  if(!xmlhttp) return alert(lsNoXMLHTTP); // No XMLHTTP
	xmlhttp.open("GET", "/w/api.php?format=xml&action=query&prop=revisions&rvlimit=36&rvcomments&titles=" + aswcGet_tidy_title()); // Get timestamp, user, summary of last 16 edits
  xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState!=4) return;
		if(!xmlhttp) return alert("Error: "+lsNoXMLHTTP + "\n" + xmlhttp.status + ": " + xmlhttp.statusText ); // No XMLHTTP
		var xmldoc = xmlhttp.responseXML;
		// IE workaround suggested by [[User:Olliminatore]]
		if(!xmldoc.documentElement && window.ActiveXObject){ // !FIXME: IE6 can't read XML???
			document.body.style.backgroundColor = "#CCCCFF"; // Debugging aid
			xmldoc = new ActiveXObject("Microsoft.XMLDOM");
			xmldoc.async = false;
			xmldoc.loadXML(xmlhttp.responseText);
		}
		var revisions = xmldoc.documentElement.getElementsByTagName("rev"); // Get the revisions
		if(revisions.length < 1) return alert(lsNoRev); // No revisions
		var t = revisions[0].getAttribute("timestamp").replace(/[^0-9]/g, ""); // Get rid of non-numeric characters in timestamp
		if(t != document.editform.wpEdittime.value) // Detect an edit conflict
			return alert(lsConflict);
		var dialog_text = lsDialog1;
		var edit_data = [];
		var edit_data2 = []; // with minoredits
		var minor = "";
		var is_used;
		var sigdates = sig2ms(get_all_sig_dates_from_textarea());
		for(var n=0; n<revisions.length; ++n){ // Extract edit data and build dialog text
			minor = (revisions[n].getAttribute("minor") != null)? lsMinor : "";
			edit_data[n] = {timestamp: revisions[n].getAttribute("timestamp").replace(/[^0-9]/g, ""),
											 user: revisions[n].getAttribute("user"),
											 comment: revisions[n].getAttribute("comment")};
			is_used = (is_elem_of_arr(timestamp2ms(edit_data[n].timestamp), sigdates)) ? '(used) ': '';
			dialog_text += ("[" + n.toString(36).toUpperCase() + "] " + edit_data[n].timestamp.replace(/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/g, "$1-$2-$3 $4:$5:$6") + " " + is_used +
			 edit_data[n].user + ": " + minor + edit_data[n].comment).substring(0, 80) + "\n";
			edit_data2[n] = edit_data[n];
		}
 
		while(true){
			if(edit_data.length == 1) var unsigned_edit = 0; // no choice
			else if(is_gecko) // for Mozilla, def in wikibits.js
				var unsigned_edit = prompt(dialog_text + "\n" + lsDialog2, "0");
			else{ // for IE or other
				alert(dialog_text);
				var unsigned_edit = prompt(lsDialog2, "0");
			}
			if(unsigned_edit == null) return; // Cancel button
			else if(isNaN(unsigned_edit = parseInt(unsigned_edit, 36))) return alert(lsInvalid1); // Non-numeric input
			else if(!(edit_data[unsigned_edit])){
				if(confirm(lsInvalid2)){ // Non-existent edit
					unsigned_edit = edit_data2[unsigned_edit];
				}	else return;
			}	else unsigned_edit = edit_data[unsigned_edit];
			t = unsigned_edit.timestamp; // So the full name doesn't have to be used
 
			// LOCALIZABLE STRINGS START (current de:)
			var year = t.substring(0, 4);
			var month = t.substring(4, 6);
			var day = (t.substring(6, 8) - 0);
			var hours = parseInt(t.substring(8, 10), 10);
			// Add Timezone offset
			if(hours > 21){ // if not same day (in de:) calc next day
				// get UTC time in msec
				nd = new Date(year, month, day, hours).getTime();
				// create new Date object for different
				// using timezone offset
				nd = new Date(nd + (3600000*fetchTimezoneBackup().substring(0,2)));
				year = nd.getFullYear();
				month = nd.getMonth();
				day = nd.getDate();
				hours = nd.getHours();
			}
			else hours += parseInt(fetchTimezoneBackup().substring(0,2), 10);
 
			// select matching time zone for date
			// var tzdiff = new Date(Date.UTC(year, month, day, hours, 0, 0, 0));
			var tzdiff = new Date(year, month, day, hours, 0, 0, 0);
			var tzoff = (-1) * tzdiff.getTimezoneOffset();
			var tzcode = (tzoff == 120)? "CEST" : "CET";
 
			insertTags("{{unsigned|" + unsigned_edit.user + "|" + hours + ":" + t.substring(10, 12) + ", " + day + ". " + lsMonth_names[month - 1] + " " + year + " (" + tzcode + ")}}", "", ""); // Format and insert the tag. The data returned by app.php is UTC, FetchTimezone is needed.
 
			// LOCALIZABLE STRINGS END
			return;
		}
	};
	xmlhttp.send(null);
};
 
$(function(){ // put onload in wikibits.js
// From [[:en:Wikipedia:WikiProject_User_scripts/Scripts/Add_LI_link]]
	function aswcAddlilink(tabs, url, name, id, title, key){
	 var na = document.createElement('a');
	 na.href = url;
	 na.appendChild(document.createTextNode(name));
	 var li = document.createElement('li');
	 if(id) li.id = id;
	 li.appendChild(na);
	 //tabs.appendChild(li); // to end
	 ta_hi = document.getElementById('ca-history'); // to versions tab
	 if(ta_hi) tabs.insertBefore(li, ta_hi);
	 if(id){
		 if(key && title) ta[id] = [key, title];
		 else if(key) ta[id] = [key, ''];
		 else if(title) ta[id] = ['', title];
	 }
	 akeytt(); // re-render the title and accesskeys from existing code in wikibits.js
	 return li;
	};
 
	if(!wgIsArticle)
		aswcAddlilink(document.getElementById('p-cactions').getElementsByTagName('ul')[0], "javascript:addSigWikiCode();", /* LOCALIZABLE STRINGS START */ "Unsigniert" , "ca-unsigned", "Markiere einen unsignierten Kommentar", "" /* LOCALIZABLE STRINGS END */);
});
// Above by Invitatious. Dual-licensed under the terms of the GFDL v1.2 or the GPL v2.
 
// in [-]HH:MM format...
// won't yet work with non-even tzs
function fetchTimezoneBackup() {
        // FIXME: work around Safari bug
        var localclock = new Date();
        // returns negative offset from GMT in minutes
        var tzRaw = localclock.getTimezoneOffset();
        var tzHour = Math.floor( Math.abs(tzRaw) / 60);
        var tzMin = Math.abs(tzRaw) % 60;
        var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour +
                ":" + ((tzMin < 10) ? "0" : "") + tzMin;
        return tzString;
}
 
//</nowiki></pre>