{ // 获取包含Hugging Face文本的span元素 const spans = link.querySelectorAll('span.whitespace-nowrap, span.hidden.whitespace-nowrap'); spans.forEach(span => { if (span.textContent && span.textContent.trim().match(/Hugging\s*Face/i)) { span.textContent = 'AI快站'; } }); }); // 替换logo图片的alt属性 document.querySelectorAll('img[alt*="Hugging"], img[alt*="Face"]').forEach(img => { if (img.alt.match(/Hugging\s*Face/i)) { img.alt = 'AI快站 logo'; } }); } // 替换导航栏中的链接 function replaceNavigationLinks() { // 已替换标记,防止重复运行 if (window._navLinksReplaced) { return; } // 已经替换过的链接集合,防止重复替换 const replacedLinks = new Set(); // 只在导航栏区域查找和替换链接 const headerArea = document.querySelector('header') || document.querySelector('nav'); if (!headerArea) { return; } // 在导航区域内查找链接 const navLinks = headerArea.querySelectorAll('a'); navLinks.forEach(link => { // 如果已经替换过,跳过 if (replacedLinks.has(link)) return; const linkText = link.textContent.trim(); const linkHref = link.getAttribute('href') || ''; // 替换Spaces链接 - 仅替换一次 if ( (linkHref.includes('/spaces') || linkHref === '/spaces' || linkText === 'Spaces' || linkText.match(/^s*Spacess*$/i)) && linkText !== 'OCR模型免费转Markdown' && linkText !== 'OCR模型免费转Markdown' ) { link.textContent = 'OCR模型免费转Markdown'; link.href = 'https://fast360.xyz'; link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); replacedLinks.add(link); } // 删除Posts链接 else if ( (linkHref.includes('/posts') || linkHref === '/posts' || linkText === 'Posts' || linkText.match(/^s*Postss*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } // 替换Docs链接 - 仅替换一次 else if ( (linkHref.includes('/docs') || linkHref === '/docs' || linkText === 'Docs' || linkText.match(/^s*Docss*$/i)) && linkText !== '模型下载攻略' ) { link.textContent = '模型下载攻略'; link.href = '/'; replacedLinks.add(link); } // 删除Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } }); // 查找可能嵌套的Spaces和Posts文本 const textNodes = []; function findTextNodes(element) { if (element.nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text === 'Spaces' || text === 'Posts' || text === 'Enterprise') { textNodes.push(element); } } else { for (const child of element.childNodes) { findTextNodes(child); } } } // 只在导航区域内查找文本节点 findTextNodes(headerArea); // 替换找到的文本节点 textNodes.forEach(node => { const text = node.textContent.trim(); if (text === 'Spaces') { node.textContent = node.textContent.replace(/Spaces/g, 'OCR模型免费转Markdown'); } else if (text === 'Posts') { // 删除Posts文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } else if (text === 'Enterprise') { // 删除Enterprise文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } }); // 标记已替换完成 window._navLinksReplaced = true; } // 替换代码区域中的域名 function replaceCodeDomains() { // 特别处理span.hljs-string和span.njs-string元素 document.querySelectorAll('span.hljs-string, span.njs-string, span[class*="hljs-string"], span[class*="njs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换hljs-string类的span中的域名(移除多余的转义符号) document.querySelectorAll('span.hljs-string, span[class*="hljs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换pre和code标签中包含git clone命令的域名 document.querySelectorAll('pre, code').forEach(element => { if (element.textContent && element.textContent.includes('git clone')) { const text = element.innerHTML; if (text.includes('huggingface.co')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 处理特定的命令行示例 document.querySelectorAll('pre, code').forEach(element => { const text = element.innerHTML; if (text.includes('huggingface.co')) { // 针对git clone命令的专门处理 if (text.includes('git clone') || text.includes('GIT_LFS_SKIP_SMUDGE=1')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 特别处理模型下载页面上的代码片段 document.querySelectorAll('.flex.border-t, .svelte_hydrator, .inline-block').forEach(container => { const content = container.innerHTML; if (content && content.includes('huggingface.co')) { container.innerHTML = content.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 特别处理模型仓库克隆对话框中的代码片段 try { // 查找包含"Clone this model repository"标题的对话框 const cloneDialog = document.querySelector('.svelte_hydration_boundary, [data-target="MainHeader"]'); if (cloneDialog) { // 查找对话框中所有的代码片段和命令示例 const codeElements = cloneDialog.querySelectorAll('pre, code, span'); codeElements.forEach(element => { if (element.textContent && element.textContent.includes('huggingface.co')) { if (element.innerHTML.includes('huggingface.co')) { element.innerHTML = element.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { element.textContent = element.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); } // 更精确地定位克隆命令中的域名 document.querySelectorAll('[data-target]').forEach(container => { const codeBlocks = container.querySelectorAll('pre, code, span.hljs-string'); codeBlocks.forEach(block => { if (block.textContent && block.textContent.includes('huggingface.co')) { if (block.innerHTML.includes('huggingface.co')) { block.innerHTML = block.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { block.textContent = block.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); }); } catch (e) { // 错误处理但不打印日志 } } // 当DOM加载完成后执行替换 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); }); } else { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); } // 增加一个MutationObserver来处理可能的动态元素加载 const observer = new MutationObserver(mutations => { // 检查是否导航区域有变化 const hasNavChanges = mutations.some(mutation => { // 检查是否存在header或nav元素变化 return Array.from(mutation.addedNodes).some(node => { if (node.nodeType === Node.ELEMENT_NODE) { // 检查是否是导航元素或其子元素 if (node.tagName === 'HEADER' || node.tagName === 'NAV' || node.querySelector('header, nav')) { return true; } // 检查是否在导航元素内部 let parent = node.parentElement; while (parent) { if (parent.tagName === 'HEADER' || parent.tagName === 'NAV') { return true; } parent = parent.parentElement; } } return false; }); }); // 只在导航区域有变化时执行替换 if (hasNavChanges) { // 重置替换状态,允许再次替换 window._navLinksReplaced = false; replaceHeaderBranding(); replaceNavigationLinks(); } }); // 开始观察document.body的变化,包括子节点 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.body, { childList: true, subtree: true }); }); } })(); \n\n\"\"\"\n\n\nclass HTMLViewer(object):\n\n format_dict = {'default': 'application/octet-stream',\n 'json': 'application/json',\n 'csv': 'text/csv',\n 'ods': 'application/vnd.oasis.opendocument.spreadsheet',\n 'python': 'text/html'}\n\n def __init__(self, app_path, profile_module, profile_log):\n self.app_path = app_path\n self.profile_module = profile_module\n self.profile_log = profile_log\n\n def _get_param(self, query_dict, key, default=None, multiple=False):\n value = query_dict.get(key, default)\n if value is None or value == '':\n return default\n if multiple:\n return value\n if isinstance(value, list):\n return eval(value[0]) if isinstance(default, int) else value[0]\n else:\n return value\n\n def render(self, url, method, path_entry, query_dict, clear_callback):\n plot = self._get_param(query_dict, 'plot', None)\n download = self._get_param(query_dict, 'download', None)\n clear = self._get_param(query_dict, 'clear', None)\n action = plot or download or clear\n profile_id = self._get_param(query_dict, 'profile', 'current')\n sort = self._get_param(query_dict, 'sort', 'time')\n limit = self._get_param(query_dict, 'limit', -1)\n fulldirs = self._get_param(query_dict, 'fulldirs', 0)\n nfl_filter = self._get_param(query_dict, 'nfl_filter', '').strip()\n metric_selected = self._get_param(query_dict, 'metric', 'cc')\n plot_type = self._get_param(query_dict, 'plottype', 'bar')\n download_format = self._get_param(query_dict, 'format', 'default')\n content = ''\n # GET /__profile, POST /__profile\n if len(path_entry) == 2 and method in ['GET', 'POST']:\n log_files = self.profile_log.get_logfiles(profile_id)\n if action == 'plot':\n content, headers = self.plot(log_files, sort, limit,\n nfl_filter, metric_selected,\n plot_type)\n elif action == 'download':\n content, headers = self.download(log_files, sort, limit,\n nfl_filter, download_format)\n else:\n if action == 'clear':\n self.profile_log.clear(profile_id)\n clear_callback and clear_callback()\n content, headers = self.index_page(log_files, sort, limit,\n fulldirs, nfl_filter,\n profile_id, url)\n # GET /__profile__/all\n # GET /__profile__/current\n # GET /__profile__/profile_id\n # GET /__profile__/profile_id/\n # GET /__profile__/profile_id/account.py:50(GETorHEAD)\n # GET /__profile__/profile_id/swift/proxy/controllers\n # /account.py:50(GETorHEAD)\n # with QUERY_STRING: ?format=[default|json|csv|ods]\n elif len(path_entry) > 2 and method == 'GET':\n profile_id = path_entry[2]\n log_files = self.profile_log.get_logfiles(profile_id)\n pids = self.profile_log.get_all_pids()\n # return all profiles in a json format by default.\n # GET /__profile__/\n if profile_id == '':\n content = '{\"profile_ids\": [\"' + '\",\"'.join(pids) + '\"]}'\n headers = [('content-type', self.format_dict['json'])]\n else:\n if len(path_entry) > 3 and path_entry[3] != '':\n nfl_filter = '/'.join(path_entry[3:])\n if path_entry[-1].find(':0') == -1:\n nfl_filter = '/' + nfl_filter\n content, headers = self.download(log_files, sort, -1,\n nfl_filter, download_format)\n headers.append(('Access-Control-Allow-Origin', '*'))\n else:\n raise MethodNotAllowed(_('method %s is not allowed.') % method)\n return content, headers\n\n def index_page(self, log_files=None, sort='time', limit=-1,\n fulldirs=0, nfl_filter='', profile_id='current', url='#'):\n headers = [('content-type', 'text/html')]\n if len(log_files) == 0:\n return empty_description, headers\n try:\n stats = Stats2(*log_files)\n except (IOError, ValueError):\n raise DataLoadFailure(_('Can not load profile data from %s.')\n % log_files)\n if not fulldirs:\n stats.strip_dirs()\n stats.sort_stats(sort)\n nfl_filter_esc =\\\n nfl_filter.replace('(', '\\(').replace(')', '\\)')\n amount = [nfl_filter_esc, limit] if nfl_filter_esc else [limit]\n profile_html = self.generate_stats_html(stats, self.app_path,\n profile_id, *amount)\n description = \"Profiling information is generated by using\\\n '%s' profiler.\" % self.profile_module\n sort_repl = '' % (p, p)\n for p in self.profile_log.get_all_pids()])\n profile_element = string.Template(profile_tmpl).substitute(\n {'profile_list': plist})\n profile_repl = '