Skip to content

Commit beb282a

Browse files
committed
feat: 添加新脚本
来自: https://greasyfork.org/zh-CN/scripts/548837
1 parent eea07bd commit beb282a

File tree

9 files changed

+288
-0
lines changed

9 files changed

+288
-0
lines changed

docs/ScriptsPath.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,20 @@
11161116
"icon": "https://raw.githubusercontent.com/ChinaGodMan/UserScriptsHistory/main/scriptsIcon/x.svg",
11171117
"readme_locales": "zh-TW,vi,en,ko",
11181118
"script_locales": null
1119+
},
1120+
{
1121+
"name": "github-clone-button",
1122+
"description": "",
1123+
"group": "GitHub 脚本",
1124+
"js_name": "github-clone-button.user.js",
1125+
"directory": "github-clone-button",
1126+
"version": "2026.3.16.1",
1127+
"greasyfork_id": null,
1128+
"created_at": "2026-03-16 15:12:45",
1129+
"preview": "https://raw.githubusercontent.com/Poker-sang/GitHubCopyButton/main/.github/glance.png",
1130+
"icon": "https://raw.githubusercontent.com/ChinaGodMan/UserScriptsHistory/main/scriptsIcon/github-commit-viewer.png",
1131+
"readme_locales": "zh-TW,vi,en,ko",
1132+
"script_locales": null
11191133
}
11201134
]
11211135
}

github-clone-button/AUTHORS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!---->
2+
<!--AUTHORS-->
3+
<!--AUTHORS-END-->
4+
<!--OTHERS-->
5+
<!--OTHERS-END-->

github-clone-button/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# **🛠️ github-clone 更新日志**
2+
3+
### **📅 2026.3.16.1**
4+
5+
**新增**: •初始版本
6+
7+
---

github-clone-button/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<a id="top"></a>
2+
3+
<!--NAVIGATION-->
4+
<!--NAVIGATION-END-->
5+
<!--SHIELDS-->
6+
<!--SHIELDS-END-->
7+
<!--HISTORY-->
8+
<!--HISTORY-END-->
9+
<!--TEXT-->
10+
# GitHub 一键复制带子模块的 Clone 命令
11+
12+
用于在 GitHub 仓库页面的 **Code 按钮旁边添加一个复制按钮**,可以一键复制包含 **submodules(子模块)** 的完整 `git clone` 命令。
13+
14+
## 功能
15+
16+
- 在 GitHub 仓库页面 **Code 按钮旁边添加复制按钮**
17+
- 一键复制包含子模块的克隆命令:`git clone --recurse-submodules https://github.com/<owner>/<repo>.git`
18+
- 修复使用中文脚本无法显示按钮的问题
19+
20+
<!--AUTHORS-->
21+
<!--AUTHORS-END-->
22+
<!--SCREENSHOT-->
23+
![sc](https://raw.githubusercontent.com/Poker-sang/GitHubCopyButton/main/.github/glance.png)
24+
<!--SCREENSHOT-END-->
25+
<!--TEXT-END-->
26+
27+
<!--RELATED-->
28+
<!--RELATED-END-->
29+
<!--HELP-->
30+
<!--HELP-END-->
31+
<!--FOOTER-->
32+
33+
<img height="6px" width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest">
34+
<center><div align="center"><p><a href="https://github.com/ChinaGodMan/UserScripts#readme"><strong>更多用户脚本</strong></a> /<a href="#top">回到顶部↑</a></p></div></center>
35+
36+
<!--FOOTER--END-->

github-clone-button/README_en.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<a id="top"></a>
2+
3+
<!--NAVIGATION-->
4+
<!--NAVIGATION-END-->
5+
<!--SHIELDS-->
6+
<!--SHIELDS-END-->
7+
<!--HISTORY-->
8+
<!--HISTORY-END-->
9+
<!--TEXT-->
10+
11+
<!--AUTHORS-->
12+
<!--AUTHORS-END-->
13+
<!--SCREENSHOT-->
14+
15+
<!--SCREENSHOT-END-->
16+
<!--TEXT-END-->
17+
18+
<!--RELATED-->
19+
<!--RELATED-END-->
20+
<!--HELP-->
21+
<!--HELP-END-->
22+
<!--FOOTER-->
23+
24+
<img height="6px" width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest">
25+
<center><div align="center"><p><a href="https://github.com/ChinaGodMan/UserScripts#readme"><strong>更多用户脚本</strong></a> /<a href="#top">回到顶部↑</a></p></div></center>
26+
27+
<!--FOOTER--END-->

github-clone-button/README_ko.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<a id="top"></a>
2+
3+
<!--NAVIGATION-->
4+
<!--NAVIGATION-END-->
5+
<!--SHIELDS-->
6+
<!--SHIELDS-END-->
7+
<!--HISTORY-->
8+
<!--HISTORY-END-->
9+
<!--TEXT-->
10+
11+
<!--AUTHORS-->
12+
<!--AUTHORS-END-->
13+
<!--SCREENSHOT-->
14+
15+
<!--SCREENSHOT-END-->
16+
<!--TEXT-END-->
17+
18+
<!--RELATED-->
19+
<!--RELATED-END-->
20+
<!--HELP-->
21+
<!--HELP-END-->
22+
<!--FOOTER-->
23+
24+
<img height="6px" width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest">
25+
<center><div align="center"><p><a href="https://github.com/ChinaGodMan/UserScripts#readme"><strong>更多用户脚本</strong></a> /<a href="#top">回到顶部↑</a></p></div></center>
26+
27+
<!--FOOTER--END-->

github-clone-button/README_vi.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<a id="top"></a>
2+
3+
<!--NAVIGATION-->
4+
<!--NAVIGATION-END-->
5+
<!--SHIELDS-->
6+
<!--SHIELDS-END-->
7+
<!--HISTORY-->
8+
<!--HISTORY-END-->
9+
<!--TEXT-->
10+
11+
<!--AUTHORS-->
12+
<!--AUTHORS-END-->
13+
<!--SCREENSHOT-->
14+
15+
<!--SCREENSHOT-END-->
16+
<!--TEXT-END-->
17+
18+
<!--RELATED-->
19+
<!--RELATED-END-->
20+
<!--HELP-->
21+
<!--HELP-END-->
22+
<!--FOOTER-->
23+
24+
<img height="6px" width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest">
25+
<center><div align="center"><p><a href="https://github.com/ChinaGodMan/UserScripts#readme"><strong>更多用户脚本</strong></a> /<a href="#top">回到顶部↑</a></p></div></center>
26+
27+
<!--FOOTER--END-->
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<a id="top"></a>
2+
3+
<!--NAVIGATION-->
4+
<!--NAVIGATION-END-->
5+
<!--SHIELDS-->
6+
<!--SHIELDS-END-->
7+
<!--HISTORY-->
8+
<!--HISTORY-END-->
9+
<!--TEXT-->
10+
11+
<!--AUTHORS-->
12+
<!--AUTHORS-END-->
13+
<!--SCREENSHOT-->
14+
15+
<!--SCREENSHOT-END-->
16+
<!--TEXT-END-->
17+
18+
<!--RELATED-->
19+
<!--RELATED-END-->
20+
<!--HELP-->
21+
<!--HELP-END-->
22+
<!--FOOTER-->
23+
24+
<img height="6px" width="100%" src="https://media.chatgptautorefresh.com/images/separators/gradient-aqua.png?latest">
25+
<center><div align="center"><p><a href="https://github.com/ChinaGodMan/UserScripts#readme"><strong>更多用户脚本</strong></a> /<a href="#top">回到顶部↑</a></p></div></center>
26+
27+
<!--FOOTER--END-->
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// ==UserScript==
2+
// @name Github copy clone command button(fork)
3+
// @name:zh-CN GitHub 复制克隆命令按钮(fork)
4+
// @description Add a 1-click copy button with the "git clone --recurse-submodules ..." command, after the Code button on the GitHub repository page
5+
// @description:zh-CN 在 GitHub 仓库页面的“代码”按钮之后,添加一个使用“git clone --recurse-submodules ...”命令的一键复制按钮。
6+
// @author 人民的勤务员 <china.qinwuyuan@gmail.com>
7+
// @namespace https://github.com/ChinaGodMan/UserScripts
8+
// @supportURL https://github.com/ChinaGodMan/UserScripts/issues
9+
// @homepageURL https://github.com/ChinaGodMan/UserScripts
10+
// @homepage https://github.com/ChinaGodMan/UserScripts
11+
// @license MIT
12+
// @match https://github.com/*
13+
// @icon https://raw.githubusercontent.com/ChinaGodMan/UserScriptsHistory/main/scriptsIcon/github-commit-viewer.png
14+
// @grant GM_setClipboard
15+
// @compatible chrome
16+
// @compatible firefox
17+
// @compatible edge
18+
// @compatible opera
19+
// @compatible safari
20+
// @compatible kiwi
21+
// @compatible qq
22+
// @compatible via
23+
// @compatible brave
24+
// @version 2026.3.16.1
25+
// @created 2026-03-16 15:12:45
26+
// @downloadURL https://raw.githubusercontent.com/ChinaGodMan/UserScripts/main/github-clone/github-clone.user.js
27+
// @updateURL https://raw.githubusercontent.com/ChinaGodMan/UserScripts/main/github-clone/github-clone.user.js
28+
// ==/UserScript==
29+
30+
(function () {
31+
'use strict'
32+
33+
function getCloneCmd() {
34+
const match = location.pathname.match(/^\/([^/]+)\/([^/]+)(\/|$)/)
35+
if (!match) return null
36+
return `git clone --recurse-submodules https://github.com/${match[1]}/${match[2]}.git`
37+
}
38+
39+
function copyCloneCmd(cmd) {
40+
if (!cmd) return
41+
if (typeof GM_setClipboard === 'function') {
42+
GM_setClipboard(cmd)
43+
} else if (navigator.clipboard) {
44+
navigator.clipboard.writeText(cmd)
45+
}
46+
showTip(`Copied: ${cmd}`)
47+
}
48+
49+
function showTip(msg) {
50+
const tip = document.createElement('div')
51+
tip.textContent = msg
52+
tip.style.position = 'fixed'
53+
tip.style.top = '20px'
54+
tip.style.right = '20px'
55+
tip.style.background = '#28a745'
56+
tip.style.color = '#fff'
57+
tip.style.padding = '8px 16px'
58+
tip.style.borderRadius = '6px'
59+
tip.style.zIndex = 9999
60+
tip.style.fontSize = '16px'
61+
tip.style.boxShadow = '0 2px 8px rgba(0,0,0,0.15)'
62+
document.body.appendChild(tip)
63+
setTimeout(() => tip.remove(), 1800)
64+
}
65+
66+
function addCopyButton() {
67+
const cmd = getCloneCmd()
68+
if (!cmd) return
69+
const codeBtn = Array.from(document.querySelectorAll('button[class^="prc-Button-ButtonBase-"]')).find(
70+
btn => ['代码', 'Code'].includes(btn.textContent.trim())
71+
)
72+
if (!codeBtn) return
73+
if (document.getElementById('copy-clone-submodules-btn')) return
74+
75+
// SVG字符串多行可读
76+
const svg = `
77+
<svg aria-hidden="true" focusable="false" class="octicon octicon-copy" viewBox="0 0 16 16" width="16" height="16" fill="currentColor" display="inline-block" overflow="visible" style="vertical-align: text-bottom;">
78+
<path d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 0 1 0 1.5h-1.5a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-1.5a.75.75 0 0 1 1.5 0v1.5A1.75 1.75 0 0 1 9.25 16h-7.5A1.75 1.75 0 0 1 0 14.25Z"></path>
79+
<path d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0 1 14.25 11h-7.5A1.75 1.75 0 0 1 5 9.25Zm1.75-.25a.25.25 0 0 0-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 0 0 .25-.25v-7.5a.25.25 0 0 0-.25-.25Z"></path>
80+
</svg>
81+
`.trim()
82+
83+
// 克隆Code按钮
84+
const copyBtn = codeBtn.cloneNode(true)
85+
copyBtn.id = 'copy-clone-submodules-btn'
86+
87+
// 替换内容为SVG
88+
const contentSpan = copyBtn.querySelector('[data-component="buttonContent"]')
89+
if (contentSpan) {
90+
contentSpan.innerHTML = svg
91+
} else {
92+
copyBtn.innerHTML = svg
93+
}
94+
95+
// 设置title为命令内容
96+
copyBtn.title = cmd
97+
98+
// 移除aria-haspopup等下拉相关属性
99+
copyBtn.removeAttribute('aria-haspopup')
100+
copyBtn.removeAttribute('aria-expanded')
101+
copyBtn.removeAttribute('aria-describedby')
102+
103+
// 绑定复制事件
104+
copyBtn.addEventListener('click', function (e) {
105+
e.preventDefault()
106+
e.stopPropagation()
107+
copyCloneCmd(cmd)
108+
})
109+
110+
// 插入到Code按钮后
111+
codeBtn.parentNode.insertBefore(copyBtn, codeBtn.nextSibling)
112+
}
113+
114+
// 监听页面变化(支持pjax和动态加载)
115+
const observer = new MutationObserver(addCopyButton)
116+
observer.observe(document.body, { childList: true, subtree: true })
117+
addCopyButton()
118+
})()

0 commit comments

Comments
 (0)