HTML + Javascript + jQuery + jQuery UI
输入应在文本区域中给出,并且应格式化为一行中的每个命令。这些命令不区分大小写。所有命令均已完全实现。希望您喜欢。
您可以在http://jsfiddle.net/bCBfk/上尝试
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>Useless interpreter</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<style type="text/css">
textarea { height: auto; }
.badshit { color: red; }
.ui-dialog-titlebar-close { display: none; }
</style>
<script type="text/javascript">
String.prototype.startsWith = function(x) {
return this.substring(0, x.length) === x;
};
String.prototype.endsWith = function(x) {
return this.substr(this.length - x.length, x.length) === x;
};
var npe = "<pre>java.lang.NullPointerException\n"
+ " at org.esolangs.wiki.useless.memorymodel.ExistentObjectPool.findObject(ExistentObjectPool.java:684)\n"
+ " at org.esolangs.wiki.useless.interpreter.WhereInstruction.visit(WhereInstruction.java:29)\n"
+ " at org.esolangs.wiki.useless.interpreter.UselessProgram.run(UselessProgram.java:413)\n"
+ " at org.esolangs.wiki.useless.interpreter.Main.main(Main.java:53)</pre>";
var wut = navigator.userAgent + " - " + navigator.language + " - " + navigator.platform + " - Ii?".toLocaleUpperCase();
var wut2 = "";
for (var c = wut.length - 1; c >= 0; c--) {
wut2 += wut.charAt(c);
}
var popupMasterMind;
function killIt() {
clearInterval(popupMasterMind);
$(".dontuseme").remove();
popupMasterMind = null;
}
function spawn() {
var x = $("<div class='dontuseme' title=''><p></p></div>");
$("body").append(x);
x.dialog();
var bw = $("body").innerWidth();
var bh = $("body").innerHeight();
if (bh < 500) bh = 500;
var xw = x.width();
var xh = x.height();
x.parent().css({left: Math.random() * (bw - xw) + "px", top: Math.random() * (bh - xh) + "px"});
}
function dontuseme() {
if (popupMasterMind) return;
spawn();
popupMasterMind = setInterval(spawn, 700);
}
var hasOutput = false;
function clearOutput() {
$("#output").empty();
hasOutput = false;
$("#cc").hide();
}
function out(a) {
$("#output").append($(a));
hasOutput = true;
}
function finish() {
$("#running").hide();
$("#bt").show();
if (hasOutput) $("#cc").show();
}
var annoyingUser = false;
function swap() {
annoyingUser = true;
$("#everything").toggle();
setTimeout(swap, 800);
}
function randomString() {
var r = "";
var f = Math.floor(Math.random() * 12) + 8;
for (var i = 0; i < f; i++) {
r += "ABCDEFGHIJKLMNOPQRSTUVWXYZ.!?0123456789".charAt(Math.floor(Math.random() * 39));
}
return r;
}
var instructions;
function includeInstruction(name) {
name = name.toUpperCase();
if (instructions[name]) return; // Do not add it twice or overwrite existing instructions.
var array = [];
for (var e in instructions) {
array.push(e);
}
var rand = Math.floor(Math.random() * array.length);
//alert(name + ": " + array[rand]);
instructions[name] = instructions[array[rand]];
}
// DONTUSEME(n) are special cases handled elsewhere.
instructions = {
"FAIL": function() { out("<p class='badshit'>Warning: The <blink> tag is obsolete.</p>"); if (!annoyingUser) swap(); return "next"; },
"NOT": function() { out("<p class='badshit'>Warning: The NOT instruction is discouraged because it breaks yor Useless program.</p>"); return "quit"; },
"NEVER": function() { out("<pre>Wild MISSINGNO. appeared!</pre>"); return "next"; },
"IDK": function() { out("<pre>" + {}.idk + "</pre>"); return "next"; },
"BOOM!": function() { $("#everything").empty(); return "quit"; },
"KABOOM!": function() { window.location = "http://answers.yahoo.com/question/index?qid=20110816062515AANqygl"; return "quit"; },
"NO.": function() { finish(); return "quit"; },
"QWAOZAPWQFUOA": function() { out("<p class='badshit'>Sorry, I could not understand <a href='https://www.google.com.br/#q=women+psychology+and+behaviour'>this</a>.</p>"); return "next"; },
"WUT?": function() { out("<p>" + wut2 + "</p>"); return "next"; },
"WHERE?": function() { out(npe); return "next"; },
"HOW?": function() { out("<p class='badshit'>Regular expression parser failed for HTML. Cause: \"ZALGO\"</p>"); return "next"; },
"ILLEGAL": function() { out("<pre>codegolfer is not in the sudoers file. This incident will be reported</pre>"); return "next"; },
"GODEXISTS": function() { out("<p>'GOD' spelled backwards is 'DOG'. A DOG is an animal that does not exists, and by backwarding this, we conclude that GOD exists and is not an animal.</p>"); return "next"; },
"WINDOWS": function() { out("<p><img width='640' height='400' src='http://upload.wikimedia.org/wikipedia/commons/3/3b/Windows_9X_BSOD.png' alt='Sorry, this optional instruction was not implemented. Please, install the service pack.'></p>"); return "next"; },
"NOOP": function() { return "next"; },
"TURINGVSALONZO": function() {
var r = Math.random() * 10;
if (r < 2) return "next";
if (r < 7) return "t" + (Math.random() * 14 + 1) * 1000;
if (r < 9) return "t" + (Math.random() * 50 + 10) * 60 * 1000;
return "quit";
},
"42": function() {
out("<p>Calculating the answer of the life, the universe and everything.</p>");
out("<p>Estimated time is 7.5 million years.</p>");
out("<p>Don't you want to briefly take a coffe while you wait? It will not take long, I promise.</p>");
return "quit";
},
// This is special, as it needs a (surprising) useless parameter, it can't be acessed directly without prior processing, this is why it is lowercase.
"dontuseme": function() { dontuseme(); return "next"; },
// This is special. If the INCLUDE-xxx generates a INCLUDE-yyy instruction, the yyy instruction will have an unknown random generated name.
// Since yyy is random and unknown, it probably won't appear in the input source code, but implement it regardless.
"include-random": function() { includeInstruction(randomString()); return "next"; }
};
function bad(line) {
//alert(line);
out("<p class='badshit'>Syntax error: </p>");
}
function beyondEnd() {
out("<p class='badshit'>Unrecoverable error: Tried to execute code beyond the end or program.</p>");
}
function interpretInstruction(lines, idx) {
if (idx >= lines.length) { beyondEnd(); return; }
// The toUpperCase serves two purposes: Making the language case-insensitive and hiding private implementations as lowercase instructions.
ins = lines[idx].trim().toUpperCase();
var result;
// Special handling for parsing DONTUSEME(n)
if (ins.startsWith("DONTUSEME(") && ins.endsWith(")")) {
try {
parseInt(ins.substring("DONTUSEME(".length, ins.length - 1));
} catch (e) {
bad(ins);
return;
}
ins = "dontuseme";
// Special handling for INCLUDE-xxx
} else if (ins.startsWith("INCLUDE-") && ins.length > 8) {
var name = ins.substring(8);
includeInstruction(name);
ins = "NOOP"; // Already executed, follow-up as noop.
}
// Execute the instruction.
var f = instructions[ins];
if (!f) { bad(ins); return; }
var result = f();
// Move on.
if (result === "quit") return;
var toWait = result === "next" ? 0 : parseInt(result.substring(1));
var ii = idx + 1;
setTimeout(function() {
interpretInstruction(lines, ii);
}, toWait);
}
function startInterpreter() {
$("#bt").hide();
$("#cc").hide();
$("#running").show();
var src = $("#input").val();
var lines = src.split('\n');
interpretInstruction(lines, 0);
}
$(document).ready(function() {
$("#bt").click(startInterpreter);
$("#cc").click(clearOutput);
});
</script>
</head>
<body>
<div id="everything">
<p>Type here your program input:</p>
<textarea id="input" style="width: 400px; height: 150px;"></textarea>
<p>
<button id="bt">Run the program</button>
<span id="running" style="display: none;">Running the program...</span>
</p>
<p>Here is the program output:</p>
<p id="output" class="useless"></p>
<button id="cc" style="display: none;">Clear the output</button>
</div>
</body>
</html>
它有一个新命令:
它是42
计算生命,宇宙和万物的答案的命令。唯一的怪癖是需要750万年才能完成。
其他扰流板:
此项具有几个功能:
- 您真的会讨厌该
FAIL
命令。
-
BOOM!
会让您搞砸“执行单元”。至少Windows DONTUSEME(n)
能够幸免于难。
-
KABOOM!
确实以多种不良方式对世界构成威胁。
-
DONTUSEME(n)
总是打开无限的不可关闭的空窗口,每0.8秒打开一个。但是有一个隐藏的终止开关。
-
DONTUSEME(n)
生存NO.
,FAIL
甚至BOOM!
。我只是无法使它幸存下来KABOOM!
。原因是弹出窗口不起作用,因为这不是单击的结果(而且其他主流浏览器长期禁止使用其他方式创建的弹出窗口),并且由于违反同源政策也无法使用iframe 。
-
INCLUDE-xxx
可以创建任何指令,包括DONTUSEME(n)
或其他INCLUDE-yyy
指令。
- 如果
INCLUDE-xxx
确实生成INCLUDE-yyy
指令,则yyy
名称是随机生成的。如果您使用firebug或类似工具获取生成的命令的名称,则可以使用它。
- 它处理格式错误的语法以及不完整或空的输入。