Benutzer:J*/vector.js: Unterschied zwischen den Versionen

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
K
K (-debug, +Formatierung)
Zeile 57: Zeile 57:
  
 
/* Zeug für die Buschtrommel */
 
/* Zeug für die Buschtrommel */
 +
 
function serialize (obj)
 
function serialize (obj)
 
{
 
{
    if (obj == null)
+
if (obj == null)
        return "z";
+
return "z";
  
    switch (typeof obj)
+
switch (typeof obj)
    {
+
{
        case "string":
+
case "string":
            return "s"+escape(obj)
+
return "s"+escape(obj);
            break;
+
break;
        case "number":
+
case "number":
            return "n"+escape(String(obj));
+
return "n"+escape(String(obj));
            break;
+
break;
        case "object":
+
case "object":
            var arr = [];
+
var arr = [];
            for (var k in obj)
+
for (var k in obj)
            {
+
{
                arr.push(serialize(k) + "=" + serialize(obj[k]))
+
arr.push(serialize(k) + "=" + serialize(obj[k]));
            }
+
}
            if (obj instanceof Array)
+
if (obj instanceof Array)
                return "a"+escape(arr.join("&"));
+
return "a"+escape(arr.join("&"));
            else
+
else
                return "o"+escape(arr.join("&"));
+
return "o"+escape(arr.join("&"));
 
+
break;
        default:
+
default:
            throw "Cannot serialize " + (typeof obj) + " type."
+
throw "Cannot serialize " + (typeof obj) + " type.";
    }
+
}
 
}
 
}
  
 
function deserialize (str)
 
function deserialize (str)
 
{
 
{
    var type = str[0]
+
var type = str[0];
    var data = str.substr(1)
+
var data = str.substr(1);
  
    switch(type)
+
switch(type)
    {
+
{
        case "z":
+
case "z":
            return null;
+
return null;
        case "s": //string
+
break;
            return unescape(data);
+
case "s": //string
            break;
+
return unescape(data);
        case "n": //number
+
break;
            if (data == "Infinity")
+
case "n": //number
                return Infinity
+
if (data == "Infinity")
            else if (data == "-Infinity")
+
return Infinity;
                return -Infinity
+
else if (data == "-Infinity")
            else
+
return -Infinity;
                return parseInt(unescape(data));
+
else
            break;
+
return parseInt(unescape(data));
        case "a": // Array
+
break;
        case "o": //Object
+
case "a": // Array
 +
case "o": //Object
 +
var ret = {};
 +
if (type == "a")
 +
ret = [];
  
            var ret = {};
+
var pairs = unescape(data).split("&");
            if (type == "a")
+
for (var i=0; i<pairs.length; i++)
                ret = [];
+
{
           
+
var kv = pairs[i].split("=");
            var pairs = unescape(data).split("&")
+
ret[deserialize(kv[0])] = deserialize(kv[1]);
            for (var i=0; i<pairs.length; i++)
+
}
            {
+
return ret;
                var kv = pairs[i].split("=")
+
break;
                ret[deserialize(kv[0])] = deserialize(kv[1]);
+
default:
            }
+
throw "Cannot deserialize " + type + " type."
            return ret;
+
}
            break;
 
       
 
        default:
 
            throw "Cannot deserialize " + type + " type."
 
    }
 
 
}
 
}
  
 
if (wgPageName=="Spezial:KamelBox")
 
if (wgPageName=="Spezial:KamelBox")
 
{
 
{
    addOnloadHook( function () {
+
addOnloadHook( function () {
        jQuery("#buschtrommel").append("<div id='buschtrommel-log'/>");
+
jQuery("#buschtrommel").append("<div id='buschtrommel-log'/>");
        var oldPrepare = prepare;
+
var oldPrepare = prepare;
        prepare = function (j)
+
prepare = function (j)
        {
+
{
            if (window.log)
+
if (window.log)
                window.log(j);
+
window.log(j);
            else if (console.log)
+
return oldPrepare(j);
                console.log(j);
+
}
            return oldPrepare(j);
+
});
        }
 
    });
 
 
}
 
}
  
