-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
30 lines (27 loc) · 988 Bytes
/
Copy pathcontent.js
File metadata and controls
30 lines (27 loc) · 988 Bytes
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
// Matches commit-author links like:
// /org/repo/commits?author=username
// /org/repo/commits/branch?author=username
// Rewrites them to: /username (the user's profile)
const AUTHOR_COMMIT_LINK = /^\/[^/]+\/[^/]+\/commits(\/[^?]*)?\?author=(.+)$/;
function rewriteLinks() {
const links = document.querySelectorAll('a[href*="commits?author="], a[href*="commits/?author="]');
for (const link of links) {
const path = link.pathname + link.search;
const match = path.match(AUTHOR_COMMIT_LINK);
if (match) {
const username = decodeURIComponent(match[2]);
link.href = `https://github.com/${username}`;
}
}
}
rewriteLinks();
// GitHub uses Turbo (pjax-style navigation), so we need to catch DOM changes
let pending = null;
const observer = new MutationObserver(() => {
if (pending) return;
pending = requestAnimationFrame(() => {
rewriteLinks();
pending = null;
});
});
observer.observe(document.body, { childList: true, subtree: true });