{ // 获取包含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\nA: Getting the window width on resize isn't anything specific to Angular JS. in fact Angular doesn't provide any capability to do it. It's native javascript, the native window object fires a resize event that you can access. jQuery provides a handy wrapper for this. By using a simple callback in your controller and then updating your double bound windowWidth property on the $scope object you can get the functionality you need without using a directive.\n$(window).resize(function() {\n $scope.windowWidth = $( window ).width();\n});\n\n\nA: Just include this code in your controller and you will get the new window width every time.\n$scope.windowWidth = $window.innerWidth;\nangular.element($window).bind('resize', function(){\n $scope.windowWidth = $window.innerWidth;\n $scope.$apply();\n});\n\n\nA: The best way is to use a directive and watch for resize event of the window:\n'use strict';\n\nvar app = angular.module('plunker', []);\n\napp.directive('myDirective', ['$window', function ($window) {\n\n return {\n link: link,\n restrict: 'A' \n };\n\n function link(scope, element, attrs){\n\n angular.element($window).bind('resize', function(){\n scope.windowWidth = $window.innerWidth;\n }); \n } \n }]);\n\nAnd use it on your div:\n
320\">\n\nHere is a working plunker."},"language":{"kind":"string","value":"unknown"},"title":{"kind":"string","value":""}}},{"rowIdx":18603,"cells":{"_id":{"kind":"string","value":"d18604"},"partition":{"kind":"string","value":"test"},"text":{"kind":"string","value":"Creating/filling a structured array is a little tricky. There are various ways, but I think the simplest to remember is to use a list of tuples:\nIn [11]: np.array([tuple(row) for row in matrix], dtype=dt)\nOut[11]: \narray([('name', '23', '45', '1'), \n ('name2', '223', '43', '5'),\n ('name3', '12', '33', '2')], \n dtype=[('name', 'S10'), ('x', 'S10'), ('y', 'S10'), ('n', 'S10')])\n\nThe result is 1d array, with the dtype fields replacing the columns of the original 2d array. Each element of the new array has the same type - as specified by dt.\nOr you can create an empty array of the desired dtype, and fill it, row by row or field by field:\nIn [14]: arr = np.zeros((3,),dt) \nIn [16]: arr[0]=tuple(matrix[0,:]) # tuple of row\nIn [17]: arr['name']=matrix[:,0] # field\n\nIn [18]: arr\nOut[18]: \narray([('name', '23', '45', '1'), \n ('name2', '', '', ''),\n ('name3', '', '', '')], \n dtype=[('name', 'S10'), ('x', 'S10'), ('y', 'S10'), ('n', 'S10')])\n\nWith a compatible dt1, view would also work\ndt1 = numpy.dtype({'names':['name','x','y','n'],'formats': ['S5', 'S5', 'S5', 'S5']})\nmatrix.view(dt1)\n\nThis doesn't change the data; it just interprets the bytes differently.\n\nconverting the strings to numbers is easy with the list of tuples\nIn [40]: dt2 = numpy.dtype({'names':['name','x','y','n'],'formats': ['S5', 'f', 'f', 'i']})\n\nIn [41]: np.array([tuple(row) for row in matrix], dtype=dt2)Out[41]: \narray([('name', 23.0, 45.0, 1), \n ('name2', 223.0, 43.0, 5),\n ('name3', 12.0, 33.0, 2)], \n dtype=[('name', 'S5'), ('x', ' /etc/yum.repos.d/centos-appstream.repo <<'EOF'\n[appstream]\nname=CentOS Stream $releasever - AppStream\nmirrorlist=http://mirrorlist.centos.org/?release=$releasever-stream&arch=$basearch&repo=AppStream&infra=$infra\ngpgcheck=1\nenabled=0\ngpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial\nEOF\n\n\n\n*Install the CentOS 8 GPG key:\nrpm --import https://www.centos.org/keys/RPM-GPG-KEY-CentOS-Official\n\n\n\n*Enable the EPEL repository if you haven't already:\ndnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm\n\n\n\n*Install rlwrap:\ndnf --enablerepo=appstream install rlwrap\n\n\nAlternately, instead of installing rlwrap and it's myriad dependencies, just install socat:\nmicrodnf install socat\n\nAnd then use the readline and exec connectors:\nsocat readline exec:\"/path/to/some/program --arg foo\",pty"},"language":{"kind":"string","value":"unknown"},"title":{"kind":"string","value":""}}},{"rowIdx":18606,"cells":{"_id":{"kind":"string","value":"d18607"},"partition":{"kind":"string","value":"test"},"text":{"kind":"string","value":"Here's the solution. You have to iterate through all option elements, grab the value of every element and push inside an array.\n\n\nfunction getValues() {\r\n var array = document.getElementsByTagName('option');\r\n var arr = [];\r\n for (var i = 0; i < array.length; i++) {\r\n arr.push(array[i].value)\r\n }\r\n console.log(arr);\r\n};\n\r\n\n\n\nES6 solution:\n\n\nfunction getValues() {\r\n var array = document.getElementsByTagName('option');\r\n var arr = [];\r\n Array.from(array).forEach(v => arr.push(v.value));\r\n console.log(arr);\r\n};\n\r\n\n\n\n\nA: Assuming that ES6 is an option for you, then the following will do as you wish:\n// using a named function:\nfunction grabTextFrom() {\n\n // initialising the local variable using 'let',\n // converting the argument supplied to Array.from()\n // to convert the Array-like Object (in this case\n // a NodeList, or HTMLCollection, from\n // document.querySelectorAll()) into an Array:\n let texts = Array.from(\n document.querySelectorAll(\n\n // 'this' is passed automatically from the\n // later use of EventTarget.addEventListener(),\n // and the dataset.textFrom property value is\n // the value stored in the data-textfrom attribute:\n this.dataset.textfrom\n )\n\n // iterating over that Array of elements using\n // Array.prototype.map() along with an arrow function:\n ).map(\n\n // 'opt' is a reference to the current Array-element\n // from the Array of elements over which we're iterating;\n // and here we return the value property-value of that\n // current element:\n opt => opt.value\n );\n\n // logging to the console for demo purposes:\n console.log(texts);\n\n // returning to the calling context:\n return texts;\n}\n\n// finding the first element which matches the\n// supplied CSS selector, and adding the\n// grabTextFrom() function as the event-handler\n// for the 'click' event (note the deliberate\n// lack of parentheses in the function-name):\ndocument.querySelector('#submit').addEventListener('click', grabTextFrom);\n\n\n\nfunction grabTextFrom() {\r\n let texts = Array.from(\r\n document.querySelectorAll(this.dataset.textfrom)\r\n ).map(\r\n opt => opt.value\r\n );\r\n console.log(texts);\r\n return texts;\r\n}\r\n\r\ndocument.querySelector('#submit').addEventListener('click', grabTextFrom);\n\r\n\n\n\nIf, however, you have to provide for ES5 compatibility then the following will work identically:\nfunction grabTextFrom() {\n\n // here we use Array.prototype.slice(), along\n // with Function.prototype.call(), to apply\n // the slice() method to the supplied NodeList:\n var texts = Array.prototype.slice.call(\n document.querySelectorAll(this.dataset.textfrom)\n\n // here we use the anonymous function of the\n // Array.prototype.map() method to perform the\n // same function as above, returning the\n // opt.value property-value to the created Array:\n ).map(function(opt) {\n return opt.value;\n });\n console.log(texts);\n return texts;\n}\n\ndocument.querySelector('#submit').addEventListener('click', grabTextFrom);\n\n\n\nfunction grabTextFrom() {\r\n var texts = Array.prototype.slice.call(\r\n document.querySelectorAll(this.dataset.textfrom)\r\n ).map(function(opt) {\r\n return opt.value;\r\n });\r\n console.log(texts);\r\n return texts;\r\n}\r\n\r\ndocument.querySelector('#submit').addEventListener('click', grabTextFrom);\n\r\n\n\n\n\nA: You're close.\ndocument.getElementsByTagName('option') returns an array of