Zeile 148: Zeile 146:
 
function saveChatLog ()
 
function saveChatLog ()
 
{
 
{
    document.cookie = "kpChatLog="+serialize(chatLog.log)
+
document.cookie = "kpChatLog="+serialize(chatLog.log);
 
}
 
}
  
 
function loadChatLog ()
 
function loadChatLog ()
 
{
 
{
    chatLog.current = null;
+
chatLog.current = null;
    var cookie = document.cookie.match(/(^|;)\s*kpChatLog=([^;]+);/);
+
var cookie = document.cookie.match(/(^|;)\s*kpChatLog=([^;]+);/);
    try
+
try
    {
+
{
        if (cookie != null)
+
if (cookie != null)
            chatLog.log = deserialize(cookie[2]);     
+
chatLog.log = deserialize(cookie[2]);     
        else
+
else
            throw 1
+
throw 1;
    }
+
}
    catch (e)
+
catch (e)
    {
+
{
        chatLog.log = [];
+
chatLog.log = [];
    }
+
}
 
}
 
}
  
 
function log (d)
 
function log (d)
 
{
 
{
    if (chatLog.log.length > 0 && parseInt(chatLog.log[chatLog.log.length-1].last_ts) >= parseInt(d.time) )
+
if (chatLog.log.length > 0 && parseInt(chatLog.log[chatLog.log.length-1].last_ts) >= parseInt(d.time) )
    {
+
{
        // do not log as it is already logged
+
// do not log as it is already logged
        // switch to append mode
+
// switch to append mode
        console.log("skipping",d);
+
chatLog.current = chatLog.log[chatLog.log.length-1];
        chatLog.current = chatLog.log[chatLog.log.length-1]
+
listChatLogs();
        listChatLogs();
+
return;
        return;
+
}
    }
+
else if (chatLog.current == null || chatLog.log.length == 0)
    else if (chatLog.current == null || chatLog.log.length == 0)
+
{
    {
+
// init
        // init
+
chatLog.current = {data: []};
        console.log("init");
+
chatLog.log.push(chatLog.current);
        chatLog.current = {data: []};
+
}
        chatLog.log.push(chatLog.current);
 
    }
 
  
    chatLog.current.last_ts = d.time;
+
chatLog.current.last_ts = d.time;
    chatLog.current.data.push(d);
+
chatLog.current.data.push(d);
    saveChatLog();
+
saveChatLog();
    listChatLogs();
+
listChatLogs();
 
}
 
}
  
 
function showChatLog(idx)
 
function showChatLog(idx)
 
{
 
{
    str = "";
+
str = "";
    var entries = chatLog.log[idx].data;
+
var entries = chatLog.log[idx].data;
    for (var i in entries)
+
for (var i in entries)
    {
+
{
        str += prepareLog(entries[i]);
+
str += prepareLog(entries[i]);
    }
+
}
    newwin = window.open();
+
newwin = window.open();
    newwin.document.write(str);
+
newwin.document.write(str);
 
}
 
}
  
 
function listChatLogs ()
 
function listChatLogs ()
 
{
 
{
    jQuery("#buschtrommel-log").empty()
+
jQuery("#buschtrommel-log").empty();
    for(var i in chatLog.log)
+
for(var i in chatLog.log)
    {
+
{
        var time = new Date();
+
var time = new Date();
        time.setTime(chatLog.log[i].data[0].time);
+
time.setTime(chatLog.log[i].data[0].time);
        var showButton = jQuery("<input type='button' onclick='showChatLog("+parseInt(i)+")' value='Anzeigen'>");
+
var showButton = jQuery("<input type='button' onclick='showChatLog("+parseInt(i)+")' value='Anzeigen'>");
        var deleteButton = jQuery("<input type='button' onclick='deleteChatLog("+parseInt(i)+")' value='Löschen'>");
+
var deleteButton = jQuery("<input type='button' onclick='deleteChatLog("+parseInt(i)+")' value='Löschen'>");
        var container = jQuery("<div/>")
+
var container = jQuery("<div/>");
        container.append(time.toLocaleString());
+
container.append(time.toLocaleString());
        container.append(showButton);
+
container.append(showButton);
        container.append(deleteButton);
+
container.append(deleteButton);
        jQuery("#buschtrommel-log").append(container)
+
jQuery("#buschtrommel-log").append(container);
    }
+
}
 
}
 
}
  
 
function deleteChatLog(i)
 
