所以我一直在四处寻找尝试获得一个1337翻译,我可以理解足够的工作到一个jQuery插件,我觉得我很接近..但我'不是100%我做错了什么..我非常确定我有什么..不是一个jQuery插件..所以我希望有人能帮我弄清楚我做错了什么。jQuery/Javascript的leet翻译插件
(function($){
$.fn.leet = function() {
// Create the Phrase translations arrays
var PhrasesEnglish =
new Array('crap', 'dude', 'hacker',
'hacks', 'you', 'cool', 'oh my god',
'fear', 'power', 'own',
'what the hell', 'elite', 'for the win',
'oh really', 'good game');
var PhrasesLeet =
new Array('carp', 'dood', 'haxor', 'hax', 'joo',
'kewl', 'omg', 'ph43', 'powwah', 'pwn',
'wth', 'leet', 'ftw', 'o rly', 'gg');
// Create the Letter translations arrays
var LettersEnglish =
new Array('n', 'b', 'k', 'd', 'e', 'f', 'g', 'h',
'p', 'm', 'r', 'l', 'o', 'q', 's', 't',
'u', 'x', 'w', 'y', 'z', 'c', 'a', 'j',
'i', 'v', ' ');
var LettersLeet =
new Array('/\\/', '|}', '|X', '[)', '3', '|=', 'gee', '|-|',
'|*', '(\\/)', '|2', '1', '()', '0', '$', '+',
'|_|', '><', '\\X/', '\'/', '2', '<', '/\\', '_|',
'|', '\\/', ' ');
// Translates text in input area to/from leet speak
function translateText() {
var inputString = document.getElementById('input').value;
if (document.getElementById('conversionType').value == "e") {
for (i = 0; i < PhrasesEnglish.length; ++i)
inputString = inputString.replace(
new RegExp(PhrasesEnglish[i], "gi"),
PhrasesLeet[i]
);
for (i = 0; i < LettersEnglish.length; ++i)
inputString = inputString.replace(
new RegExp(LettersEnglish[i], "gi"),
LettersLeet[i]
);
}
else {
for (i = 0; i < LettersLeet.length; ++i)
inputString = inputString.replace(
new RegExp(RegExp.escape(LettersLeet[i]), "g"),
LettersEnglish[i]
);
for (i = 0; i < PhrasesLeet.length; ++i)
inputString = inputString.replace(
new RegExp(RegExp.escape(PhrasesLeet[i]), "g"),
PhrasesEnglish[i]
);
}
document.getElementById('input').value = inputString;
}
return this;
};
})(jQuery);
这就是我尽可能的插件了,请不要忘记我发现这个网上,我试图返工..所以HTML是有点可怕的ATM ..
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="leet.js"></script>
<script>
$(function() {
$("div").leet();
});
</script>
<body>
<div style="border: solid 1px Black;
padding: 5px; width: 350px;
background-color: White;">
<label for="input">
Enter message here:</label><br />
<textarea id="input" name="input" rows="10" cols="40"
style="font-weight: bold;
background-image: url('leetBG.png');
background-attachment: fixed;
background-position: 160px 165px;
background-repeat: no-repeat;"></textarea>
<br />
<input type="submit" value="Translate"
onclick="translateText();" />
<select id="conversionType">
<option value="e">English -> 1337</option>
<option value="3">1337 -> English</option>
</select>
</div>
</body>
你真的应该使用一个对象而不是两个数组作为单词。 – epascarello 2012-02-21 19:40:05
好吧,我敢肯定这可能是要走的路..就像我说的..我在网上找到了这个,我正在尝试将它重写为一个jQuery插件..但我还没那么棒!所以真的有什么帮助 – 2012-02-21 19:42:05
也不是100%,但它可能是更好的做法(?)创建数组字面而不是作为一个对象,所以变量PhrasesEnglish = ['等等','等等','等等'... ]。 – 2012-02-21 20:39:43