开始与 AI 对话吧!
Enter 提交
Shift+Enter 换行
// ==UserScript== // @name Thpilot AI 划词助手 // @namespace ThpilotAIHelper // @version 2.23.1 // @description 通用网页划词助手:任意网页划词解释、翻译、纠错、总结和聊天、搜索、抓网页、图片、web搜索和工具调用等 // @author Wilsons / Web adaptation // @match http://*/* // @match https://*/* // @match file:///* // @run-at document-idle // @noframes // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_getResourceText // @grant GM_registerMenuCommand // @grant GM_setClipboard // @grant unsafeWindow // @connect * // @require https://fastly.jsdelivr.net/npm/markdown-it@14.1.0/dist/markdown-it.min.js // @require https://fastly.jsdelivr.net/npm/katex@0.18.1/dist/katex.min.js // @require https://fastly.jsdelivr.net/npm/markdown-it-task-lists@2.1.1/dist/markdown-it-task-lists.min.js // @require https://fastly.jsdelivr.net/npm/markdown-it-footnote@4.0.0/dist/markdown-it-footnote.min.js // @require https://fastly.jsdelivr.net/npm/@highlightjs/cdn-assets@11.11.1/highlight.min.js // @require https://fastly.jsdelivr.net/npm/dompurify@3.2.6/dist/purify.min.js // @require https://fastly.jsdelivr.net/npm/@mozilla/readability@0.6.0/Readability.js // Mermaid 11 等 不能 @require(沙箱挂载失败);用 @resource 扩展内缓存,运行时注入 // @resource katexCss https://fastly.jsdelivr.net/npm/katex@0.18.1/dist/katex.min.css // @resource highlightCss https://fastly.jsdelivr.net/npm/highlight.js@11.11.1/styles/github-dark.min.css // @resource mermaidJs https://fastly.jsdelivr.net/npm/mermaid@11.16.0/dist/mermaid.min.js // @license MIT // ==/UserScript== /* // @require file:///Users/wish/workspace/ThpilotAI/user.js?r=1 */ (async () => { 'use strict'; const SETTINGS_STORAGE_KEY = 'thpilot-web-settings-v2'; function normalizeDomainBlacklist(input) { const domains = Array.isArray(input) ? input : String(input || '').split(/\r?\n/); return [...new Set(domains .map(domain => String(domain || '') .trim() .toLowerCase() .replace(/^\.+|\.+$/g, '')) .filter(Boolean))]; } const storedSettings = GM_getValue(SETTINGS_STORAGE_KEY, {}) || {}; const domainBlacklist = normalizeDomainBlacklist( storedSettings.domainBlacklist, ); const currentHostname = location.hostname .toLowerCase() .replace(/\.+$/, ''); const isDomainBlacklisted = domainBlacklist.some(domain => { return domain && ( currentHostname === domain || currentHostname.endsWith(`.${domain}`) ); }); if (isDomainBlacklisted) return; if (window.top !== window.self) return; if (document.documentElement.dataset.thpilotWebLoaded === '1') return; document.documentElement.dataset.thpilotWebLoaded = '1'; const trustedTypesApi = window.trustedTypes; const trustedHTMLPolicy = (() => { if (!trustedTypesApi) return null; try { return trustedTypesApi.createPolicy( 'thpilot-ai-helper', { createHTML: value => value, }, ); } catch (error) { return trustedTypesApi.getPolicy?.( 'thpilot-ai-helper', ) || null; } })(); function toTrustedHTML(value) { const html = String(value ?? ''); return trustedHTMLPolicy ? trustedHTMLPolicy.createHTML(html) : html; } function setHTML(element, value) { element.innerHTML = toTrustedHTML(value); } function setShadowHTML(shadowRoot, value) { const html = String(value ?? ''); const styleMatch = html.match(/
Enter 提交
Shift+Enter 换行