accessify-widget 0.3.98 → 0.3.99
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/dist/accessify.min.js +1 -1
- package/dist/accessify.min.js.map +1 -1
- package/dist/accessify.mjs +1 -1
- package/dist/{index-BF8ksHVw.js → index-CUmLkmwP.js} +4 -4
- package/dist/{index-BF8ksHVw.js.map → index-CUmLkmwP.js.map} +1 -1
- package/dist/{keyboard-nav-C6vqsm1k.js → keyboard-nav--ZFLwRfu.js} +2 -2
- package/dist/{keyboard-nav-C6vqsm1k.js.map → keyboard-nav--ZFLwRfu.js.map} +1 -1
- package/dist/{page-structure-8pIvzkO4.js → page-structure-C78Y3t4E.js} +2 -2
- package/dist/{page-structure-8pIvzkO4.js.map → page-structure-C78Y3t4E.js.map} +1 -1
- package/dist/{text-simplify-W0rPYWpv.js → text-simplify-DUdShGEx.js} +332 -6
- package/dist/text-simplify-DUdShGEx.js.map +1 -0
- package/dist/widget.js +1 -1
- package/dist/widget.js.map +1 -1
- package/package.json +1 -1
- package/dist/text-simplify-W0rPYWpv.js.map +0 -1
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
function tokenize(s) {
|
|
2
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
3
|
+
const parts = s.toLowerCase().replace(/[^\p{L}\p{N}\s]/gu, " ").split(/\s+/);
|
|
4
|
+
for (const t of parts) {
|
|
5
|
+
if (t.length >= 3) tokens.add(t);
|
|
6
|
+
}
|
|
7
|
+
return tokens;
|
|
8
|
+
}
|
|
9
|
+
function tokenSimilarity(a, b) {
|
|
10
|
+
if (a.size === 0 || b.size === 0) return 0;
|
|
11
|
+
let inter = 0;
|
|
12
|
+
for (const t of a) if (b.has(t)) inter++;
|
|
13
|
+
const uni = a.size + b.size - inter;
|
|
14
|
+
return uni === 0 ? 0 : inter / uni;
|
|
15
|
+
}
|
|
16
|
+
const STALE_SIMILARITY_THRESHOLD = 0.4;
|
|
17
|
+
const CONTENT_ANCHOR_DEPTH = 4;
|
|
18
|
+
function isWholePageAncestor(a) {
|
|
19
|
+
const tag = a.tagName;
|
|
20
|
+
return tag === "BODY" || tag === "HTML";
|
|
21
|
+
}
|
|
22
|
+
function buildContentAnchors(applied) {
|
|
23
|
+
const anchors = /* @__PURE__ */ new Set();
|
|
24
|
+
for (const el of applied) {
|
|
25
|
+
let a = el;
|
|
26
|
+
for (let i = 0; i < CONTENT_ANCHOR_DEPTH && a; i++) {
|
|
27
|
+
if (isWholePageAncestor(a)) break;
|
|
28
|
+
anchors.add(a);
|
|
29
|
+
a = a.parentElement;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return anchors;
|
|
33
|
+
}
|
|
34
|
+
function isNearContent(el, anchors) {
|
|
35
|
+
let a = el;
|
|
36
|
+
for (let i = 0; i < CONTENT_ANCHOR_DEPTH && a; i++) {
|
|
37
|
+
if (isWholePageAncestor(a)) return false;
|
|
38
|
+
if (anchors.has(a)) return true;
|
|
39
|
+
a = a.parentElement;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
function isObviousBoilerplate(el) {
|
|
44
|
+
return !!el.closest(
|
|
45
|
+
'nav, [role="navigation"], [role="menu"], [role="menubar"], [role="menuitem"]'
|
|
46
|
+
);
|
|
47
|
+
}
|
|
1
48
|
function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
2
49
|
let enabled = false;
|
|
3
50
|
const defaultLevel = typeof options === "string" ? options : options?.simplificationLevel || void 0;
|
|
@@ -14,6 +61,89 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
14
61
|
const SIMPLIFIED_ATTR = "data-accessify-simplified";
|
|
15
62
|
const ORIGINAL_ATTR = "data-accessify-original";
|
|
16
63
|
const BLOCK_HASH_ATTR = "data-accessify-block-hash";
|
|
64
|
+
let diagRun = null;
|
|
65
|
+
const diagHistory = [];
|
|
66
|
+
const DIAG = () => !!window.__ACCESSIFY_DIAG;
|
|
67
|
+
function diagInit(route, siteKey) {
|
|
68
|
+
diagRun = {
|
|
69
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
70
|
+
route,
|
|
71
|
+
level,
|
|
72
|
+
siteMode: currentSiteMode,
|
|
73
|
+
siteKey,
|
|
74
|
+
manifestLoaded: false,
|
|
75
|
+
manifestBlocks: 0,
|
|
76
|
+
elementsFound: 0,
|
|
77
|
+
phase1Applied: 0,
|
|
78
|
+
phase1Stale: 0,
|
|
79
|
+
phase15IdbHits: 0,
|
|
80
|
+
phase2AICalls: 0,
|
|
81
|
+
phase2AIErrors: 0,
|
|
82
|
+
totalReplaced: 0,
|
|
83
|
+
totalSkipped: 0,
|
|
84
|
+
blocks: [],
|
|
85
|
+
restoreLog: []
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function diagBlock(partial) {
|
|
89
|
+
const entry = {
|
|
90
|
+
hash: partial.hash,
|
|
91
|
+
text: partial.text || "",
|
|
92
|
+
tag: partial.tag || "",
|
|
93
|
+
manifestMatch: partial.manifestMatch || "none",
|
|
94
|
+
idbHit: partial.idbHit || false,
|
|
95
|
+
liveAI: partial.liveAI || false,
|
|
96
|
+
persistOk: partial.persistOk ?? null,
|
|
97
|
+
replaced: partial.replaced || false,
|
|
98
|
+
skipReason: partial.skipReason || null,
|
|
99
|
+
stale: partial.stale || false,
|
|
100
|
+
source: partial.source || "skipped"
|
|
101
|
+
};
|
|
102
|
+
diagRun?.blocks.push(entry);
|
|
103
|
+
return entry;
|
|
104
|
+
}
|
|
105
|
+
function diagFinish() {
|
|
106
|
+
if (!diagRun) return;
|
|
107
|
+
diagRun.totalReplaced = diagRun.blocks.filter((b) => b.replaced).length;
|
|
108
|
+
diagRun.totalSkipped = diagRun.blocks.filter((b) => !b.replaced).length;
|
|
109
|
+
diagHistory.push(diagRun);
|
|
110
|
+
window.__accessifyDiag = diagHistory;
|
|
111
|
+
if (DIAG()) {
|
|
112
|
+
console.groupCollapsed(
|
|
113
|
+
`%c[Accessify DIAG] Run complete: ${diagRun.route}`,
|
|
114
|
+
"color: #38bdf8; font-weight: bold"
|
|
115
|
+
);
|
|
116
|
+
console.table({
|
|
117
|
+
route: diagRun.route,
|
|
118
|
+
level: diagRun.level,
|
|
119
|
+
siteMode: diagRun.siteMode,
|
|
120
|
+
manifestLoaded: diagRun.manifestLoaded,
|
|
121
|
+
manifestBlocks: diagRun.manifestBlocks,
|
|
122
|
+
elementsFound: diagRun.elementsFound,
|
|
123
|
+
"Phase 1 (manifest)": diagRun.phase1Applied,
|
|
124
|
+
"Phase 1 stale": diagRun.phase1Stale,
|
|
125
|
+
"Phase 1.5 (IDB)": diagRun.phase15IdbHits,
|
|
126
|
+
"Phase 2 (AI)": diagRun.phase2AICalls,
|
|
127
|
+
"Phase 2 errors": diagRun.phase2AIErrors,
|
|
128
|
+
totalReplaced: diagRun.totalReplaced,
|
|
129
|
+
totalSkipped: diagRun.totalSkipped
|
|
130
|
+
});
|
|
131
|
+
console.table(diagRun.blocks.map((b) => ({
|
|
132
|
+
hash: b.hash,
|
|
133
|
+
text: b.text,
|
|
134
|
+
tag: b.tag,
|
|
135
|
+
source: b.source,
|
|
136
|
+
manifest: b.manifestMatch,
|
|
137
|
+
idb: b.idbHit,
|
|
138
|
+
ai: b.liveAI,
|
|
139
|
+
persist: b.persistOk,
|
|
140
|
+
replaced: b.replaced,
|
|
141
|
+
skip: b.skipReason,
|
|
142
|
+
stale: b.stale
|
|
143
|
+
})));
|
|
144
|
+
console.groupEnd();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
17
147
|
const CLIENT_CACHE_DB = "accessify-simplify-cache";
|
|
18
148
|
const CLIENT_CACHE_STORE = "blocks";
|
|
19
149
|
const CLIENT_CACHE_VERSION = 1;
|
|
@@ -461,6 +591,7 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
461
591
|
bySelector.set(block.selector, block);
|
|
462
592
|
}
|
|
463
593
|
}
|
|
594
|
+
const claimedBlockHashes = /* @__PURE__ */ new Set();
|
|
464
595
|
for (const el of elements) {
|
|
465
596
|
const text = el.dataset.accessifyOriginal || el.textContent?.trim() || "";
|
|
466
597
|
const elHash = hashText(text);
|
|
@@ -469,8 +600,11 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
469
600
|
const success = safeReplace(el, exactMatch.result, elHash);
|
|
470
601
|
if (success) {
|
|
471
602
|
applied.push(el);
|
|
603
|
+
claimedBlockHashes.add(exactMatch.blockHash);
|
|
604
|
+
if (DIAG()) diagBlock({ hash: elHash, text: text.slice(0, 60), tag: el.tagName, manifestMatch: "exact", replaced: true, source: "manifest" });
|
|
472
605
|
} else {
|
|
473
606
|
remaining.push(el);
|
|
607
|
+
if (DIAG()) diagBlock({ hash: elHash, text: text.slice(0, 60), tag: el.tagName, manifestMatch: "exact", replaced: false, skipReason: "layout-unsafe", source: "skipped" });
|
|
474
608
|
}
|
|
475
609
|
continue;
|
|
476
610
|
}
|
|
@@ -490,8 +624,11 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
490
624
|
const success = safeReplace(el, fuzzyMatch.result, elHash);
|
|
491
625
|
if (success) {
|
|
492
626
|
applied.push(el);
|
|
627
|
+
claimedBlockHashes.add(fuzzyMatch.blockHash);
|
|
628
|
+
if (DIAG()) diagBlock({ hash: elHash, text: text.slice(0, 60), tag: el.tagName, manifestMatch: "fuzzy", replaced: true, source: "manifest" });
|
|
493
629
|
} else {
|
|
494
630
|
remaining.push(el);
|
|
631
|
+
if (DIAG()) diagBlock({ hash: elHash, text: text.slice(0, 60), tag: el.tagName, manifestMatch: "fuzzy", replaced: false, skipReason: "layout-unsafe", source: "skipped" });
|
|
495
632
|
}
|
|
496
633
|
} else {
|
|
497
634
|
console.info(
|
|
@@ -499,11 +636,67 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
499
636
|
text.slice(0, 50) + "…"
|
|
500
637
|
);
|
|
501
638
|
stale.push(el);
|
|
639
|
+
claimedBlockHashes.add(fuzzyMatch.blockHash);
|
|
640
|
+
if (DIAG()) diagBlock({ hash: elHash, text: text.slice(0, 60), tag: el.tagName, manifestMatch: "fuzzy", stale: true, skipReason: `stale(diff=${diff})`, source: "skipped" });
|
|
502
641
|
}
|
|
503
642
|
continue;
|
|
504
643
|
}
|
|
505
644
|
remaining.push(el);
|
|
506
645
|
}
|
|
646
|
+
const unclaimedBlocks = manifest.blocks.filter(
|
|
647
|
+
(b) => b.originalText && b.result && !claimedBlockHashes.has(b.blockHash)
|
|
648
|
+
);
|
|
649
|
+
if (unclaimedBlocks.length > 0 && remaining.length > 0) {
|
|
650
|
+
const blockTokens = unclaimedBlocks.map((b) => ({
|
|
651
|
+
block: b,
|
|
652
|
+
tokens: tokenize(b.originalText)
|
|
653
|
+
}));
|
|
654
|
+
const candidates = [];
|
|
655
|
+
for (const el of remaining) {
|
|
656
|
+
const text = el.dataset.accessifyOriginal || el.textContent?.trim() || "";
|
|
657
|
+
if (text.length < 20) continue;
|
|
658
|
+
const elTokens = tokenize(text);
|
|
659
|
+
if (elTokens.size < 3) continue;
|
|
660
|
+
let best = null;
|
|
661
|
+
for (const { block, tokens } of blockTokens) {
|
|
662
|
+
const sim = tokenSimilarity(elTokens, tokens);
|
|
663
|
+
if (sim >= STALE_SIMILARITY_THRESHOLD && (!best || sim > best.sim)) {
|
|
664
|
+
best = { el, block, sim };
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (best) candidates.push(best);
|
|
668
|
+
}
|
|
669
|
+
candidates.sort((a, b) => b.sim - a.sim);
|
|
670
|
+
const assignedBlocks = /* @__PURE__ */ new Set();
|
|
671
|
+
const assignedEls = /* @__PURE__ */ new Set();
|
|
672
|
+
for (const c of candidates) {
|
|
673
|
+
if (assignedBlocks.has(c.block.blockHash)) continue;
|
|
674
|
+
if (assignedEls.has(c.el)) continue;
|
|
675
|
+
assignedBlocks.add(c.block.blockHash);
|
|
676
|
+
assignedEls.add(c.el);
|
|
677
|
+
stale.push(c.el);
|
|
678
|
+
claimedBlockHashes.add(c.block.blockHash);
|
|
679
|
+
const elText = c.el.dataset.accessifyOriginal || c.el.textContent?.trim() || "";
|
|
680
|
+
console.info(
|
|
681
|
+
`[Accessify] Stale block (similarity=${c.sim.toFixed(2)}):`,
|
|
682
|
+
elText.slice(0, 50) + "…"
|
|
683
|
+
);
|
|
684
|
+
if (DIAG()) diagBlock({
|
|
685
|
+
hash: hashText(elText),
|
|
686
|
+
text: elText.slice(0, 60),
|
|
687
|
+
tag: c.el.tagName,
|
|
688
|
+
manifestMatch: "similarity",
|
|
689
|
+
stale: true,
|
|
690
|
+
skipReason: `stale(sim=${c.sim.toFixed(2)})`,
|
|
691
|
+
source: "skipped"
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
if (assignedEls.size > 0) {
|
|
695
|
+
const stillRemaining = remaining.filter((el) => !assignedEls.has(el));
|
|
696
|
+
remaining.length = 0;
|
|
697
|
+
remaining.push(...stillRemaining);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
507
700
|
return { applied, remaining, stale };
|
|
508
701
|
}
|
|
509
702
|
function buildSelector(el) {
|
|
@@ -549,11 +742,37 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
549
742
|
if (window.__ACCESSIFY_DEBUG) {
|
|
550
743
|
console.log(`[Accessify] Persisted ${blocks.length} blocks to D1+KV`);
|
|
551
744
|
}
|
|
745
|
+
if (DIAG() && diagRun) {
|
|
746
|
+
for (const b of blocks) {
|
|
747
|
+
const entry = diagRun.blocks.find((d) => d.hash === b.blockHash);
|
|
748
|
+
if (entry) entry.persistOk = true;
|
|
749
|
+
}
|
|
750
|
+
console.log(
|
|
751
|
+
`%c[Accessify DIAG] Persist OK: ${blocks.length} blocks → ${pageUrl}`,
|
|
752
|
+
"color: #22c55e"
|
|
753
|
+
);
|
|
754
|
+
}
|
|
552
755
|
} else {
|
|
553
756
|
console.warn(`[Accessify] Persist failed: ${res.status}`);
|
|
757
|
+
if (DIAG() && diagRun) {
|
|
758
|
+
for (const b of blocks) {
|
|
759
|
+
const entry = diagRun.blocks.find((d) => d.hash === b.blockHash);
|
|
760
|
+
if (entry) entry.persistOk = false;
|
|
761
|
+
}
|
|
762
|
+
console.warn(
|
|
763
|
+
`%c[Accessify DIAG] Persist FAILED (${res.status}): ${blocks.length} blocks`,
|
|
764
|
+
"color: #ef4444"
|
|
765
|
+
);
|
|
766
|
+
}
|
|
554
767
|
}
|
|
555
768
|
}).catch((err) => {
|
|
556
769
|
console.warn("[Accessify] Failed to persist live simplification:", err);
|
|
770
|
+
if (DIAG() && diagRun) {
|
|
771
|
+
for (const b of blocks) {
|
|
772
|
+
const entry = diagRun.blocks.find((d) => d.hash === b.blockHash);
|
|
773
|
+
if (entry) entry.persistOk = false;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
557
776
|
});
|
|
558
777
|
}
|
|
559
778
|
function markLoading(el) {
|
|
@@ -625,15 +844,24 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
625
844
|
let fromCache = 0;
|
|
626
845
|
let remaining = elements;
|
|
627
846
|
const staleBlocks = /* @__PURE__ */ new Set();
|
|
847
|
+
let appliedFromManifest = [];
|
|
628
848
|
const DEBUG = !!window.__ACCESSIFY_DEBUG;
|
|
849
|
+
if (DIAG()) diagInit(window.location.pathname, siteKey || null);
|
|
850
|
+
if (diagRun) diagRun.elementsFound = elements.length;
|
|
629
851
|
if (siteKey) {
|
|
630
852
|
showProgress(0, elements.length);
|
|
631
853
|
const manifest = await fetchManifest(siteKey, proxyUrl);
|
|
632
854
|
if (DEBUG) console.log(`[Accessify] Manifest: ${manifest?.blocks?.length ?? 0} blocks for ${elements.length} elements`);
|
|
855
|
+
if (diagRun) {
|
|
856
|
+
diagRun.manifestLoaded = !!manifest?.blocks?.length;
|
|
857
|
+
diagRun.manifestBlocks = manifest?.blocks?.length ?? 0;
|
|
858
|
+
diagRun.siteMode = currentSiteMode;
|
|
859
|
+
}
|
|
633
860
|
if (manifest?.blocks?.length) {
|
|
634
861
|
await clearClientCacheForPage();
|
|
635
862
|
const result = applyManifestBlocks(manifest, elements);
|
|
636
863
|
fromCache = result.applied.length;
|
|
864
|
+
appliedFromManifest = result.applied;
|
|
637
865
|
if (DEBUG) console.log(`[Accessify] Manifest hit: ${fromCache}, stale: ${result.stale.length}, remaining: ${result.remaining.length}`);
|
|
638
866
|
for (const el of result.stale) staleBlocks.add(el);
|
|
639
867
|
remaining = [...result.stale, ...result.remaining];
|
|
@@ -642,8 +870,13 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
642
870
|
setClientCached(clientCacheKey(block.blockHash), block.result);
|
|
643
871
|
}
|
|
644
872
|
}
|
|
873
|
+
if (diagRun) {
|
|
874
|
+
diagRun.phase1Applied = result.applied.length;
|
|
875
|
+
diagRun.phase1Stale = result.stale.length;
|
|
876
|
+
}
|
|
645
877
|
if (remaining.length === 0) {
|
|
646
878
|
showDone();
|
|
879
|
+
if (DIAG()) diagFinish();
|
|
647
880
|
return;
|
|
648
881
|
}
|
|
649
882
|
}
|
|
@@ -662,8 +895,13 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
662
895
|
const success = safeReplace(el, cached, blockHash);
|
|
663
896
|
if (success) {
|
|
664
897
|
fromCache++;
|
|
898
|
+
if (DIAG()) {
|
|
899
|
+
diagBlock({ hash: blockHash, text: text.slice(0, 60), tag: el.tagName, idbHit: true, replaced: true, source: "idb" });
|
|
900
|
+
if (diagRun) diagRun.phase15IdbHits++;
|
|
901
|
+
}
|
|
665
902
|
} else {
|
|
666
903
|
stillRemaining.push(el);
|
|
904
|
+
if (DIAG()) diagBlock({ hash: blockHash, text: text.slice(0, 60), tag: el.tagName, idbHit: true, replaced: false, skipReason: "layout-unsafe", source: "skipped" });
|
|
667
905
|
}
|
|
668
906
|
} else {
|
|
669
907
|
stillRemaining.push(el);
|
|
@@ -672,22 +910,48 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
672
910
|
remaining = stillRemaining;
|
|
673
911
|
if (remaining.length === 0) {
|
|
674
912
|
showDone();
|
|
913
|
+
if (DIAG()) diagFinish();
|
|
675
914
|
return;
|
|
676
915
|
}
|
|
677
916
|
}
|
|
678
917
|
const manifestWasLoaded = fromCache > 0 || siteKey && staleBlocks.size > 0;
|
|
679
918
|
if (manifestWasLoaded && remaining.length > 0) {
|
|
680
|
-
const
|
|
681
|
-
|
|
919
|
+
const contentAnchors = buildContentAnchors(appliedFromManifest);
|
|
920
|
+
const skipAsBoilerplate = [];
|
|
921
|
+
const keepForAI = [];
|
|
922
|
+
for (const el of remaining) {
|
|
923
|
+
if (staleBlocks.has(el)) {
|
|
924
|
+
keepForAI.push(el);
|
|
925
|
+
continue;
|
|
926
|
+
}
|
|
927
|
+
if (isObviousBoilerplate(el)) {
|
|
928
|
+
skipAsBoilerplate.push(el);
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
if (currentSiteMode === "auto" && isNearContent(el, contentAnchors)) {
|
|
932
|
+
keepForAI.push(el);
|
|
933
|
+
} else {
|
|
934
|
+
skipAsBoilerplate.push(el);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
if (skipAsBoilerplate.length > 0 && DEBUG) {
|
|
682
938
|
console.info(
|
|
683
|
-
`[Accessify]
|
|
939
|
+
`[Accessify] Safety Gate: ${skipAsBoilerplate.length} boilerplate skipped, ${keepForAI.length} queued for AI (stale + near-content).`
|
|
684
940
|
);
|
|
685
941
|
}
|
|
686
|
-
|
|
687
|
-
|
|
942
|
+
if (DIAG()) {
|
|
943
|
+
for (const el of skipAsBoilerplate) {
|
|
944
|
+
const t = el.dataset.accessifyOriginal || el.textContent?.trim() || "";
|
|
945
|
+
const reason = isObviousBoilerplate(el) ? "structural-boilerplate(nav/menu)" : currentSiteMode === "auto" ? "no-content-anchor" : `manual-mode(siteMode=${currentSiteMode})`;
|
|
946
|
+
diagBlock({ hash: hashText(t), text: t.slice(0, 60), tag: el.tagName, skipReason: reason, source: "skipped" });
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
for (const el of skipAsBoilerplate) clearLoading(el);
|
|
950
|
+
remaining = keepForAI;
|
|
688
951
|
if (remaining.length === 0) {
|
|
689
952
|
showDone();
|
|
690
953
|
showDisclaimer();
|
|
954
|
+
if (DIAG()) diagFinish();
|
|
691
955
|
return;
|
|
692
956
|
}
|
|
693
957
|
} else if (currentSiteMode !== "auto" && remaining.length > 0) {
|
|
@@ -696,6 +960,12 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
696
960
|
`[Accessify] siteMode=${currentSiteMode} — skipping live AI for ${remaining.length} uncached block(s). Site owner: trigger a crawl from the dashboard or switch to 'auto' mode.`
|
|
697
961
|
);
|
|
698
962
|
}
|
|
963
|
+
if (DIAG()) {
|
|
964
|
+
for (const el of remaining) {
|
|
965
|
+
const t = el.dataset.accessifyOriginal || el.textContent?.trim() || "";
|
|
966
|
+
diagBlock({ hash: hashText(t), text: t.slice(0, 60), tag: el.tagName, skipReason: `manual-mode(siteMode=${currentSiteMode})`, source: "skipped" });
|
|
967
|
+
}
|
|
968
|
+
}
|
|
699
969
|
if (staleBlocks.size > 0) skippedBlocks += staleBlocks.size;
|
|
700
970
|
for (const el of remaining) clearLoading(el);
|
|
701
971
|
if (fromCache > 0) {
|
|
@@ -704,6 +974,7 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
704
974
|
} else {
|
|
705
975
|
removeProgress();
|
|
706
976
|
}
|
|
977
|
+
if (DIAG()) diagFinish();
|
|
707
978
|
return;
|
|
708
979
|
}
|
|
709
980
|
if (!aiService && remaining.length > 0) {
|
|
@@ -737,6 +1008,11 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
737
1008
|
continue;
|
|
738
1009
|
}
|
|
739
1010
|
const blockHash = hashText(text);
|
|
1011
|
+
let diagEntry = null;
|
|
1012
|
+
if (DIAG()) {
|
|
1013
|
+
diagEntry = diagBlock({ hash: blockHash, text: text.slice(0, 60), tag: el.tagName, liveAI: true, stale: isStale(el), source: "ai" });
|
|
1014
|
+
if (diagRun) diagRun.phase2AICalls++;
|
|
1015
|
+
}
|
|
740
1016
|
try {
|
|
741
1017
|
const simplified = await aiService.simplifyText(text, level, lang);
|
|
742
1018
|
if (abortController?.signal.aborted) return;
|
|
@@ -748,9 +1024,25 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
748
1024
|
if (siteKey) {
|
|
749
1025
|
persistToManifest(siteKey, blockHash, text, simplified, buildSelector(el), proxyUrl);
|
|
750
1026
|
}
|
|
1027
|
+
if (diagEntry) diagEntry.replaced = true;
|
|
1028
|
+
} else {
|
|
1029
|
+
if (diagEntry) {
|
|
1030
|
+
diagEntry.replaced = false;
|
|
1031
|
+
diagEntry.skipReason = "layout-unsafe";
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
} else {
|
|
1035
|
+
if (diagEntry) {
|
|
1036
|
+
diagEntry.replaced = false;
|
|
1037
|
+
diagEntry.skipReason = simplified ? "ai-returned-identical" : "ai-returned-empty";
|
|
751
1038
|
}
|
|
752
1039
|
}
|
|
753
1040
|
} catch (err) {
|
|
1041
|
+
if (diagEntry) {
|
|
1042
|
+
diagEntry.skipReason = `error:${err?.message?.slice(0, 50) || "unknown"}`;
|
|
1043
|
+
diagEntry.replaced = false;
|
|
1044
|
+
}
|
|
1045
|
+
if (diagRun) diagRun.phase2AIErrors++;
|
|
754
1046
|
if (err?.message?.includes("401") || err?.message?.includes("403")) {
|
|
755
1047
|
console.warn("[Accessify] AI auth failed, stopping live simplification");
|
|
756
1048
|
for (const r of remaining) {
|
|
@@ -772,6 +1064,10 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
772
1064
|
if (siteKey) {
|
|
773
1065
|
persistToManifest(siteKey, blockHash, text, retry, buildSelector(el), proxyUrl);
|
|
774
1066
|
}
|
|
1067
|
+
if (diagEntry) {
|
|
1068
|
+
diagEntry.replaced = true;
|
|
1069
|
+
diagEntry.skipReason = null;
|
|
1070
|
+
}
|
|
775
1071
|
}
|
|
776
1072
|
}
|
|
777
1073
|
} catch {
|
|
@@ -804,10 +1100,15 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
804
1100
|
showDisclaimer();
|
|
805
1101
|
}
|
|
806
1102
|
}
|
|
1103
|
+
if (DIAG()) diagFinish();
|
|
807
1104
|
}
|
|
808
1105
|
function restorePage() {
|
|
809
1106
|
disconnectObservers();
|
|
1107
|
+
const restoreReason = abortController?.signal.aborted ? "abort(navigation/toggle)" : "toggle-off";
|
|
810
1108
|
for (const { el, originalHtml, savedTextNodes, ancestorPatches } of savedParagraphs) {
|
|
1109
|
+
const blockHash = el.getAttribute(BLOCK_HASH_ATTR) || "unknown";
|
|
1110
|
+
let textNodeRestore = false;
|
|
1111
|
+
let innerHtmlFallback = false;
|
|
811
1112
|
if (savedTextNodes.length > 0) {
|
|
812
1113
|
let allRestored = true;
|
|
813
1114
|
for (const sn of savedTextNodes) {
|
|
@@ -819,9 +1120,23 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
819
1120
|
}
|
|
820
1121
|
if (!allRestored) {
|
|
821
1122
|
el.innerHTML = originalHtml;
|
|
1123
|
+
innerHtmlFallback = true;
|
|
1124
|
+
} else {
|
|
1125
|
+
textNodeRestore = true;
|
|
822
1126
|
}
|
|
823
1127
|
} else {
|
|
824
1128
|
el.innerHTML = originalHtml;
|
|
1129
|
+
innerHtmlFallback = true;
|
|
1130
|
+
}
|
|
1131
|
+
if (DIAG() && diagRun) {
|
|
1132
|
+
diagRun.restoreLog.push({
|
|
1133
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1134
|
+
hash: blockHash,
|
|
1135
|
+
text: (el.textContent?.trim() || "").slice(0, 60),
|
|
1136
|
+
textNodeRestore,
|
|
1137
|
+
innerHtmlFallback,
|
|
1138
|
+
reason: innerHtmlFallback ? `${restoreReason}+innerHTML-fallback(text-nodes-detached)` : restoreReason
|
|
1139
|
+
});
|
|
825
1140
|
}
|
|
826
1141
|
el.removeAttribute(ORIGINAL_ATTR);
|
|
827
1142
|
el.removeAttribute(SIMPLIFIED_ATTR);
|
|
@@ -834,6 +1149,17 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
834
1149
|
}
|
|
835
1150
|
revertPatches(ancestorPatches);
|
|
836
1151
|
}
|
|
1152
|
+
if (DIAG() && diagRun) {
|
|
1153
|
+
const rl = diagRun.restoreLog;
|
|
1154
|
+
console.log(
|
|
1155
|
+
`%c[Accessify DIAG] Restore: ${rl.length} blocks, ${rl.filter((r) => r.textNodeRestore).length} text-node, ${rl.filter((r) => r.innerHtmlFallback).length} innerHTML-fallback`,
|
|
1156
|
+
"color: #f59e0b; font-weight: bold"
|
|
1157
|
+
);
|
|
1158
|
+
if (rl.some((r) => r.innerHtmlFallback)) {
|
|
1159
|
+
console.warn("[Accessify DIAG] innerHTML fallbacks detected — framework may have detached text nodes:");
|
|
1160
|
+
console.table(rl.filter((r) => r.innerHtmlFallback));
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
837
1163
|
savedParagraphs = [];
|
|
838
1164
|
skippedBlocks = 0;
|
|
839
1165
|
}
|
|
@@ -927,4 +1253,4 @@ function createTextSimplifyModule(aiService, lang = "de", options) {
|
|
|
927
1253
|
export {
|
|
928
1254
|
createTextSimplifyModule as default
|
|
929
1255
|
};
|
|
930
|
-
//# sourceMappingURL=text-simplify-
|
|
1256
|
+
//# sourceMappingURL=text-simplify-DUdShGEx.js.map
|