forked from gxr404/go-deepwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtampermonkey-script.js
More file actions
178 lines (156 loc) · 5.02 KB
/
tampermonkey-script.js
File metadata and controls
178 lines (156 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// ==UserScript==
// @name github-deepread
// @namespace
// @version 0.1
// @description GitHub仓库阅读分析
// @source https://github.com/wuding129/github-deepread
// @author wuding129
// @match https://github.com/*
// @grant GM_addStyle
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 添加动画效果
GM_addStyle(`
/* 下拉容器 */
.go-deepwiki-dropdown {
position: relative;
display: inline-block;
margin-right: 10px;
}
/* 下拉按钮 */
.go-deepwiki-dropbtn {
background-color: #2da44e;
color: white;
padding: 6px 12px 6px 10px;
font-size: 12px;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
display: flex;
align-items: center;
gap: 4px;
transition: background-color 0.2s;
}
.go-deepwiki-dropbtn:hover {
background-color: #2c974b;
}
/* 箭头图标动画 */
.go-deepwiki-dropbtn.active svg {
transform: rotate(180deg);
transition: transform 0.3s ease;
}
/* 下拉菜单动画 */
.go-deepwiki-dropdown-content {
position: absolute;
background-color: #f6f8fa;
min-width: 120px;
box-shadow: 0 3px 12px rgba(0,0,0,0.15);
border: 1px solid #d0d7de;
border-radius: 6px;
z-index: 1000;
top: calc(100% + 5px);
left: 0;
opacity: 0;
transform: scaleY(0.8) translateY(-10px);
transform-origin: top center;
transition:
opacity 0.3s ease,
transform 0.3s ease,
visibility 0.3s;
visibility: hidden;
}
.go-deepwiki-dropdown-content.show {
opacity: 1;
transform: scaleY(1) translateY(0);
visibility: visible;
}
/* 菜单项动画 */
.go-deepwiki-dropdown-content a {
display: flex;
align-items: center;
padding: 8px 12px;
text-decoration: none;
color: #24292f;
font-size: 12px;
border-bottom: 1px solid #eaecef;
transition: all 0.2s;
}
.go-deepwiki-dropdown-content a:hover {
background: #818b9826;
}
`);
const bodyEl = document.querySelector('body');
if (bodyEl) {
watchDom(bodyEl, main);
main();
}
// 全局监听点击事件
document.addEventListener('click', function(e) {
const dropdowns = document.querySelectorAll('.go-deepwiki-dropdown');
dropdowns.forEach(dropdown => {
const btn = dropdown.querySelector('.go-deepwiki-dropbtn');
const content = dropdown.querySelector('.go-deepwiki-dropdown-content');
if (!dropdown.contains(e.target)) {
content.classList.remove('show');
btn.classList.remove('active');
}
});
});
})();
function watchDom(dom, callback) {
const observer = new MutationObserver(callback);
observer.observe(dom, { childList: true, subtree: true });
}
function main() {
if (document.getElementById('go-deepwiki')) return;
const repoBtnContainer = document.getElementById('repository-details-container');
if (!repoBtnContainer) return;
const btnList = repoBtnContainer.querySelector('ul');
if (!btnList) return;
btnList.appendChild(createDropDownDOM());
}
function createDropDownDOM() {
const li = document.createElement('li');
li.id = "go-deepwiki";
const repName = location.pathname.split('/').filter(Boolean).slice(0,2).join('/');
const deepWikiUrl = `https://deepwiki.com/${repName}`;
const codeWikiXUrl = `https://codewiki.google/github.com/${repName}`;
const zreadUrl = `https://zread.ai/${repName}`;
const readmeXUrl = `https://readmex.com/${repName}`;
// 箭头SVG
const arrowSVG = `<svg class="go-deepwiki-arrow" aria-hidden="true" focusable="false" viewBox="0 0 16 16" width="12" height="12" fill="currentColor" style="vertical-align: text-bottom; transition: transform 0.3s;">
<path d="m4.427 7.427 3.396 3.396a.25.25 0 0 0 .354 0l3.396-3.396A.25.25 0 0 0 11.396 7H4.604a.25.25 0 0 0-.177.427Z"></path>
</svg>`;
li.innerHTML = `
<div class="go-deepwiki-dropdown">
<button class="go-deepwiki-dropbtn" aria-haspopup="true">
DeepRead
${arrowSVG}
</button>
<div class="go-deepwiki-dropdown-content" role="menu">
<a href="${deepWikiUrl}" target="_blank" rel="nofollow" role="menuitem">DeepWiki</a>
<a href="${codeWikiXUrl}" target="_blank" rel="nofollow" role="menuitem">CodeWiki</a>
<a href="${zreadUrl}" target="_blank" rel="nofollow" role="menuitem">Zread</a>
<a href="${readmeXUrl}" target="_blank" rel="nofollow" role="menuitem">ReadmeX</a>
</div>
</div>
`;
// 绑定点击事件
const dropBtn = li.querySelector('.go-deepwiki-dropbtn');
const dropContent = li.querySelector('.go-deepwiki-dropdown-content');
dropBtn.addEventListener('click', function(e) {
e.stopPropagation();
const isShowing = dropContent.classList.contains('show');
if (isShowing) {
dropContent.classList.remove('show');
dropBtn.classList.remove('active');
} else {
dropContent.classList.add('show');
dropBtn.classList.add('active');
}
});
return li;
}