Javascript Codes for xkcd.com/unixkcd

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

Yolda
Posts: 3
Joined: Thu Apr 01, 2010 7:06 am UTC

Javascript Codes for xkcd.com/unixkcd

Postby Yolda » Thu Apr 01, 2010 7:11 am UTC

A little debugging and de-obfuscation ;) enjoy

Moved to Coding from individual comics - Fatstaff

Code: Select all


TerminalShell.commands.next = function (a)
{
    xkcdDisplay(a, xkcd.last.num + 1)
};
TerminalShell.commands.previous = TerminalShell.commands.prev = function (a)
{
    xkcdDisplay(a, xkcd.last.num - 1)
};
TerminalShell.commands.first = function (a)
{
    xkcdDisplay(a, 1)
};
TerminalShell.commands.latest = TerminalShell.commands.last = function (a)
{
    xkcdDisplay(a, xkcd.latest.num)
};
TerminalShell.commands.random = function (a)
{
    xkcdDisplay(a, getRandomInt(1, xkcd.latest.num))
};
TerminalShell.commands["goto"] = function (a, b)
{
    $("#screen").one("cli-ready", function (c)
    {
        a.print('Did you mean "display"?')
    });
    xkcdDisplay(a, 292)
};


TerminalShell.commands.cd = function (a, b)
{
    if (b in this.pwd)
    {
        if (this.pwd[b].type == "dir")
        {
            this.pwd[b].enter(a)
        }
        else
        {
            if (this.pwd[b].type == "file")
            {
                a.print("cd: " + b + ": Not a directory")
            }
        }
    }
    else
    {
        a.print("cd: " + b + ": No such file or directory")
    }
};
TerminalShell.commands.ls = function (a, b)
{
    name_list = $("<ul>");
    $.each(this.pwd, function (c, d)
    {
        if (d.type == "dir")
        {
            c += "/"
        }
        name_list.append($("<li>").text(c))
    });
    a.print(name_list)
};
TerminalShell.commands.cat = function (a, b)
{
    if (b in this.pwd)
    {
        if (this.pwd[b].type == "file")
        {
            this.pwd[b].read(a)
        }
        else
        {
            if (this.pwd[b].type == "dir")
            {
                a.print("cat: " + b + ": Is a directory")
            }
        }
    }
    else
    {
        if (pathFilename(b) == "alt.txt")
        {
            a.setWorking(true);
            num = Number(b.match(/^\d+/));
            xkcd.get(num, function (c)
            {
                a.print(c.alt);
                a.setWorking(false)
            }, function ()
            {
                a.print($("<p>").addClass("error").text('cat: "' + b + '": No such file or directory.'));
                a.setWorking(false)
            })
        }
        else
        {
            a.print("You're a kitty!")
        }
    }
};
TerminalShell.commands.reddit = function (c, b)
{
    b = Number(b);
    if (b)
    {
        a = "http://xkcd.com/" + b + "/"
    }
    else
    {
        var a = window.location
    }
    c.print($('<iframe src="http://www.reddit.com/static/button/button1.html?width=140&url=' + encodeURIComponent(a) + '&newwindow=1" height="22" width="140" scrolling="no" frameborder="0"></iframe>'))
};
TerminalShell.commands["apt-get"] = function (c, d, a)
{
    if ((a != "sudo") && (d in {
        update: true,
        upgrade: true,
        "dist-upgrade": true
    }))
    {
        c.print("E: Unable to lock the administration directory, are you root?")
    }
    else
    {
        if (d == "update")
        {
            c.print("Reading package lists... Done")
        }
        else
        {
            if (d == "upgrade")
            {
                if (($.browser.name == "msie") || ($.browser.name == "firefox" || $.browser.versionX < 3))
                {
                    c.print($("<p>").append($("<a>").attr("href", "http://abetterbrowser.org/").text("To complete installation, click here.")))
                }
                else
                {
                    c.print("This looks pretty good to me.")
                }
            }
            else
            {
                if (d == "dist-upgrade")
                {
                    var e =
                    {
                        win: "Windows",
                        mac: "OS X",
                        linux: "Linux"
                    };
                    var b = $.os.name;
                    if (b in e)
                    {
                        b = e[b]
                    }
                    else
                    {
                        b = "something fancy"
                    }
                    c.print("You are already running " + b + ".")
                }
                else
                {
                    if (d == "moo")
                    {
                        c.print("        (__)");
                        c.print("        (oo)");
                        c.print("  /------\\/ ");
                        c.print(" / |    ||  ");
                        c.print("*  /\\---/\\  ");
                        c.print("   ~~   ~~  ");
                        c.print('...."Have you mooed today?"...')
                    }
                    else
                    {
                        if (!d)
                        {
                            c.print("This APT has Super Cow Powers.")
                        }
                        else
                        {
                            c.print("E: Invalid operation " + d)
                        }
                    }
                }
            }
        }
    }
};
TerminalShell.commands.sudo = function (a)
{
    var c = Array.prototype.slice.call(arguments);
    c.shift();
    if (c.join(" ") == "make me a sandwich")
    {
        a.print("Okay.")
    }
    else
    {
        var b = c.shift();
        c.unshift(a);
        c.push("sudo");
        if (b in TerminalShell.commands)
        {
            this.commands[b].apply(this, c)
        }
        else
        {
            a.print("sudo: " + b + ": command not found")
        }
    }
};

