{ // 获取包含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\r\n\n\n## With the media's timeupdate event\n\n\nI also tried the video's [timeupdate event](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/timeupdate_event), since their rate of fire depends on the browser's implementation:\n```\nconst video = document.querySelector(\"video\");\nconst captions = document.getElementById(\"captions\");\n\nconst trackElement = document.createElement(\"track\");\ntrackElement.src = getVttUrl();\nvideo.append(trackElement);\n\nconst track = trackElement.track;\ntrack.mode = \"hidden\";\n\nvideo.addEventListener(\"timeupdate\", () => {\n captions.replaceChildren(...Array.from(track.activeCues).map(cue => cue.getCueAsHTML()));\n});\n\nfunction getVttUrl() {\n const vtt = `WEBVTT\n\n00:00:00.000 --> 00:00:00.999 line:80%\nHildy!\n\n00:00:01.000 --> 00:00:01.499 line:80%\nHow are you?\n\n00:00:01.500 --> 00:00:02.999 line:80%\nTell me, is the lord of the universe in?\n\n00:00:03.000 --> 00:00:04.299 line:80%\nYes, he's in - in a bad humor\n\n00:00:04.300 --> 00:00:06.000 line:80%\nSomebody must've stolen the crown jewels\n`;\n\n const vttBlob = new Blob([vtt], { type: \"text/vtt\" });\n \n return URL.createObjectURL(vttBlob);\n}\n```\n```\n\n\n \n

\n\n```\n\r\n\n: Keep the `` element added to the media, so that [activeCues](https://developer.mozilla.org/en-US/docs/Web/API/TextTrack/activeCues) is still kept live!\n\n## With requestAnimationFrame()\n\n\nTechnically, using the [requestAnimationFrame() function](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame) should provide the most up-to-date captions possible, since it fires before frame:\n```\nconst video = document.querySelector(\"video\");\nconst captions = document.getElementById(\"captions\");\n\nconst trackElement = document.createElement(\"track\");\ntrackElement.src = getVttUrl();\nvideo.append(trackElement);\n\nconst track = trackElement.track;\ntrack.mode = \"hidden\";\n\ntrack.cues; // Accessing `cues` fixes a \"not iterable\" error (on Chrome)\nrequestAnimationFrame(function captionsCallback() {\n updateCaptions();\n requestAnimationFrame(captionsCallback);\n});\n\nfunction updateCaptions() {\n captions.replaceChildren(...Array.from(track.activeCues).map(cue => cue.getCueAsHTML()));\n}\n\nfunction getVttUrl() {\n const vtt = `WEBVTT\n\n00:00:00.000 --> 00:00:00.999 line:80%\nHildy!\n\n00:00:01.000 --> 00:00:01.499 line:80%\nHow are you?\n\n00:00:01.500 --> 00:00:02.999 line:80%\nTell me, is the lord of the universe in?\n\n00:00:03.000 --> 00:00:04.299 line:80%\nYes, he's in - in a bad humor\n\n00:00:04.300 --> 00:00:06.000 line:80%\nSomebody must've stolen the crown jewels\n`;\n\n const vttBlob = new Blob([vtt], { type: \"text/vtt\" });\n \n return URL.createObjectURL(vttBlob);\n}\n```\n```\n\n\n \n

\n\n```\n\r\n\nWe can decouple it from `TextTrack`'s `activeCues` by implementing a custom \"activeness evaluation\" using [HTMLMediaElement.currentTime](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/currentTime). This may be \"even more\" live:\n```\nconst video = document.querySelector(\"video\");\nconst captions = document.getElementById(\"captions\");\n\nconst trackElement = document.createElement(\"track\");\ntrackElement.src = getVttUrl();\nvideo.append(trackElement);\n\nconst track = trackElement.track;\ntrack.mode = \"hidden\";\n\ntrack.cues; // Accessing `cues` fixes a \"not iterable\" error (on Chrome)\nrequestAnimationFrame(function captionsCallback() {\n updateCaptions();\n requestAnimationFrame(captionsCallback);\n});\n\nfunction updateCaptions() {\n const activeCues = Array.from(track.cues).filter(cue => {\n // Check according to:\n // https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API#cue_timings (see \"Non-overlapping cue timing examples\")\n return cue.startTime <= video.currentTime && cue.endTime > video.currentTime;\n });\n captions.replaceChildren(...activeCues.map(cue => cue.getCueAsHTML()));\n}\n\nfunction getVttUrl() {\n const vtt = `WEBVTT\n\n00:00:00.000 --> 00:00:00.999 line:80%\nHildy!\n\n00:00:01.000 --> 00:00:01.499 line:80%\nHow are you?\n\n00:00:01.500 --> 00:00:02.999 line:80%\nTell me, is the lord of the universe in?\n\n00:00:03.000 --> 00:00:04.299 line:80%\nYes, he's in - in a bad humor\n\n00:00:04.300 --> 00:00:06.000 line:80%\nSomebody must've stolen the crown jewels\n`;\n\n const vttBlob = new Blob([vtt], { type: \"text/vtt\" });\n \n return URL.createObjectURL(vttBlob);\n}\n```\n```\n\n\n \n

\n\n```\n\r\n\n\n---\n\n\n\n# Comparing the methods\n\n\nHere you can try the methods from above yourself:\n```\nconst video = document.querySelector(\"video\");\n\nconst trackElement = document.createElement(\"track\");\ntrackElement.src = getVttUrl();\nvideo.append(trackElement);\n\nconst track = trackElement.track;\ntrack.mode = \"hidden\";\n\n(function captionsCuechange() {\n const captions = document.getElementById(\"cap-cuechange\");\n track.addEventListener(\"cuechange\", () => {\n captions.replaceChildren(...Array.from(track.activeCues).map(cue => cue.getCueAsHTML()));\n });\n})();\n\n(function captionsTimeupdate() {\n const captions = document.getElementById(\"cap-timeupdate\");\n\n video.addEventListener(\"timeupdate\", () => {\n captions.replaceChildren(...Array.from(track.activeCues).map(cue => cue.getCueAsHTML()));\n });\n})();\n\n(function captionsRequestAnimationFrame() {\n const captions = document.getElementById(\"cap-frame\");\n \n track.cues; // Accessing `cues` fixes a \"not iterable\" error (on Chrome)\n requestAnimationFrame(function captionsCallback() {\n updateCaptions();\n requestAnimationFrame(captionsCallback);\n });\n \n function updateCaptions() {\n const cuesAsHTML = Array.from(track.activeCues).map(cue => cue.getCueAsHTML());\n captions.replaceChildren(...cuesAsHTML);\n }\n})();\n\n(function captionsRequestAnimationFrameAndCurrentTime() {\n const captions = document.getElementById(\"cap-frame-current\");\n \n track.cues; // Accessing `cues` fixes a \"not iterable\" error (on Chrome)\n requestAnimationFrame(function captionsCallback() {\n updateCaptions();\n requestAnimationFrame(captionsCallback);\n });\n \n function updateCaptions() {\n const activeCues = Array.from(track.cues).filter(cue => {\n return cue.startTime <= video.currentTime && cue.endTime > video.currentTime;\n });\n const cuesAsHTML = activeCues.map(cue => cue.getCueAsHTML());\n captions.replaceChildren(...cuesAsHTML);\n }\n})();\n\nfunction getVttUrl() {\n const vtt = `WEBVTT\n\n00:00:00.000 --> 00:00:00.999 line:80%\nHildy!\n\n00:00:01.000 --> 00:00:01.499 line:80%\nHow are you?\n\n00:00:01.500 --> 00:00:02.999 line:80%\nTell me, is the lord of the universe in?\n\n00:00:03.000 --> 00:00:04.299 line:80%\nYes, he's in - in a bad humor\n\n00:00:04.300 --> 00:00:06.000 line:80%\nSomebody must've stolen the crown jewels\n`;\n\n const vttBlob = new Blob([vtt], { type: \"text/vtt\" });\n \n return URL.createObjectURL(vttBlob);\n}\n```\n```\n.caption {min-height: 1lh}\n```\n```\n\n\n \n
\n

On cuechange:

\n

\n
\n
\n

On timeupdate:

\n

\n
\n
\n

With requestAnimationFrame():

\n

\n
\n
\n

With requestAnimationFrame() and currentTime:

\n

\n
\n\n```\n\r\n\nAlso try scrubbing the timeline and see how the captions react!\n: You may want to try the custom activeness check with the other events as well.\n"},"Title":{"kind":"null"},"ContentLicense":{"kind":"string","value":"CC BY-SA 4.0"},"FavoriteCount":{"kind":"null"},"CreationDate":{"kind":"string","value":"2023-02-15T18:47:51.973"},"LastActivityDate":{"kind":"string","value":"2023-02-15T18:56:53.360"},"LastEditDate":{"kind":"string","value":"2023-02-15T18:56:53.360"},"LastEditorUserId":{"kind":"number","value":13561410,"string":"13,561,410"},"OwnerUserId":{"kind":"number","value":13561410,"string":"13,561,410"},"Tags":{"kind":"null"}}},{"rowIdx":1249603,"cells":{"Id":{"kind":"number","value":75464282,"string":"75,464,282"},"PostTypeId":{"kind":"number","value":2,"string":"2"},"AcceptedAnswerId":{"kind":"null"},"ParentId":{"kind":"number","value":75464160,"string":"75,464,160"},"Score":{"kind":"number","value":0,"string":"0"},"ViewCount":{"kind":"null"},"Body":{"kind":"string","value":"Use the [ClipRRect](https://api.flutter.dev/flutter/widgets/ClipRRect-class.html).\n```\nClipRRect(\n borderRadius: BorderRadius.circular(12),\n child: _tToImage(t)\n),\n```\n\n"},"Title":{"kind":"null"},"ContentLicense":{"kind":"string","value":"CC BY-SA 4.0"},"FavoriteCount":{"kind":"null"},"CreationDate":{"kind":"string","value":"2023-02-15T18:53:26.603"},"LastActivityDate":{"kind":"string","value":"2023-02-15T18:53:26.603"},"LastEditDate":{"kind":"null"},"LastEditorUserId":{"kind":"null"},"OwnerUserId":{"kind":"number","value":18504621,"string":"18,504,621"},"Tags":{"kind":"null"}}},{"rowIdx":1249604,"cells":{"Id":{"kind":"number","value":75464403,"string":"75,464,403"},"PostTypeId":{"kind":"number","value":2,"string":"2"},"AcceptedAnswerId":{"kind":"null"},"ParentId":{"kind":"number","value":5743027,"string":"5,743,027"},"Score":{"kind":"number","value":0,"string":"0"},"ViewCount":{"kind":"null"},"Body":{"kind":"string","value":"it's 2023 there might be other answers out there but here is one that is sure to work\n```\n//the path where your text/paint will be drawn across\n Path path = new Path();\n\n path.addArc(mEventsRect, fStartAngle, fSweepAngle);//add this if you want your path to be drawn across the arc of your sector\n\n //if you are using a text get the width\n float textWidth = mTextPaint.measureText(\"text\");\n\n //this is the y co-ordinate your text will start from\n int hOffset = 100;\n\n //this is the x co-ordinate your text will start from\n int vOffset = 100;\n\n //we will be using the matrix to rotate the bunds of our current path\n Matrix matrix = new Matrix();\n\n //we will use this to get the bounds of our current path\n RectF bounds = new RectF();\n\n path.computeBounds(bounds,true);\n\n //we are using the matrix to rotate the bound (with is the bound of the path) by 90 degrees\n matrix.setRotate(90,bounds.centerX(),bounds.centerY());\n\n the we transform the points in the path using the matrix\n path.transform(matrix);\n\n //you can now draw the text on the path\n canvas.drawTextOnPath(\"text\", path, hOffset, vOffset , mBgPaints);\n```\n\n"},"Title":{"kind":"null"},"ContentLicense":{"kind":"string","value":"CC BY-SA 4.0"},"FavoriteCount":{"kind":"null"},"CreationDate":{"kind":"string","value":"2023-02-15T19:06:08.803"},"LastActivityDate":{"kind":"string","value":"2023-02-15T19:06:08.803"},"LastEditDate":{"kind":"null"},"LastEditorUserId":{"kind":"null"},"OwnerUserId":{"kind":"number","value":11779243,"string":"11,779,243"},"Tags":{"kind":"null"}}},{"rowIdx":1249605,"cells":{"Id":{"kind":"number","value":75464586,"string":"75,464,586"},"PostTypeId":{"kind":"number","value":2,"string":"2"},"AcceptedAnswerId":{"kind":"null"},"ParentId":{"kind":"number","value":75464109,"string":"75,464,109"},"Score":{"kind":"number","value":0,"string":"0"},"ViewCount":{"kind":"null"},"Body":{"kind":"string","value":"Try something like this:\n```\ndrop table #test\nSELECT 1 YEAR, 100 DVALUE, 2 PERSON\nINTO #TEST\nUNION ALL\nSELECT 2 YEAR, 100 DVALUE, 2 PERSON\nUNION ALL\nSELECT 3 YEAR, 150 DVALUE, 2 PERSON\nUNION ALL\nSELECT 4 YEAR, 100 DVALUE, 2 PERSON\nUNION ALL\nSELECT 5 YEAR, 100 DVALUE, 2 PERSON\n\nselect person, dvalue, MIN(year) AS startyear, max(year) AS endyear\nfrom (\n select count(case when prevvalue <> dvalue then 1 end) over(partition by person order by year) as cnt\n , *\n from (\n select *\n , LAG(DValue) OVER(PARTITION BY Person ORDER BY Year) AS prevValue\n from #TEST\n ) x\n ) x\ngroup by person, dvalue, cnt\norder by person, MIN(year)\n```\n\nIt's a very standard LAG / COUNT technique which finds \"groups\" of same values as previous ones. After you have that, it's easy to GROUP BY and get the edges\n"},"Title":{"kind":"null"},"ContentLicense":{"kind":"string","value":"CC BY-SA 4.0"},"FavoriteCount":{"kind":"null"},"CreationDate":{"kind":"string","value":"2023-02-15T19:27:27.043"},"LastActivityDate":{"kind":"string","value":"2023-02-15T21:03:51.773"},"LastEditDate":{"kind":"string","value":"2023-02-15T21:03:51.773"},"LastEditorUserId":{"kind":"number","value":13061224,"string":"13,061,224"},"OwnerUserId":{"kind":"number","value":13061224,"string":"13,061,224"},"Tags":{"kind":"null"}}},{"rowIdx":1249606,"cells":{"Id":{"kind":"number","value":75464641,"string":"75,464,641"},"PostTypeId":{"kind":"number","value":2,"string":"2"},"AcceptedAnswerId":{"kind":"null"},"ParentId":{"kind":"number","value":75459674,"string":"75,459,674"},"Score":{"kind":"number","value":1,"string":"1"},"ViewCount":{"kind":"null"},"Body":{"kind":"string","value":"I faced the same problem while making the git graph, I solved it using `sleep