Skip to content

Instantly share code, notes, and snippets.

@kickbase
Created November 13, 2016 02:47
Show Gist options
  • Save kickbase/a0751b98d26a7d52113e96b3fce2e5d4 to your computer and use it in GitHub Desktop.
Save kickbase/a0751b98d26a7d52113e96b3fce2e5d4 to your computer and use it in GitHub Desktop.
[Mac] [JXA] replace selected text to sudden death wrapped
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