function oneLiner(a, c, b)
{
    if (c in b)
    {
        a.print(b[c]);
        return true
    }
    else
    {
        return false
    }
}
TerminalShell.commands.man = function (a, b)
{
    pages =
    {
        last: "Man, last night was AWESOME.",
        help: "Man, help me out here.",
        next: "Request confirmed; you will be reincarnated as a man next.",
        cat: "You are now riding a half-man half-cat."
    };
    if (!oneLiner(a, b, pages))
    {
        a.print("Oh, I'm sure you can figure it out.")
    }
};

TerminalShell.commands.look = Adventure.look = function (b)
{
    b.print(Adventure.location.description);
    if (Adventure.location.exits)
    {
        b.print();
        var a = [];
        $.each(Adventure.location.exits, function (c, d)
        {
            a.push(c)
        });
        b.print("Exits: " + a.join(", "))
    }
};
TerminalShell.commands.go = Adventure.go = function (a, b)
{
    if (Adventure.location.exits && b in Adventure.location.exits)
    {
        Adventure.goTo(a, Adventure.location.exits[b])
    }
    else
    {
        if (!b)
        {
            a.print("Go where?")
        }
        else
        {
            a.print("You cannot go " + b + ".")
        }
    }
};
TerminalShell.commands.light = function (a, b)
{
    if (b == "lamp")
    {
        if (!Adventure.status.lamp)
        {
            a.print("You set your lamp ablaze.");
            Adventure.status.lamp = true
        }
        else
        {
            a.print("Your lamp is already lit!")
        }
    }
    else
    {
        a.print("Light what?")
    }
};
TerminalShell.commands.help = TerminalShell.commands.halp = function (a)
{
    a.print("That would be cheating!")
};
TerminalShell.fallback = function (a, b)
{
    oneliners =
    {
        "make me a sandwich": "What? Make it yourself.",
        "i read the source code": "<3",
        pwd: "You are in a maze of twisty passages, all alike.",
        lpr: "PC LOAD LETTER",
        "hello joshua": "How about a nice game of Global Thermonuclear War?",
        xyzzy: "Nothing happens.",
        date: "March 32nd"
    };
    oneliners.emacs = "You should really use vim.";
    oneliners.vi = oneliners.vim = "You should really use emacs.";
    b = b.toLowerCase();
    if (!oneLiner(a, b, oneliners))
    {
        if (b == "asl" || b == "a/s/l")
        {
            a.print(randomChoice(["2/AMD64/Server Rack", "328/M/Transylvania", "6/M/Battle School", "48/M/The White House", "7/F/Rapture", "Exactly your age/A gender you're attracted to/Far far away.", "7,831/F/Lothlórien", "42/M/FBI Field Office"]))
        }
        else
        {
            if (b == "find kitten")
            {
                a.print($('<iframe width="800" height="600" src="http://www.robotfindskitten.net/rfk.swf"></iframe>'))
            }
            else
            {
                if (b == "buy stuff")
                {
                    Filesystem.store.enter()
                }
                else
                {
                    $.get("/unixkcd/missing", {
                        cmd: b
                    });
                    return false
                }
            }
        }
    }
    return true
};


User avatar
TheGrimReaper
Posts: 56
Joined: Thu Jan 22, 2009 6:56 am UTC

Re: javascript Codes for April Fools

Postby TheGrimReaper » Thu Apr 01, 2010 8:02 am UTC

