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

aus Kamelopedia, der wüsten Enzyklopädie
Zur Navigation springen Zur Suche springen
K
Zeile 169: Zeile 169:
 
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
Zeile 196: Zeile 196:
 
     for (var i in entries)
 
     for (var i in entries)
 
     {
 
     {
        console.log(entries[i]);
 
 
         str += prepare(entries[i]);
 
         str += prepare(entries[i]);
 
     }
 
     }
Zeile 223: Zeile 222:
 
{
 
{
 
     chatLog.log.pop(i);
 
     chatLog.log.pop(i);
     listChatLogs()
+
    saveChatLog();
 +
     listChatLogs();
 
}
 
}

Version vom 12. Dezember 2010, 12:12 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("&"));

        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;
        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);
            else if (console.log)
                console.log(j);
            return oldPrepare(j);
        }
    });
}

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

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

function loadChatLog ()
{
    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]
        return;
    }
    else if (chatLog.current == null || chatLog.log.length == 0)
    {
        // init
        console.log("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 += prepare(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.pop(i);
    saveChatLog();
    listChatLogs();
}