Created
November 13, 2016 02:47
-
-
Save kickbase/a0751b98d26a7d52113e96b3fce2e5d4 to your computer and use it in GitHub Desktop.
[Mac] [JXA] replace selected text to sudden death wrapped
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run(input, parameters) { | |
String.prototype.getLengthByte = function () { | |
var self = this, | |
count = 0, | |
char, | |
i; | |
for (i = 0; i < self.length; i++) { | |
char = self.charCodeAt(i); | |
if ((char >= 0x0 && char < 0x81) || (char == 0xf8f0) || | |
(char >= 0xff61 && char < 0xffa0) || (char >= 0xf8f1 && char < 0xf8f4)) { | |
count += 1; | |
} else { | |
count += 2; | |
} | |
} | |
return count; | |
}; | |
String.prototype.repeat = function (n) { | |
return new Array(n + 1).join(this); | |
}; | |
function suddenDeath(str) { | |
var len = Math.floor(str.getLengthByte() / 2); | |
return "_" + ("人".repeat(len + 2)) + "_\n" + | |
"> " + str + " <\n" + | |
" ̄Y^" + ("Y^".repeat(len)) + " ̄"; | |
} | |
return suddenDeath(input.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment