TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: I used ChatGPT to write a UserScript that removes all mentions of *GPT

1 点作者 skarz大约 2 年前
I have little to no coding experience, just basic HTML and CSS. This was generated entirely by ChatGPT with me giving the prompts. It took some trial and error but we got there:<p>&#x2F;&#x2F; ==UserScript== &#x2F;&#x2F; @name Block GPT Posts on Hacker News &#x2F;&#x2F; @namespace http:&#x2F;&#x2F;tampermonkey.net&#x2F; &#x2F;&#x2F; @version 0.1 &#x2F;&#x2F; @description Block posts containing the term &quot;GPT&quot; on news.ycombinator.com and renumber the remaining posts &#x2F;&#x2F; @author You &#x2F;&#x2F; @match https:&#x2F;&#x2F;news.ycombinator.com&#x2F;* &#x2F;&#x2F; @grant none &#x2F;&#x2F; ==&#x2F;UserScript==<p>(function() { &#x27;use strict&#x27;;<p><pre><code> function getStartingNumber() { const firstRankSpan = document.querySelector(&#x27;span.rank&#x27;); if (firstRankSpan) { const number = parseInt(firstRankSpan.textContent, 10); return isNaN(number) ? 1 : number; } return 1; } function blockGPTPosts() { const searchTerm = &#x2F;GPT&#x2F;i; const titleLines = document.querySelectorAll(&#x27;span.titleline&#x27;); const rankSpans = document.querySelectorAll(&#x27;span.rank&#x27;); const startingNumber = getStartingNumber(); let visiblePosts = []; titleLines.forEach((titleLine, index) =&gt; { const postLink = titleLine.querySelector(&#x27;a&#x27;); if (postLink &amp;&amp; searchTerm.test(postLink.textContent)) { const athingRow = titleLine.closest(&#x27;tr.athing&#x27;); if (athingRow) { athingRow.style.display = &#x27;none&#x27;; const subtextRow = athingRow.nextElementSibling; if (subtextRow &amp;&amp; subtextRow.querySelector(&#x27;td.subtext&#x27;)) { subtextRow.style.display = &#x27;none&#x27;; } } } else { visiblePosts.push(index); } }); visiblePosts.forEach((visiblePostIndex, index) =&gt; { const postNumber = startingNumber + index; if (rankSpans[visiblePostIndex]) { rankSpans[visiblePostIndex].textContent = `${postNumber}.`; } }); } &#x2F;&#x2F; Wait for the content to load before executing the function window.addEventListener(&#x27;load&#x27;, blockGPTPosts);</code></pre> })();

暂无评论

暂无评论