function deleteChatLog(i)
 
{
 
{
    chatLog.log.splice(i,1);
+
chatLog.log.splice(i,1);
    saveChatLog();
+
saveChatLog();
    loadChatLog();
+
loadChatLog();
    listChatLogs();
+
listChatLogs();
 
}
 
}
  
        function prepareLog(response) {
+
// fast unverändert aus der Kamelbox kopiert
          var d = new Date();
+
function prepareLog(response)
          d.setTime(response.time);
+
{
          var currentHours  = ( d.getHours() < 10 ? "0" : "" ) + d.getHours();
+
var d = new Date();
          var currentMinutes = ( d.getMinutes() < 10 ? "0" : "" ) + d.getMinutes();
+
d.setTime(response.time);
          var mytime = currentHours+':'+currentMinutes;
+
var currentHours  = ( d.getHours() < 10 ? "0" : "" ) + d.getHours();
          if (mytime != oldmytime) {
+
var currentMinutes = ( d.getMinutes() < 10 ? "0" : "" ) + d.getMinutes();
          oldmytime = mytime;
+
var mytime = currentHours+':'+currentMinutes;
          } else {
+
if (mytime != oldmytime) {
          mytime = "<span style='color:#aaa;'>≀</span>" ;
+
oldmytime = mytime;
          };
+
} else {
          var tempnick = response.nickname;
+
mytime = "<span style='color:#aaa;'>≀</span>" ;
          var tempnick2 = " '@"+response.nickname+" '";
+
};
          if (tempnick.length > 16)  {
+
var tempnick = response.nickname;
              tempnick = tempnick.substr(0, 16)+"~"
+
var tempnick2 = " '@"+response.nickname+" '";
          }
+
if (tempnick.length > 16)  {
          if ((tempnick != '&nbsp;') && (tempnick != wgUserName ) ){  
+
tempnick = tempnick.substr(0, 16)+"~"
          var nick = '<span style="color:#00137F; cursor:pointer;" onclick="document.Trommel.message.value += '+tempnick2+';document.Trommel.message.focus()" title="Nachricht an '+response.nickname+'">'+tempnick+'</span>';
+
}
          } else if (tempnick == wgUserName ){
+
if ((tempnick != '&nbsp;') && (tempnick != wgUserName ) ){  
            nick = '<span style="color:#7F0000;">'+tempnick+'</span>';
+
var nick = '<span style="color:#00137F; cursor:pointer;" onclick="document.Trommel.message.value += '+tempnick2+';document.Trommel.message.focus()" title="Nachricht an '+response.nickname+'">'+tempnick+'</span>';
            } else {
+
} else if (tempnick == wgUserName ){
            var nick = '&nbsp;'  ;
+
nick = '<span style="color:#7F0000;">'+tempnick+'</span>';
          }   
+
} else {
          var checkkamel = response.message;
+
var nick = '&nbsp;'  ;
          var kamel = wgUserName+" ";
+
}   
          var kamel2 = wgUserName+":";
+
var checkkamel = response.message;
          if ((checkkamel.indexOf (kamel) != -1 || checkkamel.indexOf (kamel2) != -1) && tempnick != '&nbsp;' ) {
+
var kamel = wgUserName+" ";
          var string = '<table width="100%" cellspacing="0" cellpadding="0" class="buschtrommel-list">'
+
var kamel2 = wgUserName+":";
              + '<tr><td width="35px" class="buschtrommel-list-time" valign="top" align="right">'+mytime+'</td>'
+
if ((checkkamel.indexOf (kamel) != -1 || checkkamel.indexOf (kamel2) != -1) && tempnick != '&nbsp;' ) {
              + '<td width="115px" style="text-align:right;" class="buschtrommel-kamelname" valign="top">'+nick+'</td>'
+
var string = '<table width="100%" cellspacing="0" cellpadding="0" class="buschtrommel-list">'
              + '<td class="buschtrommel-list-message"  valign="top"><span style="background-color:#FFFF00;border:1px solid #FFFF00;border-radius:.5em;">'+response.message+'</span></td>'
+
+ '<tr><td width="35px" class="buschtrommel-list-time" valign="top" align="right">'+mytime+'</td>'
              +'</tr></table>';
+
+ '<td width="115px" style="text-align:right;" class="buschtrommel-kamelname" valign="top">'+nick+'</td>'
          } else {
+
+ '<td class="buschtrommel-list-message"  valign="top"><span style="background-color:#FFFF00;border:1px solid #FFFF00;border-radius:.5em;">'+response.message+'</span></td>'
          var string = '<table width="100%" cellspacing="0" cellpadding="0" class="buschtrommel-list">'
+
+'</tr></table>';
              + '<tr><td width="35px" class="buschtrommel-list-time" valign="top" align="right">'+mytime+'</td>'
+
} else {
              + '<td width="115px" style="text-align:right;" class="buschtrommel-kamelname" valign="top">'+nick+'</td>'
+
var string = '<table width="100%" cellspacing="0" cellpadding="0" class="buschtrommel-list">'
              + '<td class="buschtrommel-list-message" style="padding-left:.3em;" valign="top">'+response.message+'</td>'
+
+ '<tr><td width="35px" class="buschtrommel-list-time" valign="top" align="right">'+mytime+'</td>'
              +'</tr></table>';
+
+ '<td width="115px" style="text-align:right;" class="buschtrommel-kamelname" valign="top">'+nick+'</td>'
              }
+
+ '<td class="buschtrommel-list-message" style="padding-left:.3em;" valign="top">'+response.message+'</td>'
          if (tempnick == "&nbsp;") {
+
+'</tr></table>';
            tempnick="";
+
}
            };
+
if (tempnick == "&nbsp;") {
         
+
tempnick="";
          if (tempnick.indexOf("&" != -1)) {
+
};
          tempnick = tempnick.replace(/&Auml;/g, "Ä");
+
 
          tempnick = tempnick.replace(/&auml;/g, "ä");
+
if (tempnick.indexOf("&" != -1)) {
          tempnick = tempnick.replace(/&ouml;/g, "ö");
+
tempnick = tempnick.replace(/&Auml;/g, "Ä");
          tempnick = tempnick.replace(/&Ouml;/g, "Ö");
+
tempnick = tempnick.replace(/&auml;/g, "ä");
          tempnick = tempnick.replace(/&uuml;/g, "ü");
+
tempnick = tempnick.replace(/&ouml;/g, "ö");
          tempnick = tempnick.replace(/&Uuml;/g, "Ü");
+
tempnick = tempnick.replace(/&Ouml;/g, "Ö");
          tempnick = tempnick.replace(/&szlig;/g, "ß");
+
tempnick = tempnick.replace(/&uuml;/g, "ü");
          }
+
tempnick = tempnick.replace(/&Uuml;/g, "Ü");
          return string;
+
tempnick = tempnick.replace(/&szlig;/g, "ß");
        }
+
}
 +
return string;
 +
}

