Spaces:
Sleeping
Sleeping
fix(content.js): add CRITICAL severity to highlight mapping, tooltip badge
Browse files- extension/content.js +13 -3
extension/content.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
/**
|
| 2 |
-
* ClauseGuard β Content Script
|
| 3 |
* Page scanning + highlighting + auth bridge.
|
|
|
|
|
|
|
| 4 |
*
|
| 5 |
* Auth bridge: listens for postMessage from the website's ExtensionBridge component.
|
| 6 |
* Content scripts CAN receive window.postMessage from the page β they share the same
|
|
@@ -16,6 +18,9 @@
|
|
| 16 |
let isScanning = false;
|
| 17 |
let currentHighlights = [];
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
// βββ Auth Bridge βββ
|
| 20 |
// Listen for auth sync from our website (ExtensionBridge component sends this)
|
| 21 |
window.addEventListener("message", (event) => {
|
|
@@ -103,13 +108,18 @@
|
|
| 103 |
try {
|
| 104 |
const range = document.createRange();
|
| 105 |
range.setStart(textNode, start); range.setEnd(textNode, end);
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
| 107 |
const mark = document.createElement("mark");
|
| 108 |
mark.className = `clauseguard-highlight clauseguard-${severity.toLowerCase()}`;
|
| 109 |
mark.dataset.categories = JSON.stringify(clauseData.categories);
|
| 110 |
mark.addEventListener("mouseenter", showTooltip);
|
| 111 |
mark.addEventListener("mouseleave", hideTooltip);
|
| 112 |
-
mark.addEventListener("click", () => {
|
|
|
|
|
|
|
| 113 |
range.surroundContents(mark);
|
| 114 |
currentHighlights.push(mark);
|
| 115 |
} catch (e) {}
|
|
|
|
| 1 |
/**
|
| 2 |
+
* ClauseGuard β Content Script v4.3
|
| 3 |
* Page scanning + highlighting + auth bridge.
|
| 4 |
+
*
|
| 5 |
+
* FIXED v4.3: CRITICAL severity is now handled in highlights and tooltips.
|
| 6 |
*
|
| 7 |
* Auth bridge: listens for postMessage from the website's ExtensionBridge component.
|
| 8 |
* Content scripts CAN receive window.postMessage from the page β they share the same
|
|
|
|
| 18 |
let isScanning = false;
|
| 19 |
let currentHighlights = [];
|
| 20 |
|
| 21 |
+
// Severity ordering (higher = more severe)
|
| 22 |
+
const SEV_ORDER = { CRITICAL: 4, HIGH: 3, MEDIUM: 2, LOW: 1 };
|
| 23 |
+
|
| 24 |
// βββ Auth Bridge βββ
|
| 25 |
// Listen for auth sync from our website (ExtensionBridge component sends this)
|
| 26 |
window.addEventListener("message", (event) => {
|
|
|
|
| 108 |
try {
|
| 109 |
const range = document.createRange();
|
| 110 |
range.setStart(textNode, start); range.setEnd(textNode, end);
|
| 111 |
+
// FIX v4.3: Use numeric ordering that includes CRITICAL
|
| 112 |
+
const severity = clauseData.categories.reduce((m, c) =>
|
| 113 |
+
(SEV_ORDER[c.severity] || 0) > (SEV_ORDER[m] || 0) ? c.severity : m
|
| 114 |
+
, "LOW");
|
| 115 |
const mark = document.createElement("mark");
|
| 116 |
mark.className = `clauseguard-highlight clauseguard-${severity.toLowerCase()}`;
|
| 117 |
mark.dataset.categories = JSON.stringify(clauseData.categories);
|
| 118 |
mark.addEventListener("mouseenter", showTooltip);
|
| 119 |
mark.addEventListener("mouseleave", hideTooltip);
|
| 120 |
+
mark.addEventListener("click", () => {
|
| 121 |
+
try { chrome.runtime.sendMessage({ type: "OPEN_SIDEPANEL" }); } catch {}
|
| 122 |
+
});
|
| 123 |
range.surroundContents(mark);
|
| 124 |
currentHighlights.push(mark);
|
| 125 |
} catch (e) {}
|