Skip to content

Commit

Permalink
Added defaulting to utf-8 if there are non-Vyxal characters
Browse files Browse the repository at this point in the history
And one other thing ;)
  • Loading branch information
chunkybanana committed Jun 26, 2021
1 parent fffb6c0 commit e8c16d3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions templates/main.html
Expand Up @@ -164,9 +164,12 @@

function updateCount() {
var byte_box = document.getElementById("code-count");
var code = document.getElementById("code").value.length;

byte_box.innerText = `Code: ${code} byte` + "s".repeat(code != 1);
var code = document.getElementById("code").value;
if(code.every(x => codepage.includes(x)){
byte_box.innerText = `Code: ${code.length} byte` + "s".repeat(code != 1);
} else {
byte_box.innerText = `Code: ${new Blob([code]).size} byte` + "s".repeat(code.length != 1) + ' (UTF-8)';
}
}

function generateURL() {
Expand Down Expand Up @@ -196,15 +199,17 @@
flag_appendage = " `" + flags + "`,"
}
var output = ""
var utfable = code.every(x => codepage.includes(x));
var len = codepage?code.length:new Blob([code]).size
switch (shareType) {
case "permalink":
output = url;
break;
case "cmc":
output = `[Vyxal, ${code.length} byte${"s".repeat(code.length != 1)}](${url})`;
output = `[Vyxal, ${len} byte${"s".repeat(code.length != 1)}${utfable?'':' (UTF-8)'}](${url})`;
break;
case "post-template":
output = `# [Vyxal](https://github.com/Lyxal/Vyxal)${flag_appendage} ${code.length} byte${"s".repeat(code.length != 1)}
output = `# [Vyxal](https://github.com/Lyxal/Vyxal)${flag_appendage} ${len} byte${"s".repeat(len != 1)}${utfable?'':' (UTF-8)'}
\`\`\`
${code}
Expand Down Expand Up @@ -367,6 +372,7 @@
output.value = res.stdout;
extra.value = res.stderr;
run.innerHTML = '<svg style="width:24px;height:24px" viewBox="0 0 24 24"><path fill="currentColor" d="M8.5,8.64L13.77,12L8.5,15.36V8.64M6.5,5V19L17.5,12" /></svg>';
if(code == 'lyxal') location.href = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
expandBoxes();
});
} else {
Expand Down

0 comments on commit e8c16d3

Please sign in to comment.