Packet-Exchange commited on
Commit
037f593
·
verified ·
1 Parent(s): 2ccee15

Add SMS segment counter

Browse files
Files changed (2) hide show
  1. README.md +17 -5
  2. index.html +212 -18
README.md CHANGED
@@ -1,12 +1,24 @@
1
  ---
2
- title: Sms Segment Counter
3
- emoji: 📉
4
- colorFrom: gray
5
- colorTo: green
6
  sdk: static
7
  pinned: false
8
  license: mit
9
  short_description: Count SMS segments and see which character forced Unicode
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: SMS Segment Counter
3
+ emoji: 💬
4
+ colorFrom: yellow
5
+ colorTo: gray
6
  sdk: static
7
  pinned: false
8
  license: mit
9
  short_description: Count SMS segments and see which character forced Unicode
10
  ---
11
 
12
+ # SMS Segment Counter
13
+
14
+ Paste a message and see how many segments it will bill, whether it goes as GSM-7 or UCS-2, how much room is left, and exactly which character flipped it to Unicode, with a one click fix to plain equivalents.
15
+
16
+ Counting follows GSM 03.38: 160 characters for a single GSM-7 message, 153 per segment after that, 70 and 67 for UCS-2, and the twelve extended characters that cost two. Astral characters such as most emoji cost two UTF-16 units.
17
+
18
+ Everything runs in the browser. Nothing is sent anywhere.
19
+
20
+ ## Why it exists
21
+
22
+ Segments are what you pay for and what the handset has to reassemble. A single curly quote pasted from a document turns a 150 character message into three segments, and a one-time code that lands in segment two is a code the user does not see on the lock screen.
23
+
24
+ Built by [PacketExchange](https://huggingface.co/PacketExchange). The [PacketExchange API](https://packetexchange.io/developers) sends SMS and one-time codes on wholesale routes, with [open source clients](https://github.com/PacketExchangeIO) for Node, Python and more. Questions are welcome at contact@packetexchange.io.
index.html CHANGED
@@ -1,19 +1,213 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>SMS Segment Counter</title>
7
+ <style>
8
+ :root{--bg:#0A0E14;--panel:#111722;--line:#1E2938;--ink:#E8EDF5;--muted:#93A1B5;--brass:#E8C87E;--brass-dim:#C9A85C;--bad:#F08A7E;--ok:#8FD3A5}
9
+ *{box-sizing:border-box}
10
+ body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.6 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;padding:32px 16px 64px}
11
+ .wrap{max-width:860px;margin:0 auto}
12
+ .top{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-bottom:22px;font-size:13px;color:var(--muted)}
13
+ .top a{color:var(--brass);text-decoration:none}
14
+ h1{font-size:26px;margin:0 0 6px;letter-spacing:-0.01em}
15
+ h2{font-size:15px;margin:0 0 14px;color:var(--brass);text-transform:uppercase;letter-spacing:.08em}
16
+ p{color:var(--muted);margin:0 0 14px}
17
+ .lede{color:var(--ink);font-size:16px}
18
+ .card{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:20px;margin:18px 0}
19
+ .row{display:flex;flex-wrap:wrap;gap:12px;align-items:center}
20
+ .grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:16px}
21
+ button{background:var(--brass);color:#14100A;border:0;border-radius:8px;padding:10px 16px;font-weight:600;font-size:14px;cursor:pointer}
22
+ button.ghost{background:transparent;color:var(--brass);border:1px solid var(--brass-dim)}
23
+ button:disabled{opacity:.45;cursor:not-allowed}
24
+ label{display:block;font-size:13px;color:var(--muted);margin-bottom:6px}
25
+ select,input[type=text],textarea{background:#0C121C;color:var(--ink);border:1px solid var(--line);border-radius:8px;padding:9px 10px;font-size:14px;width:100%}
26
+ textarea{min-height:120px;resize:vertical;font-family:inherit}
27
+ input[type=range]{width:100%;accent-color:var(--brass)}
28
+ .val{color:var(--brass);font-variant-numeric:tabular-nums}
29
+ .stat{background:#0C121C;border:1px solid var(--line);border-radius:10px;padding:12px 14px}
30
+ .stat .k{font-size:12px;color:var(--muted);text-transform:uppercase;letter-spacing:.06em}
31
+ .stat .v{font-size:22px;font-weight:600;color:var(--ink);font-variant-numeric:tabular-nums}
32
+ .stat .v.bad{color:var(--bad)} .stat .v.ok{color:var(--ok)}
33
+ .note{font-size:13px;color:var(--muted)}
34
+ .bullets{color:var(--muted);padding-left:18px;margin:0 0 6px}
35
+ .bullets li{margin-bottom:8px}
36
+ a{color:var(--brass)}
37
+ footer{margin-top:28px;font-size:13px;color:var(--muted)}
38
+ code,.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px}
39
+ .pill{display:inline-block;padding:2px 8px;border-radius:999px;border:1px solid var(--line);font-size:12px;color:var(--muted);margin:2px 4px 2px 0}
40
+ table{width:100%;border-collapse:collapse;font-size:14px}
41
+ th,td{text-align:left;padding:8px 6px;border-bottom:1px solid var(--line)}
42
+ th{color:var(--muted);font-weight:500;font-size:12px;text-transform:uppercase;letter-spacing:.06em}
43
+
44
+ .seg{display:inline-block;background:#0C121C;border:1px solid var(--line);border-radius:8px;padding:8px 10px;margin:4px 6px 4px 0;font-size:13px;max-width:100%;white-space:pre-wrap;word-break:break-word}
45
+ .seg b{color:var(--brass);font-weight:600;margin-right:6px}
46
+ .hl{color:var(--bad);border-bottom:1px dotted var(--bad)}
47
+ </style>
48
+ </head>
49
+ <body>
50
+ <div class="wrap">
51
+ <div class="top">
52
+ <span>PacketExchange developer tools</span>
53
+ <a href="https://huggingface.co/PacketExchange">More tools</a>
54
+ </div>
55
+
56
+ <h1>SMS Segment Counter</h1>
57
+ <p class="lede">Know how many segments a message will bill before you send it, and which character flipped it to Unicode.</p>
58
+ <p>Type or paste a message. Counting is done in your browser against the GSM 03.38 character set, which is what the carrier network actually uses. Nothing is sent anywhere.</p>
59
+
60
+ <div class="card">
61
+ <h2>Message</h2>
62
+ <textarea id="msg" placeholder="Your verification code is 482913. It expires in 10 minutes."></textarea>
63
+ <div class="grid" style="margin-top:14px">
64
+ <div class="stat"><div class="k">Encoding</div><div class="v" id="enc">GSM-7</div></div>
65
+ <div class="stat"><div class="k">Characters</div><div class="v" id="chars">0</div></div>
66
+ <div class="stat"><div class="k">Segments</div><div class="v" id="segs">0</div></div>
67
+ <div class="stat"><div class="k">Left in this segment</div><div class="v" id="left">160</div></div>
68
+ </div>
69
+ <p class="note" id="why" style="margin-top:12px"></p>
70
+ <div id="fixes"></div>
71
+ </div>
72
+
73
+ <div class="card">
74
+ <h2>How it will be split</h2>
75
+ <div id="preview" class="note">Nothing to split yet.</div>
76
+ </div>
77
+
78
+ <div class="card">
79
+ <h2>The rules in one place</h2>
80
+ <ul class="bullets">
81
+ <li>GSM-7 fits 160 characters in a single message. Once a message needs more than one segment, each segment carries a 6 byte header and holds 153.</li>
82
+ <li>One character outside the GSM-7 set, a curly quote or an emoji for example, switches the whole message to UCS-2: 70 characters single, 67 per segment after that.</li>
83
+ <li>Twelve GSM-7 characters are "extended" and cost two: <span class="mono">^ { } \ [ ] ~ | €</span> and form feed. A single euro sign can push a 159 character message into two segments.</li>
84
+ <li>Segments are what you are billed for and what the handset reassembles. Long messages also take longer to deliver, because each segment travels separately.</li>
85
+ <li>For one-time codes, keep the whole message in one GSM-7 segment and put the code early. Preview text on a locked phone is short.</li>
86
+ </ul>
87
+ </div>
88
+
89
+ <footer>
90
+ Built by <a href="https://huggingface.co/PacketExchange">PacketExchange</a>. If you send SMS or one-time codes through code, the
91
+ <a href="https://packetexchange.io/developers">PacketExchange API</a> does this on wholesale routes with
92
+ <a href="https://github.com/PacketExchangeIO">open source clients</a> for Node, Python and more.
93
+ Questions are welcome at <a href="mailto:contact@packetexchange.io">contact@packetexchange.io</a>.
94
+ </footer>
95
+ </div>
96
+
97
+ <script>
98
+ (function(){
99
+ "use strict";
100
+ var BASIC = "@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà";
101
+ var EXT = "^{}\\[~]|€\f";
102
+ var basicSet = {}, extSet = {};
103
+ for(var i=0;i<BASIC.length;i++) basicSet[BASIC[i]] = true;
104
+ for(var j=0;j<EXT.length;j++) extSet[EXT[j]] = true;
105
+
106
+ var SUGGEST = {
107
+ "‘":"'", "’":"'", "‚":"'", "“":"\"", "”":"\"", "„":"\"",
108
+ "–":"-", "—":"-", "…":"...", " ":" ", "•":"-", "´":"'", "′":"'",
109
+ "«":"\"", "»":"\"", "™":"TM", "®":"(R)", "©":"(C)", "−":"-", "×":"x"
110
+ };
111
+
112
+ var els = {
113
+ msg: document.getElementById('msg'), enc: document.getElementById('enc'),
114
+ chars: document.getElementById('chars'), segs: document.getElementById('segs'),
115
+ left: document.getElementById('left'), why: document.getElementById('why'),
116
+ fixes: document.getElementById('fixes'), preview: document.getElementById('preview')
117
+ };
118
+
119
+ function codepoints(s){ return Array.from(s); }
120
+
121
+ function analyse(text){
122
+ var cps = codepoints(text), bad = [], units = 0, k;
123
+ var isGsm = true;
124
+ for(k=0;k<cps.length;k++){
125
+ var ch = cps[k];
126
+ if(basicSet[ch]) units += 1;
127
+ else if(extSet[ch]) units += 2;
128
+ else { isGsm = false; if(bad.indexOf(ch) < 0) bad.push(ch); }
129
+ }
130
+ var res = {isGsm:isGsm, bad:bad, count:cps.length};
131
+ if(isGsm){
132
+ res.units = units;
133
+ res.single = 160; res.multi = 153;
134
+ res.segments = units === 0 ? 0 : (units <= 160 ? 1 : Math.ceil(units / 153));
135
+ } else {
136
+ // UCS-2 counts UTF-16 code units; astral characters (most emoji) cost two
137
+ var u16 = 0;
138
+ for(k=0;k<cps.length;k++) u16 += cps[k].length;
139
+ res.units = u16;
140
+ res.single = 70; res.multi = 67;
141
+ res.segments = u16 === 0 ? 0 : (u16 <= 70 ? 1 : Math.ceil(u16 / 67));
142
+ }
143
+ var per = res.segments <= 1 ? res.single : res.multi;
144
+ res.left = res.segments === 0 ? res.single : (per * res.segments - res.units);
145
+ res.per = per;
146
+ return res;
147
+ }
148
+
149
+ function split(text, res){
150
+ var cps = codepoints(text), parts = [], cur = "", used = 0, cap = res.segments <= 1 ? res.single : res.multi;
151
+ for(var k=0;k<cps.length;k++){
152
+ var ch = cps[k], cost;
153
+ if(res.isGsm) cost = extSet[ch] ? 2 : 1; else cost = ch.length;
154
+ if(used + cost > cap){ parts.push(cur); cur = ""; used = 0; }
155
+ cur += ch; used += cost;
156
+ }
157
+ if(cur.length) parts.push(cur);
158
+ return parts;
159
+ }
160
+
161
+ function esc(s){ return s.replace(/[&<>]/g, function(c){ return {'&':'&amp;','<':'&lt;','>':'&gt;'}[c]; }); }
162
+ function name(ch){
163
+ var cp = ch.codePointAt(0).toString(16).toUpperCase();
164
+ while(cp.length < 4) cp = "0" + cp;
165
+ return "U+" + cp;
166
+ }
167
+
168
+ function render(){
169
+ var text = els.msg.value;
170
+ var r = analyse(text);
171
+ els.enc.textContent = r.isGsm ? "GSM-7" : "UCS-2";
172
+ els.enc.className = "v " + (r.isGsm ? "ok" : "bad");
173
+ els.chars.textContent = r.count + (r.units !== r.count ? " (" + r.units + " units)" : "");
174
+ els.segs.textContent = r.segments;
175
+ els.segs.className = "v " + (r.segments > 1 ? "bad" : "");
176
+ els.left.textContent = r.left;
177
+
178
+ if(r.count === 0){ els.why.textContent = ""; els.fixes.innerHTML = ""; els.preview.textContent = "Nothing to split yet."; return; }
179
+
180
+ if(r.isGsm){
181
+ els.why.textContent = "Every character is in the GSM-7 set. " + (r.segments === 1 ? "This goes as one segment." : "Over 160, so each segment holds 153.");
182
+ els.fixes.innerHTML = "";
183
+ } else {
184
+ els.why.textContent = "Unicode was forced by " + r.bad.length + " character" + (r.bad.length > 1 ? "s" : "") + " outside GSM-7, so every segment now holds " + r.per + ".";
185
+ var html = "";
186
+ for(var k=0;k<r.bad.length;k++){
187
+ var ch = r.bad[k], s = SUGGEST[ch];
188
+ html += '<span class="pill mono">' + esc(ch) + ' ' + name(ch) + (s !== undefined ? ' &rarr; ' + esc(s) : '') + '</span>';
189
+ }
190
+ var fixed = text;
191
+ for(var key in SUGGEST){ if(SUGGEST.hasOwnProperty(key)) fixed = fixed.split(key).join(SUGGEST[key]); }
192
+ var r2 = analyse(fixed);
193
+ if(r2.isGsm){
194
+ html += '<div style="margin-top:10px"><button class="ghost" id="applyFix">Replace with plain equivalents (' + r2.segments + ' segment' + (r2.segments === 1 ? '' : 's') + ')</button></div>';
195
+ }
196
+ els.fixes.innerHTML = html;
197
+ var btn = document.getElementById('applyFix');
198
+ if(btn) btn.addEventListener('click', function(){ els.msg.value = fixed; render(); });
199
+ }
200
+
201
+ var parts = split(text, r), out = "";
202
+ for(var p=0;p<parts.length;p++){
203
+ out += '<div class="seg"><b>' + (p+1) + '/' + parts.length + '</b>' + esc(parts[p]) + '</div>';
204
+ }
205
+ els.preview.innerHTML = out;
206
+ }
207
+
208
+ els.msg.addEventListener('input', render);
209
+ render();
210
+ })();
211
+ </script>
212
+ </body>
213
  </html>