mm-math 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/browse.html CHANGED
@@ -150,7 +150,7 @@
150
150
  submitBtn.disabled = true;
151
151
  msgEl.textContent = '';
152
152
  try {
153
- var res = await fetch('./api/users/change-password', {
153
+ var res = await fetch('https://orange-dust-8e2b.jonah-7a0.workers.dev/api/users/change-password', {
154
154
  method: 'POST',
155
155
  headers: { 'Content-Type': 'application/json' },
156
156
  body: JSON.stringify({ username: username, currentPassword: cur, newPassword: nw }),
@@ -135,7 +135,7 @@
135
135
  msgEl.textContent = '';
136
136
 
137
137
  try {
138
- var res = await fetch('./api/users/change-password', {
138
+ var res = await fetch('https://orange-dust-8e2b.jonah-7a0.workers.dev/api/users/change-password', {
139
139
  method: 'POST',
140
140
  headers: { 'Content-Type': 'application/json' },
141
141
  body: JSON.stringify({ username: username, currentPassword: cur, newPassword: nw }),
package/index.html CHANGED
@@ -519,68 +519,7 @@ document.getElementById('fUser').addEventListener('keydown', e => {
519
519
  });
520
520
 
521
521
  // ── Login ─────────────────────────────────────────────────────────────────────
522
- const _onCalc = window.location.hostname === 'calc.moshelab.com';
523
- const BRIDGE_ORIGIN = 'https://calc.moshelab.com';
524
-
525
- // Preload invisible auth-bridge iframe. The iframe is on calc.moshelab.com so its
526
- // fetch to /api/login is same-origin — no CORS, no Cloudflare cross-origin checks.
527
- let _bridge = null;
528
- let _bridgeReadyResolve = null;
529
- const _bridgeReady = new Promise(function(resolve) { _bridgeReadyResolve = resolve; });
530
-
531
- if (!_onCalc) {
532
- _bridge = document.createElement('iframe');
533
- _bridge.src = BRIDGE_ORIGIN + '/login-frame.html';
534
- _bridge.style.cssText = 'visibility:hidden;width:1px;height:1px;border:0;position:absolute;overflow:hidden;left:-9999px;top:-9999px;';
535
- _bridge.setAttribute('aria-hidden', 'true');
536
- document.body.appendChild(_bridge);
537
- } else {
538
- // On calc.moshelab.com, bridge isn't used — resolve immediately
539
- _bridgeReadyResolve();
540
- }
541
-
542
- // Shared message handler — resolves the ready promise and dispatches login results
543
- const _pendingLogins = {};
544
- window.addEventListener('message', function(event) {
545
- if (event.origin !== BRIDGE_ORIGIN) return;
546
- const d = event.data;
547
- if (!d) return;
548
- if (d.type === 'bridge_ready') { _bridgeReadyResolve(); return; }
549
- if (d.type === 'login_result' && d.nonce && _pendingLogins[d.nonce]) {
550
- _pendingLogins[d.nonce](d);
551
- delete _pendingLogins[d.nonce];
552
- }
553
- });
554
-
555
- function _loginDirect(username, password) {
556
- return fetch('/api/login', {
557
- method: 'POST',
558
- headers: { 'Content-Type': 'application/json' },
559
- body: JSON.stringify({ username, password }),
560
- }).then(function(res) {
561
- return res.json().then(function(data) {
562
- data.ok = res.ok; data.status = res.status; return data;
563
- });
564
- });
565
- }
566
-
567
- function _loginViaBridge(username, password) {
568
- return _bridgeReady.then(function() {
569
- return new Promise(function(resolve, reject) {
570
- if (!_bridge || !_bridge.contentWindow) {
571
- return reject(new Error('Auth bridge unavailable'));
572
- }
573
- const nonce = Math.random().toString(36).slice(2, 10);
574
- const timer = setTimeout(function() {
575
- delete _pendingLogins[nonce];
576
- reject(new Error('Sign-in timed out. Try again.'));
577
- }, 15000);
578
-
579
- _pendingLogins[nonce] = function(d) { clearTimeout(timer); resolve(d); };
580
- _bridge.contentWindow.postMessage({ type: 'login', username: username, password: password, nonce: nonce }, BRIDGE_ORIGIN);
581
- });
582
- });
583
- }
522
+ const API = 'https://orange-dust-8e2b.jonah-7a0.workers.dev';
584
523
 
585
524
  async function doLogin() {
586
525
  const username = document.getElementById('fUser').value.trim();
@@ -598,7 +537,13 @@ async function doLogin() {
598
537
  errEl.textContent = '';
599
538
 
600
539
  try {
601
- const data = await (_onCalc ? _loginDirect(username, password) : _loginViaBridge(username, password));
540
+ const res = await fetch(API + '/api/login', {
541
+ method: 'POST',
542
+ headers: { 'Content-Type': 'application/json' },
543
+ body: JSON.stringify({ username, password }),
544
+ });
545
+ const data = await res.json();
546
+ data.ok = res.ok; data.status = res.status;
602
547
 
603
548
  if (!data.ok || !data.success) {
604
549
  errEl.textContent = data.status === 429 || (data.error || '').includes('Too many')
@@ -615,15 +560,10 @@ async function doLogin() {
615
560
  sessionStorage.setItem('mm_user', username);
616
561
  sessionStorage.setItem('mm_force_change', data.forcePasswordChange ? 'true' : 'false');
617
562
 
618
- if (data.forcePasswordChange) {
619
- window.location.href = './change-password.html';
620
- } else if (data.rank === 'administrator') {
621
- window.location.href = './admin.html';
622
- } else if (data.rank === 'admin') {
623
- window.location.href = './control-panel.html';
624
- } else {
625
- window.location.href = './browse.html';
626
- }
563
+ if (data.forcePasswordChange) window.location.href = './change-password.html';
564
+ else if (data.rank === 'administrator') window.location.href = './admin.html';
565
+ else if (data.rank === 'admin') window.location.href = './control-panel.html';
566
+ else window.location.href = './browse.html';
627
567
  } catch (err) {
628
568
  errEl.textContent = err && err.message ? err.message : String(err);
629
569
  btn.disabled = false;
package/js/games.js CHANGED
@@ -1,4 +1,4 @@
1
- const API_BASE = (window.location.hostname === 'unpkg.com' || window.location.hostname === 'cdn.jsdelivr.net') ? 'https://calc.moshelab.com' : '';
1
+ const API_BASE = 'https://orange-dust-8e2b.jonah-7a0.workers.dev';
2
2
 
3
3
  let allGames = [];
4
4
  let activeCategory = 'All';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm-math",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "STEM educational toolkit",
5
5
  "main": "index.html",
6
6
  "files": [
package/tool.html CHANGED
@@ -147,7 +147,7 @@
147
147
 
148
148
  let games;
149
149
  try {
150
- const res = await fetch('./api/games');
150
+ const res = await fetch('https://orange-dust-8e2b.jonah-7a0.workers.dev/api/games');
151
151
  games = res.ok ? await res.json() : null;
152
152
  } catch { games = null; }
153
153