Version vom 12. Dezember 2010, 14:19 Uhr

/* für's Bürokratenspiel */
function bksp ()
{
	if (wgPageName.indexOf("Projekt:Bürokratenspiel") != -1 )
	{
		var t = wgTitle.split("/");
		var e = (wgAction = "edit") ? "$ " : "";
		document.title = t[t.length-1];
	}
}
addOnloadHook(bksp);

/* Zusammenfassungs-Warnung */

addOnloadHook( function () {
	jQuery("#wpSummary, #wpTextbox1").bind("keypress", function() {
		jQuery("#wpSummary").css("background-color","#ffffff");
		try {
			clearInterval(summaryWarnInterval);
			summaryWarnInterval = null;
		}
		catch (e) {}
		summaryWarnState = -1;
	});

	jQuery("#editform").bind("submit", function (e) {

		if ( e.originalEvent.explicitOriginalTarget != jQuery("#wpSave")[0] )
			return true;

		if (! jQuery("#wpSummary").val().replace(/^\s+/,"").replace(/\s+$/,"").replace(/\/\*.*?\*\//,"") && summaryWarnState == -1)
		{
                        jQuery("#wpSummary").focus();
			summaryWarnInterval = window.setInterval(summaryWarn,70);
			return false;
		}

		return true;
	});
});

summaryWarnState = -1;
summaryWarnInterval = null;

function summaryWarn() 
{
	summaryWarnState ++;
	if (summaryWarnState % 2 == 0)
		jQuery("#wpSummary").css("background-color","#ffff99");
	else
		jQuery("#wpSummary").css("background-color","#ffffff");

	if (summaryWarnState > 11)
		clearInterval(summaryWarnInterval);
}


/* Zeug für die Buschtrommel */

function serialize (obj)
{
	if (obj == null)
		return "z";

	switch (typeof obj)
	{
		case "string":
			return "s"+escape(obj);
			break;
		case "number":
			return "n"+escape(String(obj));
			break;
		case "object":
			var arr = [];
			for (var k in obj)
			{
				arr.push(serialize(k) + "=" + serialize(obj[k]));
			}
			if (obj instanceof Array)
				return "a"+escape(arr.join("&"));
			else
				return "o"+escape(arr.join("&"));
			break;
		default:
			throw "Cannot serialize " + (typeof obj) + " type.";
	}
}

function deserialize (str)
{
	var type = str[0];
	var data = str.substr(1);

	switch(type)
	{
		case "z":
			return null;
			break;
		case "s": //string
			return unescape(data);
			break;
		case "n": //number
			if (data == "Infinity")
				return Infinity;
			else if (data == "-Infinity")
				return -Infinity;
			else
				return parseInt(unescape(data));
			break;
		case "a": // Array
		case "o": //Object
			var ret = {};
			if (type == "a")
				ret = [];

			var pairs = unescape(data).split("&");
			for (var i=0; i<pairs.length; i++)
			{
				var kv = pairs[i].split("=");
				ret[deserialize(kv[0])] = deserialize(kv[1]);
			}
			return ret;
			break;
		default:
			throw "Cannot deserialize " + type + " type."
	}
}

if (wgPageName=="Spezial:KamelBox")
{
	addOnloadHook( function () {
		jQuery("#buschtrommel").append("<div id='buschtrommel-log'/>");
		var oldPrepare = prepare;
		prepare = function (j)
		{
			if (window.log)
				window.log(j);
			return oldPrepare(j);
		}
	});
}

chatLog = {log:[]};
loadChatLog();

function saveChatLog ()
{
	document.cookie = "kpChatLog="+serialize(chatLog.log);
}

function loadChatLog ()
{
	chatLog.current = null;
	var cookie = document.cookie.match(/(^|;)\s*kpChatLog=([^;]+);/);
	try
	{
		if (cookie != null)
			chatLog.log = deserialize(cookie[2]);    
		else
			throw 1;
	}
	catch (e)
	{
		chatLog.log = [];
	}
}

function log (d)
{
	if (chatLog.log.length > 0 && parseInt(chatLog.log[chatLog.log.length-1].last_ts) >= parseInt(d.time) )
	{
		// do not log as it is already logged
		// switch to append mode
		chatLog.current = chatLog.log[chatLog.log.length-1];
		listChatLogs();
		return;
	}
	else if (chatLog.current == null || chatLog.log.length == 0)
	{
		// init
		chatLog.current = {data: []};
		chatLog.log.push(chatLog.current);
	}

	chatLog.current.last_ts = d.time;
	chatLog.current.data.push(d);
	saveChatLog();
	listChatLogs();
}

function showChatLog(idx)
{
	str = "";
	var entries = chatLog.log[idx].data;
	for (var i in entries)
	{
		str += prepareLog(entries[i]);
	}
	newwin = window.open();
	newwin.document.write(str);
}

function listChatLogs ()
{
	jQuery("#buschtrommel-log").empty();
	for(var i in chatLog.log)
	{
		var time = new Date();
		time.setTime(chatLog.log[i].data[0].time);
		var showButton = jQuery("<input type='button' onclick='showChatLog("+parseInt(i)+")' value='Anzeigen'>");
		var deleteButton = jQuery("<input type='button' onclick='deleteChatLog("+parseInt(i)+")' value='Löschen'>");
		var container = jQuery("<div/>");
		container.append(time.toLocaleString());
		container.append(showButton);
		container.append(deleteButton);
		jQuery("#buschtrommel-log").append(container);
	}
}

function deleteChatLog(i)
{
	chatLog.log.splice(i,1);
	saveChatLog();
	loadChatLog();
	listChatLogs();
}

// fast unverändert aus der Kamelbox kopiert
function prepareLog(response)
{
	var d = new Date();
	d.setTime(response.time);
	var currentHours   = ( d.getHours() < 10 ? "0" : "" ) + d.getHours();
	var currentMinutes = ( d.getMinutes() < 10 ? "0" : "" ) + d.getMinutes();
	var mytime = currentHours+':'+currentMinutes;
	if (mytime != oldmytime) {
		oldmytime = mytime;
	} else {
		mytime = "<span style='color:#aaa;'>≀</span>" ;
	};
	var tempnick = response.nickname;
	var tempnick2 = " '@"+response.nickname+" '";
	if (tempnick.length > 16)   {
		tempnick = tempnick.substr(0, 16)+"~"
	}
	if ((tempnick != '&nbsp;') && (tempnick != wgUserName ) ){ 
		var nick = '<span style="color:#00137F; cursor:pointer;" onclick="document.Trommel.message.value += '+tempnick2+';document.Trommel.message.focus()" title="Nachricht an '+response.nickname+'">'+tempnick+'</span>';
	} else if (tempnick == wgUserName ){
		nick = '<span style="color:#7F0000;">'+tempnick+'</span>';
	} else {
		var nick = '&nbsp;'   ;
	}  
	var checkkamel = response.message;
	var kamel = wgUserName+" ";
	var kamel2 = wgUserName+":";
	if ((checkkamel.indexOf (kamel) != -1 || checkkamel.indexOf (kamel2) != -1) && tempnick != '&nbsp;' ) {
		var string = '<table width="100%" cellspacing="0" cellpadding="0" class="buschtrommel-list">'
			+ '<tr><td width="35px" class="buschtrommel-list-time" valign="top" align="right">'+mytime+'</td>'
			+ '<td width="115px" style="text-align:right;" class="buschtrommel-kamelname" valign="top">'+nick+'</td>'
			+ '<td class="buschtrommel-list-message"  valign="top"><span style="background-color:#FFFF00;border:1px solid #FFFF00;border-radius:.5em;">'+response.message+'</span></td>'
			+'</tr></table>';
	} else {
		var string = '<table width="100%" cellspacing="0" cellpadding="0" class="buschtrommel-list">'
			+ '<tr><td width="35px" class="buschtrommel-list-time" valign="top" align="right">'+mytime+'</td>'
			+ '<td width="115px" style="text-align:right;" class="buschtrommel-kamelname" valign="top">'+nick+'</td>'
			+ '<td class="buschtrommel-list-message" style="padding-left:.3em;" valign="top">'+response.message+'</td>'
			+'</tr></table>';
	}
	if (tempnick == "&nbsp;") {
		tempnick="";
	};

	if (tempnick.indexOf("&" != -1)) {
		tempnick = tempnick.replace(/&Auml;/g, "Ä");
		tempnick = tempnick.replace(/&auml;/g, "ä");
		tempnick = tempnick.replace(/&ouml;/g, "ö");
		tempnick = tempnick.replace(/&Ouml;/g, "Ö");
		tempnick = tempnick.replace(/&uuml;/g, "ü");
		tempnick = tempnick.replace(/&Uuml;/g, "Ü");
		tempnick = tempnick.replace(/&szlig;/g, "ß");
	}
	return string;
}