{ // 获取包含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 std::string initial_request;\n tensorstore::internal::Thread serve_thread({\"serve_thread\"}, [&] {\n auto client_fd = AcceptNonBlocking(*socket);\n ABSL_CHECK(client_fd.has_value());\n initial_request = ReceiveAvailable(*client_fd);\n AssertSend(*client_fd, kResponse);\n CloseSocket(*client_fd);\n });\n auto response = transport->IssueRequest(\n HttpRequestBuilder(\"POST\", absl::StrCat(\"http:\n .AddHeader(\"X-foo: bar\")\n .AddQueryParameter(\"name\", \"dragon\")\n .AddQueryParameter(\"age\", \"1234\")\n .EnableAcceptEncoding()\n .BuildRequest(),\n IssueRequestOptions(absl::Cord(\"Hello\")));\n ABSL_LOG(INFO) << response.status();\n ABSL_LOG(INFO) << \"Wait on server\";\n serve_thread.Join();\n CloseSocket(*socket);\n EXPECT_THAT(initial_request, HasSubstr(\"POST /?name=dragon&age=1234\"));\n EXPECT_THAT(initial_request,\n HasSubstr(absl::StrCat(\"Host: \", hostport, \"\\r\\n\")));\n EXPECT_THAT(initial_request, HasSubstr(\"Accept: **\\r\\n\"));\n EXPECT_THAT(request, HasSubstr(\"X-foo: bar\\r\\n\"));\n EXPECT_THAT(request, HasSubstr(\"Content-Length: 5\"));\n EXPECT_THAT(\n request,\n HasSubstr(\"Content-Type: application/x-www-form-urlencoded\\r\\n\"));\n EXPECT_THAT(request, HasSubstr(\"Hello\"));\n }\n}\n} "},"Code Url":{"kind":"string","value":"https://github.com/google/tensorstore/blob/4f887a6430414cd6088e1743555015b10f116d50/tensorstore/internal/http/curl_transport.cc"},"Test Code Url":{"kind":"string","value":"https://github.com/google/tensorstore/blob/4f887a6430414cd6088e1743555015b10f116d50/tensorstore/internal/http/curl_transport_test.cc"},"Commit Hash":{"kind":"string","value":"4f887a6430414cd6088e1743555015b10f116d50"}}},{"rowIdx":405,"cells":{"ID":{"kind":"string","value":"3ba84d55-f639-42ee-a830-911c1b3bb133"},"Language":{"kind":"string","value":"cpp"},"Repository Name":{"kind":"string","value":"google/tensorstore"},"File Name":{"kind":"string","value":"zlib"},"File Path in Repository":{"kind":"string","value":"tensorstore/internal/compression/zlib.cc"},"File Path for Unit Test":{"kind":"string","value":"tensorstore/internal/compression/zlib_test.cc"},"Code":{"kind":"string","value":"#include \"tensorstore/internal/compression/zlib.h\"\n#include \"absl/base/optimization.h\"\n#include \"absl/log/absl_check.h\"\n#include \"absl/status/status.h\"\n#include \"tensorstore/internal/compression/cord_stream_manager.h\"\n#include \nnamespace tensorstore {\nnamespace zlib {\nnamespace {\nstruct InflateOp {\n static int Init(z_stream* s, [[maybe_unused]] int level, int header_option) {\n return inflateInit2(s, 15 \n + header_option);\n }\n static int Process(z_stream* s, int flags) { return inflate(s, flags); }\n static int Destroy(z_stream* s) { return inflateEnd(s); }\n static constexpr bool kDataErrorPossible = true;\n};\nstruct DeflateOp {\n static int Init(z_stream* s, int level, int header_option) {\n return deflateInit2(s, level, Z_DEFLATED,\n 15 \n + header_option,\n 8 ,\n Z_DEFAULT_STRATEGY);\n }\n static int Process(z_stream* s, int flags) { return deflate(s, flags); }\n static int Destroy(z_stream* s) { return deflateEnd(s); }\n static constexpr bool kDataErrorPossible = false;\n};\ntemplate \nabsl::Status ProcessZlib(const absl::Cord& input, absl::Cord* output, int level,\n bool use_gzip_header) {\n z_stream s = {};\n internal::CordStreamManager\n stream_manager(s, input, output);\n const int header_option = use_gzip_header ? 16 \n : 0;\n int err = Op::Init(&s, level, header_option);\n if (err != Z_OK) {\n ABSL_CHECK(false);\n }\n struct StreamDestroyer {\n z_stream* s;\n ~StreamDestroyer() { Op::Destroy(s); }\n } stream_destroyer{&s};\n while (true) {\n const bool input_complete = stream_manager.FeedInputAndOutputBuffers();\n err = Op::Process(&s, input_complete ? Z_FINISH : Z_NO_FLUSH);\n const bool made_progress = stream_manager.HandleOutput();\n if (err == Z_OK) continue;\n if (err == Z_BUF_ERROR && made_progress) continue;\n break;\n }\n switch (err) {\n case Z_STREAM_END:\n if (!stream_manager.has_input_remaining()) {\n return absl::OkStatus();\n }\n [[fallthrough]];\n case Z_NEED_DICT:\n case Z_DATA_ERROR:\n case Z_BUF_ERROR:\n if (!Op::kDataErrorPossible) {\n ABSL_CHECK(false);\n }\n return absl::InvalidArgumentError(\"Error decoding zlib-compressed data\");\n default:\n ABSL_CHECK(false);\n }\n ABSL_UNREACHABLE(); \n}\n} \nvoid Encode(const absl::Cord& input, absl::Cord* output,\n const Options& options) {\n ProcessZlib(input, output, options.level, options.use_gzip_header)\n .IgnoreError();\n}\nabsl::Status Decode(const absl::Cord& input, absl::Cord* output,\n bool use_gzip_header) {\n return ProcessZlib(input, output, 0, use_gzip_header);\n}\n} \n} "},"Unit Test - (Ground Truth)":{"kind":"string","value":"#include \"tensorstore/internal/compression/zlib.h\"\n#include \n#include \n#include \n#include \n#include \n#include \"absl/status/status.h\"\n#include \"absl/strings/cord.h\"\n#include \"absl/strings/cord_test_helpers.h\"\n#include \"tensorstore/util/status_testutil.h\"\nnamespace {\nusing ::tensorstore::MatchesStatus;\nnamespace zlib = tensorstore::zlib;\nclass ZlibCompressorTest : public ::testing::TestWithParam {};\nINSTANTIATE_TEST_SUITE_P(ZlibCompressorTestCases, ZlibCompressorTest,\n ::testing::Values(false, true));\nTEST_P(ZlibCompressorTest, SmallRoundtrip) {\n const bool use_gzip_header = GetParam();\n zlib::Options options{6, use_gzip_header};\n const absl::Cord input(\"The quick brown fox jumped over the lazy dog.\");\n absl::Cord encode_result(\"abc\"), decode_result(\"def\");\n zlib::Encode(input, &encode_result, options);\n ASSERT_GE(encode_result.size(), 3);\n EXPECT_EQ(\"abc\", encode_result.Subcord(0, 3));\n TENSORSTORE_ASSERT_OK(\n zlib::Decode(encode_result.Subcord(3, encode_result.size() - 3),\n &decode_result, options.use_gzip_header));\n EXPECT_EQ(\"def\" + std::string(input), decode_result);\n}\nTEST_P(ZlibCompressorTest, SmallRoundtripFragmented) {\n const bool use_gzip_header = GetParam();\n zlib::Options options{6, use_gzip_header};\n const absl::Cord input = absl::MakeFragmentedCord(\n {\"The quick\", \" brown fox\", \" jumped over\", \" \", \"the lazy dog.\"});\n absl::Cord encode_result(\"abc\"), decode_result(\"def\");\n zlib::Encode(input, &encode_result, options);\n ASSERT_GE(encode_result.size(), 3);\n EXPECT_EQ(\"abc\", encode_result.Subcord(0, 3));\n std::vector encode_result_fragments;\n for (size_t i = 3; i < encode_result.size(); ++i) {\n encode_result_fragments.push_back(std::string(encode_result.Subcord(i, 1)));\n }\n TENSORSTORE_ASSERT_OK(\n zlib::Decode(absl::MakeFragmentedCord(encode_result_fragments),\n &decode_result, options.use_gzip_header));\n EXPECT_EQ(\"def\" + std::string(input), decode_result);\n}\nTEST_P(ZlibCompressorTest, LargeRoundtrip) {\n const bool use_gzip_header = GetParam();\n std::string input(100000, '\\0');\n unsigned char x = 0;\n for (auto& v : input) {\n v = x;\n x += 7;\n }\n zlib::Options options{6, use_gzip_header};\n absl::Cord encode_result, decode_result;\n zlib::Encode(absl::Cord(input), &encode_result, options);\n ASSERT_EQ(absl::OkStatus(), zlib::Decode(encode_result, &decode_result,\n options.use_gzip_header));\n EXPECT_EQ(input, decode_result);\n}\nTEST_P(ZlibCompressorTest, NonDefaultLevel) {\n const bool use_gzip_header = GetParam();\n zlib::Options options1{\n 0, use_gzip_header}; \n zlib::Options options2{9, use_gzip_header};\n const absl::Cord input(\"The quick brown fox jumped over the lazy dog.\");\n absl::Cord encode_result1, encode_result2;\n zlib::Encode(input, &encode_result1, options1);\n zlib::Encode(input, &encode_result2, options2);\n EXPECT_NE(encode_result1, encode_result2);\n absl::Cord decode_result;\n TENSORSTORE_ASSERT_OK(\n zlib::Decode(encode_result2, &decode_result, options2.use_gzip_header));\n EXPECT_EQ(input, decode_result);\n}\nTEST_P(ZlibCompressorTest, DecodeCorruptData) {\n const bool use_gzip_header = GetParam();\n zlib::Options options{6, use_gzip_header};\n const absl::Cord input(\"The quick brown fox jumped over the lazy dog.\");\n {\n absl::Cord encode_result, decode_result;\n zlib::Encode(input, &encode_result, options);\n ASSERT_GE(encode_result.size(), 1);\n std::string corrupted(encode_result);\n corrupted[0] = 0;\n EXPECT_THAT(zlib::Decode(absl::Cord(corrupted), &decode_result,\n options.use_gzip_header),\n MatchesStatus(absl::StatusCode::kInvalidArgument));\n }\n {\n absl::Cord encode_result, decode_result;\n zlib::Encode(input, &encode_result, options);\n ASSERT_GE(encode_result.size(), 1);\n std::string corrupted(encode_result);\n corrupted.resize(corrupted.size() - 1);\n EXPECT_THAT(zlib::Decode(absl::Cord(corrupted), &decode_result,\n options.use_gzip_header),\n MatchesStatus(absl::StatusCode::kInvalidArgument));\n }\n}\n} "},"Code Url":{"kind":"string","value":"https://github.com/google/tensorstore/blob/4f887a6430414cd6088e1743555015b10f116d50/tensorstore/internal/compression/zlib.cc"},"Test Code Url":{"kind":"string","value":"https://github.com/google/tensorstore/blob/4f887a6430414cd6088e1743555015b10f116d50/tensorstore/internal/compression/zlib_test.cc"},"Commit Hash":{"kind":"string","value":"4f887a6430414cd6088e1743555015b10f116d50"}}},{"rowIdx":406,"cells":{"ID":{"kind":"string","value":"75a7738d-254a-4171-9083-e75edd0bb8bc"},"Language":{"kind":"string","value":"cpp"},"Repository Name":{"kind":"string","value":"google/tensorstore"},"File Name":{"kind":"string","value":"neuroglancer_compressed_segmentation"},"File Path in Repository":{"kind":"string","value":"tensorstore/internal/compression/neuroglancer_compressed_segmentation.cc"},"File Path for Unit Test":{"kind":"string","value":"tensorstore/internal/compression/neuroglancer_compressed_segmentation_test.cc"},"Code":{"kind":"string","value":"#include \"tensorstore/internal/compression/neuroglancer_compressed_segmentation.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \"absl/base/internal/endian.h\"\n#include \"absl/container/flat_hash_map.h\"\nnamespace tensorstore {\nnamespace neuroglancer_compressed_segmentation {\nconstexpr size_t kBlockHeaderSize = 2;\nvoid WriteBlockHeader(size_t encoded_value_base_offset,\n size_t table_base_offset, size_t encoding_bits,\n void* output) {\n absl::little_endian::Store32(output,\n table_base_offset | (encoding_bits << 24));\n absl::little_endian::Store32(static_cast(output) + 4,\n encoded_value_base_offset);\n}\ntemplate \nvoid EncodeBlock(const Label* input, const ptrdiff_t input_shape[3],\n const ptrdiff_t input_byte_strides[3],\n const ptrdiff_t block_shape[3], size_t base_offset,\n size_t* encoded_bits_output, size_t* table_offset_output,\n EncodedValueCache