Ahaha thanks a lot, this is awesome :D

MQDuck
Posts: 2
Joined: Mon Oct 01, 2007 1:52 pm UTC

Re: javascript Codes for April Fools

Postby MQDuck » Thu Apr 01, 2010 8:57 am UTC

'sudo apt-get upgrade' sends you to a site telling you to choose a better browser if you're running IE *or Firefox*, but not others (line 143). What gives?

zepip
Posts: 1
Joined: Thu Apr 01, 2010 9:38 am UTC

Re: javascript Codes for April Fools

Postby zepip » Thu Apr 01, 2010 9:42 am UTC

Randall, you're awesome.
This is too good to be an April Fool's Joke.
I am purely amazed. :shock:

Landak
Posts: 8
Joined: Mon Mar 10, 2008 8:23 am UTC

Re: javascript Codes for April Fools

Postby Landak » Thu Apr 01, 2010 10:31 am UTC

I love this more than words can say! I quite like the idea of `screen' (o.e.) as a web browser....

null1024
Posts: 38
Joined: Fri Jun 05, 2009 10:20 am UTC
Location: About 4.91E11 feet from the sun.
Contact:

Re: javascript Codes for April Fools

Postby null1024 » Thu Apr 01, 2010 8:22 pm UTC

MQDuck wrote:'sudo apt-get upgrade' sends you to a site telling you to choose a better browser if you're running IE *or Firefox*, but not others (line 143). What gives?

The || is probably supposed to be an && in "($.browser.name == "firefox" || $.browser.versionX < 3)", to tell off people using old versions of FF, but that got typoed.

[or maybe it's part of the joke, especially because FF chugs a bit with this on my machine, while Chrome is running it just fine]
Image

scarletmanuka
Posts: 533
Joined: Wed Oct 17, 2007 4:29 am UTC
Location: Perth, Western Australia

Re: javascript Codes for April Fools

Postby scarletmanuka » Tue Apr 06, 2010 8:44 am UTC

The bits that made me giggle...

The man command
The help command

and these excerpts:

Code: Select all

    oneliners.emacs = "You should really use vim.";
    oneliners.vi = oneliners.vim = "You should really use emacs.";


        if (b == "asl" || b == "a/s/l")
        {
            a.print(randomChoice(["2/AMD64/Server Rack", "328/M/Transylvania", "6/M/Battle School", "48/M/The White House", "7/F/Rapture", "Exactly your age/A gender you're attracted to/Far far away.", "7,831/F/Lothlórien", "42/M/FBI Field Office"]))
        }

although... can someone please explain "7/F/Rapture" to me? I get the others...

Vaayu
Posts: 1
Joined: Fri Jan 29, 2010 7:07 am UTC

Re: javascript Codes for April Fools

Postby Vaayu » Wed Apr 07, 2010 4:53 am UTC

scarletmanuka wrote:although... can someone please explain "7/F/Rapture" to me? I get the others...


Bioshock reference, i presume.

Agent_Irons
Posts: 213
Joined: Wed Sep 10, 2008 3:54 am UTC

Re: javascript Codes for April Fools

Postby Agent_Irons » Thu Apr 08, 2010 6:53 am UTC

null1024 wrote:
MQDuck wrote:'sudo apt-get upgrade' sends you to a site telling you to choose a better browser if you're running IE *or Firefox*, but not others (line 143). What gives?

The || is probably supposed to be an && in "($.browser.name == "firefox" || $.browser.versionX < 3)", to tell off people using old versions of FF, but that got typoed.

[or maybe it's part of the joke, especially because FF chugs a bit with this on my machine, while Chrome is running it just fine]

I tried it and tells me I'm doing just fine. (using FF 3.6.3, but it says the same on Safari, so *shrug*)

User avatar
Sizik
Posts: 1255
Joined: Wed Aug 27, 2008 3:48 am UTC

Re: Javascript Codes for xkcd.com/unixkcd

Postby Sizik » Wed Apr 14, 2010 11:31 pm UTC

harris wrote:can you please explain why you use 2/AMD64/Server Rack.


It's a joke.
she/they
gmalivuk wrote:
King Author wrote:If space (rather, distance) is an illusion, it'd be possible for one meta-me to experience both body's sensory inputs.
Yes. And if wishes were horses, wishing wells would fill up very quickly with drowned horses.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 6 guests