Skip to content

Commit 67477c9

Browse files
committed
char & byte count, different ratio
1 parent 90614df commit 67477c9

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

index.html

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
<style>
66
*{margin:0;padding:0;border:0;box-sizing:border-box;vertical-align:middle}
77
html,body{height:100%;font:12px arial}
8-
.CodeMirror,#iframe{width:50%;height:100%;float:left;transition:.5s}
9-
#iframe{border-left:1px solid}
10-
#toggle{position:fixed;bottom:0;left:50%;transform:translateX(-50%);z-index:50;transition:.5s}
8+
#code,.CodeMirror,#iframe{height:100%;float:left;transition:.5s}
9+
#code,.CodeMirror{width:40%}
10+
#iframe{border-left:1px solid;width:60%}
11+
#toggle{position:fixed;bottom:0;left:40%;transform:translateX(-50%);z-index:50;transition:.5s}
1112
#toggle:checked{bottom:170px;transform:translateX(-50%) translateY(50%)}
1213
#menu{position:fixed;bottom:-170px;height:170px;width:100%;border-top:1px solid;z-index:2;transition:.5s}
1314
#toggle:checked~#menu{bottom:0}
@@ -68,6 +69,13 @@
6869
console.old_clear();
6970
}
7071

72+
// Count chars
73+
count_chars=function(b,a,c,d){a=[];for(c=0;c<b.length;c++)54==(b[d="charCodeAt"](c)>>10)?(a.push(1024*(b[d](c)-55296)+b[d](c+1)+9216),c++):a.push(b[d](c));return a.length}
74+
75+
// Count UTF-8 bytes
76+
count_bytes=function(b,a,c,d,n){a=[];for(c=0;c<b.length;c++)128>b[d="charCodeAt"](c)?a.push(b[d](c)):(n=b[c],55296==(b[d](c)&64512)&&(n=b.substr(c,2),c++),encodeURI(n).replace(/\w+/g,function(b){a.push(parseInt(b,16))}));return a.length}
77+
78+
7179
// Read hash
7280
if(location.hash){
7381
code.value=decodeURIComponent(location.hash.slice(1));
@@ -85,15 +93,15 @@
8593
download.href="data:text/html,"+encodeURIComponent(editor.getValue());
8694

8795
// Update count
88-
document.title=input.length+" chars - Codegolf IDE";
96+
document.title=count_chars(input)+" chars / "+count_bytes(input)+" bytes - Codegolf IDE";
8997

9098
// After typing code, clear console and update iframe and export link
9199
editor.on("keyup",function(){
92100
console.clear();
93101
input=editor.getValue();
94102
iframe.srcdoc=custom_console+editor.getValue();
95103
download.href="data:text/html,"+encodeURIComponent(input);
96-
document.title=input.length+" chars - Codegolf IDE";
104+
document.title=count_chars(input)+" chars / "+count_bytes(input)+" bytes - Codegolf IDE";
97105
});
98106

99107
// Save

0 commit comments

Comments
 (0)