-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-release-highlight.user.js
107 lines (96 loc) · 3.32 KB
/
github-release-highlight.user.js
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
// ==UserScript==
// @name GitHub Release Highlight
// @namespace https://github.com/Vinfall/UserScripts
// @version 4.2.3
// @author Vinfall
// @match https://github.com/*/*/releases/tag/*
// @grant none
// @license GPL-3.0-only
// @run-at document-end
// @icon data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>💡</text></svg>
// @description Highlight GitHub release assets containing keywords
// ==/UserScript==
// TODO: Support "https://github.com/*/*/releases"
// Skip highlightKeywords if handleSpecialMatching matches
// Support other git hosting services like gitlab, codeberg etc.
// General highlight keywords
// biome-ignore format: do not touch my list
const keywords = [
// Windows
'Windows-Portable-x86_64',
'win_x64.zip', 'windows-x86_64.zip', 'Win64.zip',
'msixbundle',
'.exe',
// Hash
'SHA256SUM',
'checksums',
];
const attributeShape = [
{ name: 'repo', type: 'string' },
{ name: 'asset', type: 'string' },
];
const uniqueValues = [
// Repo-specific highlight keywords
['Hibbiki/chromium-win64', 'nosync.7z'],
['obsidianmd/obsidian-releases', 'arm64.tar.gz'],
];
const services = [
// Differentiate Git hosting services
{
domain: 'github.com',
ul: '.Box--condensed > ul',
asset: 'a.' + 'Truncate',
},
];
// Pick selector by domain
const url = window.location.href;
for (const service of services) {
if (url.includes(service.domain)) {
ulSelector = service.ul;
assetSelector = service.asset;
break; // exit loop once matched
}
}
// Function to change the color of text if it includes any keyword
function highlightKeywords(element) {
for (const keyword of keywords) {
if (element.textContent.includes(keyword)) {
// console.log("Catching" + element.textContent)
element.style.color = '#7ce49a';
}
}
}
// Function to handle special matching for specific repositories
function handleSpecialMatching(element) {
// Iterating over the unique values with the new array format
for (let i = 0; i < uniqueValues.length; i++) {
const [repo, asset] = uniqueValues[i]; // Destructure the flat array
if (location.href.includes(repo) && element.textContent.includes(asset)) {
// console.log("Special matching for repo: " + unique.repo);
element.style.color = '#7ce49a';
}
}
}
// Callback function for the MutationObserver
function handleMutation(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
const ul = document.querySelector('.Box--condensed > ul');
if (ul) {
const links = ul.querySelectorAll(`a.${targetClass}`);
for (const element of links) {
handleSpecialMatching(element);
highlightKeywords(element);
}
observer.disconnect(); // Stop observing once the ul element is found
}
}
}
}
// Create a new MutationObserver
const observer = new MutationObserver(handleMutation);
// Start observing the body for changes
observer.observe(document.body, {
childList: true,
subtree: true,
});