mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
don't frezze page
This commit is contained in:
parent
cccbd757e6
commit
61933ca0ad
@ -136,6 +136,6 @@
|
|||||||
|
|
||||||
function createFloatingButton(){ const d=document.createElement("div"); d.id="ht-ai-btn"; d.textContent="🤖"; document.body.appendChild(d); return d; }
|
function createFloatingButton(){ const d=document.createElement("div"); d.id="ht-ai-btn"; d.textContent="🤖"; document.body.appendChild(d); return d; }
|
||||||
function createTooltip(btn){ const t=document.createElement("div"); t.id="ht-ai-tooltip"; t.textContent=TOOLTIP_TEXT; document.body.appendChild(t); btn.addEventListener("mouseenter",()=>{const r=btn.getBoundingClientRect(); t.style.left=`${r.left+r.width/2}px`; t.style.top=`${r.top}px`; t.classList.add("show");}); btn.addEventListener("mouseleave",()=>t.classList.remove("show")); }
|
function createTooltip(btn){ const t=document.createElement("div"); t.id="ht-ai-tooltip"; t.textContent=TOOLTIP_TEXT; document.body.appendChild(t); btn.addEventListener("mouseenter",()=>{const r=btn.getBoundingClientRect(); t.style.left=`${r.left+r.width/2}px`; t.style.top=`${r.top}px`; t.classList.add("show");}); btn.addEventListener("mouseleave",()=>t.classList.remove("show")); }
|
||||||
function createSidebar(){ const p=document.createElement("div"); p.id="ht-ai-panel"; p.innerHTML=`<div id="ht-ai-header"><strong>HackTricks Chat</strong><div class="ht-actions"><button id="ht-ai-reset" title="Reset">↺</button><span id="ht-ai-close" title="Close">✖</span></div></div><div id="ht-ai-chat"></div><div id="ht-ai-input"><textarea id="ht-ai-question" placeholder="Type your question…"></textarea><button id="ht-ai-send">Send</button></div>`; document.body.appendChild(p); return p; }
|
function createSidebar(){ const p=document.createElement("div"); p.id="ht-ai-panel"; p.innerHTML=`<div id="ht-ai-header"><strong>HackTricksAI Chat</strong><div class="ht-actions"><button id="ht-ai-reset" title="Reset">↺</button><span id="ht-ai-close" title="Close">✖</span></div></div><div id="ht-ai-chat"></div><div id="ht-ai-input"><textarea id="ht-ai-question" placeholder="Type your question…"></textarea><button id="ht-ai-send">Send</button></div>`; document.body.appendChild(p); return p; }
|
||||||
})();
|
})();
|
||||||
|
|
@ -1,3 +1,26 @@
|
|||||||
|
/* ────────────────────────────────────────────────────────────────
|
||||||
|
Polyfill so requestIdleCallback works everywhere (IE 11/Safari)
|
||||||
|
─────────────────────────────────────────────────────────────── */
|
||||||
|
if (typeof window.requestIdleCallback !== "function") {
|
||||||
|
window.requestIdleCallback = function (cb) {
|
||||||
|
const start = Date.now();
|
||||||
|
return setTimeout(function () {
|
||||||
|
cb({
|
||||||
|
didTimeout: false,
|
||||||
|
timeRemaining: function () {
|
||||||
|
return Math.max(0, 50 - (Date.now() - start));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 1);
|
||||||
|
};
|
||||||
|
window.cancelIdleCallback = window.clearTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ────────────────────────────────────────────────────────────────
|
||||||
|
search.js
|
||||||
|
─────────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
window.search = window.search || {};
|
window.search = window.search || {};
|
||||||
(function search(search) {
|
(function search(search) {
|
||||||
@ -477,8 +500,7 @@ window.search = window.search || {};
|
|||||||
`https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/refs/heads/${branch}/searchindex.js`;
|
`https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/refs/heads/${branch}/searchindex.js`;
|
||||||
const localJs = "/searchindex.js";
|
const localJs = "/searchindex.js";
|
||||||
const TIMEOUT_MS = 10_000;
|
const TIMEOUT_MS = 10_000;
|
||||||
|
|
||||||
/* helper: inject a <script src=…> and wait for it */
|
|
||||||
const injectScript = (src) =>
|
const injectScript = (src) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
const s = document.createElement("script");
|
const s = document.createElement("script");
|
||||||
@ -487,37 +509,45 @@ window.search = window.search || {};
|
|||||||
s.onerror = (e) => reject(e);
|
s.onerror = (e) => reject(e);
|
||||||
document.head.appendChild(s);
|
document.head.appendChild(s);
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/* 1 — download raw JS from GitHub */
|
/* 1 — download raw JS from GitHub */
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
||||||
|
|
||||||
const res = await fetch(rawUrl, { signal: controller.signal });
|
const res = await fetch(rawUrl, { signal: controller.signal });
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||||
|
|
||||||
/* 2 — wrap in a Blob so the browser sees application/javascript */
|
/* 2 — wrap in a Blob so the browser sees application/javascript */
|
||||||
const code = await res.text();
|
const code = await res.text();
|
||||||
const blobUrl = URL.createObjectURL(
|
const blobUrl = URL.createObjectURL(
|
||||||
new Blob([code], { type: "application/javascript" })
|
new Blob([code], { type: "application/javascript" })
|
||||||
);
|
);
|
||||||
|
|
||||||
/* 3 — execute it */
|
/* 3 — execute it */
|
||||||
await injectScript(blobUrl);
|
await injectScript(blobUrl);
|
||||||
return init(window.search);
|
|
||||||
|
/* ───────────── PATCH ─────────────
|
||||||
|
heavy parsing now deferred to idle time
|
||||||
|
*/
|
||||||
|
requestIdleCallback(() => init(window.search));
|
||||||
|
return; // ✔ UI remains responsive
|
||||||
} catch (eRemote) {
|
} catch (eRemote) {
|
||||||
console.warn("Remote JS failed →", eRemote);
|
console.warn("Remote JS failed →", eRemote);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ───────── fallback: local copy ───────── */
|
/* ───────── fallback: local copy ───────── */
|
||||||
try {
|
try {
|
||||||
await injectScript(localJs);
|
await injectScript(localJs);
|
||||||
return init(window.search);
|
|
||||||
|
/* ───────────── PATCH ───────────── */
|
||||||
|
requestIdleCallback(() => init(window.search));
|
||||||
|
return;
|
||||||
} catch (eLocal) {
|
} catch (eLocal) {
|
||||||
console.error("Local JS failed →", eLocal);
|
console.error("Local JS failed →", eLocal);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Exported functions
|
// Exported functions
|
||||||
search.hasFocus = hasFocus;
|
search.hasFocus = hasFocus;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user