{ // 获取包含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 !== '免费Z-image图片生成' && linkText !== '免费Z-image图片生成' ) { link.textContent = '免费Z-image图片生成'; link.href = 'https://zimage.run'; 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 !== 'Vibevoice' ) { link.textContent = 'Vibevoice'; link.href = 'https://vibevoice.info/'; replacedLinks.add(link); } // 替换Pricing链接 - 仅替换一次 else if ( (linkHref.includes('/pricing') || linkHref === '/pricing' || linkText === 'Pricing' || linkText.match(/^s*Pricings*$/i)) && linkText !== '免费去水印' ) { link.textContent = '免费去水印'; link.href = 'https://sora2watermarkremover.net/'; replacedLinks.add(link); } // 替换Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) && linkText !== 'GitHub加速' ) { link.textContent = 'GitHub加速'; link.href = 'https://githubproxy.cc'; 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, '免费Z-image图片生成'); } 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\nA: \n\nvar element = document.getElementById('element');\r\n\r\nelement.onclick = function() {\r\n element.classList.add('backGroundColor');\r\n \r\n setTimeout(function() {\r\n element.classList.remove('backGroundColor');\r\n }, 2000);\r\n};\n.backGroundColor {\r\n background-color: green;\r\n}\n
Click Me
\n\n\n\nA: You can try this\nvar element = document.getElementById('element_id');\nelement.style.backgroundColor = \"color or color_code\";\n\nExample.\nvar element = document.getElementById('firstname');\nelement.style.backgroundColor = \"green\";//Or #ff55ff\n\nJSFIDDLE\n\nA: KISS Answer:\ndocument.getElementById('element').style.background = '#DD00DD';\n\n\nA: You can do it with JQuery: \n$(\".class\").css(\"background\",\"yellow\");\n\n\nA: You might find your code is more maintainable if you keep all your styles, etc. in CSS and just set / unset class names in JavaScript.\nYour CSS would obviously be something like:\n.highlight {\n background:#ff00aa;\n}\n\nThen in JavaScript:\nelement.className = element.className === 'highlight' ? '' : 'highlight';\n\n\nA: You can use:\n\n\n\nA: $(\"body\").css(\"background\",\"green\"); //jQuery\n\ndocument.body.style.backgroundColor = \"green\"; //javascript\n\nso many ways are there I think it is very easy and simple\nDemo On Plunker\n\nA: $('#ID / .Class').css('background-color', '#FF6600');\n\nBy using jquery we can target the element's class or Id to apply css background or any other stylings\n\nA: var element = document.getElementById('element');\nelement.style.background = '#FF00AA';\n\n\nA: Or, using a little jQuery:\n$('#fieldID').css('background-color', '#FF6600');\n\n\nA: In general, CSS properties are converted to JavaScript by making them camelCase without any dashes. So background-color becomes backgroundColor.\nfunction setColor(element, color)\n{\n element.style.backgroundColor = color;\n}\n\n// where el is the concerned element\nvar el = document.getElementById('elementId');\nsetColor(el, 'green');\n\n\nA: you can use \n$('#elementID').css('background-color', '#C0C0C0');\n\n\nA: Changing CSS of a HTMLElement\nYou can change most of the CSS properties with JavaScript, use this statement:\ndocument.querySelector().style[] = \n\nwhere , , are all String objects.\nUsually, the style property will have the same name as the actual name used in CSS. But whenever there is more that one word, it will be camel case: for example background-color is changed with backgroundColor.\nThe following statement will set the background of #container to the color red:\ndocumentquerySelector('#container').style.background = 'red'\n\nHere's a quick demo changing the color of the box every 0.5s:\n\n\ncolors = ['rosybrown', 'cornflowerblue', 'pink', 'lightblue', 'lemonchiffon', 'lightgrey', 'lightcoral', 'blueviolet', 'firebrick', 'fuchsia', 'lightgreen', 'red', 'purple', 'cyan']\r\n\r\nlet i = 0\r\nsetInterval(() => {\r\n const random = Math.floor(Math.random()*colors.length)\r\n document.querySelector('.box').style.background = colors[random];\r\n}, 500)\n.box {\r\n width: 100px;\r\n height: 100px;\r\n}\n
\n\n\n\nChanging CSS of multiple HTMLElement\nImagine you would like to apply CSS styles to more than one element, for example, make the background color of all elements with the class name box lightgreen. Then you can:\n\n\n*\n\n*select the elements with .querySelectorAll and unwrap them in an object Array with the destructuring syntax:\nconst elements = [...document.querySelectorAll('.box')]\n\n\n*loop over the array with .forEach and apply the change to each element:\nelements.forEach(element => element.style.background = 'lightgreen')\n\nHere is the demo:\n\n\nconst elements = [...document.querySelectorAll('.box')]\r\nelements.forEach(element => element.style.background = 'lightgreen')\n.box {\r\n height: 100px;\r\n width: 100px;\r\n display: inline-block;\r\n margin: 10px;\r\n}\n
\r\n
\r\n
\r\n
\n\n\n\nAnother method\nIf you want to change multiple style properties of an element more than once you may consider using another method: link this element to another class instead.\nAssuming you can prepare the styles beforehand in CSS you can toggle classes by accessing the classList of the element and calling the toggle function:\n\n\ndocument.querySelector('.box').classList.toggle('orange')\n.box {\r\n width: 100px;\r\n height: 100px;\r\n}\r\n\r\n.orange {\r\n background: orange;\r\n}\n
\n\n\n\nList of CSS properties in JavaScript\nHere is the complete list:\nalignContent\nalignItems\nalignSelf\nanimation\nanimationDelay\nanimationDirection\nanimationDuration\nanimationFillMode\nanimationIterationCount\nanimationName\nanimationTimingFunction\nanimationPlayState\nbackground\nbackgroundAttachment\nbackgroundColor\nbackgroundImage\nbackgroundPosition\nbackgroundRepeat\nbackgroundClip\nbackgroundOrigin\nbackgroundSize\nbackfaceVisibility\nborderBottom\nborderBottomColor\nborderBottomLeftRadius\nborderBottomRightRadius\nborderBottomStyle\nborderBottomWidth\nborderCollapse\nborderColor\nborderImage\nborderImageOutset\nborderImageRepeat\nborderImageSlice\nborderImageSource \nborderImageWidth\nborderLeft\nborderLeftColor\nborderLeftStyle\nborderLeftWidth\nborderRadius\nborderRight\nborderRightColor\nborderRightStyle\nborderRightWidth\nborderSpacing\nborderStyle\nborderTop\nborderTopColor\nborderTopLeftRadius\nborderTopRightRadius\nborderTopStyle\nborderTopWidth\nborderWidth\nbottom\nboxShadow\nboxSizing\ncaptionSide\nclear\nclip\ncolor\ncolumnCount\ncolumnFill\ncolumnGap\ncolumnRule\ncolumnRuleColor\ncolumnRuleStyle\ncolumnRuleWidth\ncolumns\ncolumnSpan\ncolumnWidth\ncounterIncrement\ncounterReset\ncursor\ndirection\ndisplay\nemptyCells\nfilter\nflex\nflexBasis\nflexDirection\nflexFlow\nflexGrow\nflexShrink\nflexWrap\ncontent\nfontStretch\nhangingPunctuation\nheight\nhyphens\nicon\nimageOrientation\nnavDown\nnavIndex\nnavLeft\nnavRight\nnavUp>\ncssFloat\nfont\nfontFamily\nfontSize\nfontStyle\nfontVariant\nfontWeight\nfontSizeAdjust\njustifyContent\nleft\nletterSpacing\nlineHeight\nlistStyle\nlistStyleImage\nlistStylePosition\nlistStyleType\nmargin\nmarginBottom\nmarginLeft\nmarginRight\nmarginTop\nmaxHeight\nmaxWidth\nminHeight\nminWidth\nopacity\norder\norphans\noutline\noutlineColor\noutlineOffset\noutlineStyle\noutlineWidth\noverflow\noverflowX\noverflowY\npadding\npaddingBottom\npaddingLeft\npaddingRight\npaddingTop\npageBreakAfter\npageBreakBefore\npageBreakInside\nperspective\nperspectiveOrigin\nposition\nquotes\nresize\nright\ntableLayout\ntabSize\ntextAlign\ntextAlignLast\ntextDecoration\ntextDecorationColor\ntextDecorationLine\ntextDecorationStyle\ntextIndent\ntextOverflow\ntextShadow\ntextTransform\ntextJustify\ntop\ntransform\ntransformOrigin\ntransformStyle\ntransition\ntransitionProperty\ntransitionDuration\ntransitionTimingFunction\ntransitionDelay\nunicodeBidi\nuserSelect\nverticalAlign\nvisibility\nvoiceBalance\nvoiceDuration\nvoicePitch\nvoicePitchRange\nvoiceRate\nvoiceStress\nvoiceVolume\nwhiteSpace\nwidth\nwordBreak\nwordSpacing\nwordWrap\nwidows\nwritingMode\nzIndex\n\n\nA: Javascript:\ndocument.getElementById(\"ID\").style.background = \"colorName\"; //JS ID\n\ndocument.getElementsByClassName(\"ClassName\")[0].style.background = \"colorName\"; //JS Class\n\nJquery:\n$('#ID/.className').css(\"background\",\"colorName\") // One style\n\n$('#ID/.className').css({\"background\":\"colorName\",\"color\":\"colorname\"}); //Multiple style\n\n\nA: A simple js can solve this:\ndocument.getElementById(\"idName\").style.background = \"blue\";\n\n\nA: $(\".class\")[0].style.background = \"blue\";\n\n"},"meta":{"kind":"string","value":"{\n \"language\": \"en\",\n \"url\": \"https://stackoverflow.com/questions/3319\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"source\": \"stackexchange\",\n \"question_score\": \"129\"\n}"}}},{"rowIdx":343,"cells":{"text":{"kind":"string","value":"Q: Capturing TAB key in text box I would like to be able to use the Tab key within a text box to tab over four spaces. The way it is now, the Tab key jumps my cursor to the next input.\nIs there some JavaScript that will capture the Tab key in the text box before it bubbles up to the UI?\nI understand some browsers (i.e. FireFox) may not allow this. How about a custom key-combo like Shift+Tab, or Ctrl+Q?\n\nA: I would advise against changing the default behaviour of a key. I do as much as possible without touching a mouse, so if you make my tab key not move to the next field on a form I will be very aggravated.\nA shortcut key could be useful however, especially with large code blocks and nesting. Shift-TAB is a bad option because that normally takes me to the previous field on a form. Maybe a new button on the WMD editor to insert a code-TAB, with a shortcut key, would be possible?\n\nA: In Chrome on the Mac, alt-tab inserts a tab character into a
Subsets and Splits

No community queries yet

The top public SQL queries from the community will appear here once available.