Skip to content

Instantly share code, notes, and snippets.

@pedoc
Last active August 19, 2025 05:15
Show Gist options
  • Save pedoc/c0dbc5eed87d37ceedf9b436b6213b49 to your computer and use it in GitHub Desktop.
Save pedoc/c0dbc5eed87d37ceedf9b436b6213b49 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name GitHub Stars:隐藏我已 Star 的仓库
// @namespace https://github.com/
// @version 1.3
// @description 在 stars 页面(/stars/* 或 ?tab=stars)自动隐藏你已经 Star 的仓库,支持懒加载。
// @author You
// @include /^https:\/\/github\.com\/(?:stars\/[^\/?#]+|[^\/?#]+(?:\?.*?\btab=stars\b).*)$/
// @run-at document-idle
// @grant none
// ==/UserScript==
(function() {
"use strict";
function isVisible(el) {
if (!el)
return false;
const rect = el.getBoundingClientRect();
return rect.width > 0 && rect.height > 0;
}
function hideStarred() {
const elements = document.querySelectorAll("div.starred.BtnGroup")
//console.log(elements)
elements.forEach(el => {
const card = el?.parentElement?.parentElement?.parentElement;
if (!card || !isVisible(el))
return;
console.log('hide:', card)
card.style.setProperty("display", "none", "important");
}
);
}
// 先执行一次
//hideStarred();
let timeout = undefined;
// 监听页面变化(GitHub Stars 是懒加载 / 动态加载的)
const observer = new MutationObserver( () => {
// clearTimeout(timeout);
// timeout = setTimeout(hideStarred, 500);
hideStarred()
}
);
observer.observe(document.body, {
childList: true,
subtree: true
});
//document.addEventListener('pjax:end', hideStarred);
//document.addEventListener('turbo:load', hideStarred);
}
)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment