Undiscovered Trending

Hide starred repos in trending and remove slob

// ==UserScript==
// @name        Undiscovered Trending
// @namespace   shiftgeist
// @icon	https://github.com/fluidicon.png
// @match       https://github.com/trending*
// @grant       none
// @version     20250402.2
// @author      shiftgeist
// @description Hide starred repos in trending and remove slob
// @license     GNU GPLv3
// ==/UserScript==

function log(...params) {
  if (localStorage.getItem('undiscovered-debug') === 'true') {
    console.log('[undiscovered]', ...params)
  }
}

function createIgnoreButton(ignoredRepos, urlToIgnore, callbackOnSuccess) {
  const button = document.createElement('button')
  button.className = 'Button--secondary Button--small Button ml-2 ignore-button'
  button.innerText = 'Ignore'
  button.onclick = () => {
    if (!ignoredRepos.includes(urlToIgnore)) {
      ignoredRepos.push(urlToIgnore)
      log('hello world', ignoredRepos)
      callbackOnSuccess()
      button.style.display = 'none'
      localStorage.setItem('undiscovered-ignored', JSON.stringify(ignoredRepos))
    }
  }
  return button
}

function main() {
  log('start of main')

  setTimeout(() => {
    log('delay done')

    const ignoredRepos = JSON.parse(localStorage.getItem('undiscovered-ignored') || '[]')

    const articles = document.querySelectorAll('article')

    for (const article of articles) {
      const url = article.querySelector('h2 a').getAttribute('href')
      const hasButton = article.querySelector('.ignore-button')
      const buttonsContainer = article.querySelector('.float-right.d-flex')
      if (!hasButton) {
        const button = createIgnoreButton(ignoredRepos, url, main)
        buttonsContainer.append(button)
      }

      if (
        // Already starred
        article.querySelector('.starred-button-icon').getClientRects().length > 0 ||
        // Ignored
        ignoredRepos.includes(url) ||
        // Contains AI
        [
          ' ai ',
          'ai assistant',
          'ai chat',
          'ai models',
          'ai-powered',
          'crypto',
          'deepseek',
          'defi',
          'gemini',
          'gpt',
          'llm',
          'mcp',
          'ollama',
          'openai',
          'qwenlm',
        ].findIndex(e => article.innerText.toLowerCase().includes(e)) >= 0
      ) {
        article.style.display = 'none'
      }
    }
  }, 300)
}

log('init')

let previousUrl = ''
const observer = new MutationObserver(function (mutations) {
  if (location.href !== previousUrl) {
    previousUrl = location.href
    main()
  }
})
const config = { subtree: true, childList: true }
observer.observe(document, config)

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址