Skip to content

Commit 901d993

Browse files
xiaohuohumaxgithub-actions[bot]
authored andcommitted
build: 📦 build user script
1 parent aae83d7 commit 901d993

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// ==UserScript==
2+
// @name GitHub 仪表盘页面自动加载更多(GitHub Dashboard Auto More)
3+
// @namespace xiaohuohumax/userscripts/dashboard-auto-more
4+
// @version 1.0.0
5+
// @author xiaohuohumax
6+
// @description 我负责点,你负责看!
7+
// @license MIT
8+
// @icon https://github.githubassets.com/favicons/favicon-dark.png
9+
// @source https://github.com/xiaohuohumax/userscripts.git
10+
// @downloadURL https://raw.githubusercontent.com/xiaohuohumax/userscripts/main/dist/dashboard-auto-more.user.js
11+
// @updateURL https://raw.githubusercontent.com/xiaohuohumax/userscripts/main/dist/dashboard-auto-more.user.js
12+
// @match https://github.com
13+
// @noframes
14+
// ==/UserScript==
15+
16+
(function () {
17+
'use strict';
18+
19+
const debounce = ({ delay }, func) => {
20+
let timer = void 0;
21+
let active = true;
22+
const debounced = (...args) => {
23+
if (active) {
24+
clearTimeout(timer);
25+
timer = setTimeout(() => {
26+
active && func(...args);
27+
timer = void 0;
28+
}, delay);
29+
} else {
30+
func(...args);
31+
}
32+
};
33+
debounced.isPending = () => {
34+
return timer !== void 0;
35+
};
36+
debounced.cancel = () => {
37+
active = false;
38+
};
39+
debounced.flush = (...args) => func(...args);
40+
return debounced;
41+
};
42+
const ID = "github-dashboard-auto-more";
43+
const VERSION = "1.0.0";
44+
console.log(`${ID}(v${VERSION})`);
45+
function autoClick() {
46+
const selectors = ".ajax-pagination-btn.color-bg-overlay";
47+
const moreButton = document.querySelector(selectors);
48+
if (!moreButton) {
49+
return;
50+
}
51+
const rect = moreButton.getBoundingClientRect();
52+
const isVisible = rect.top < window.innerHeight * 2 && rect.bottom > 0;
53+
isVisible && moreButton.click();
54+
}
55+
const handleScroll = debounce({ delay: 100 }, autoClick);
56+
handleScroll();
57+
window.addEventListener("scroll", handleScroll);
58+
59+
})();

0 commit comments

Comments
 (0)