-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-release-highlight.user.js
76 lines (69 loc) · 2.56 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
// ==UserScript==
// @name GitHub Release Highlight
// @namespace https://github.com/Vinfall/UserScripts
// @version 2.2.0
// @author Vinfall
// @match https://github.com/*/*/releases/tag/*
// @grant none
// @license CC0 1.0 Universal (Public Domain)
// @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
// Function to change the color of text if it includes any keyword
function highlightKeywords(element) {
keywords.forEach(keyword => {
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) {
uniques.forEach(unique => {
if (location.href.includes(unique.repo) && element.textContent.includes(unique.asset)) {
// console.log("Special matching for repo: " + unique.repo);
element.style.color = '#7ce49a';
}
});
}
// Callback function for the MutationObserver
function handleMutation(mutationsList, observer) {
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
const ul = document.querySelector('.Box--condensed > ul');
if (ul) {
const links = ul.querySelectorAll('a.' + targetClass);
links.forEach(element => {
handleSpecialMatching(element);
highlightKeywords(element);
});
observer.disconnect(); // Stop observing once the ul element is found
}
}
}
}
const targetClass = 'Truncate';
// General highlight keywords
const keywords = ['Windows-Portable-x86_64', 'x64_Lite', 'x64_portable', 'Portable.x64.zip', 'win_x64.zip', '.exe'];
const uniques = [
// Repo-specific highlight keywords
{
repo: 'obsidianmd/obsidian-releases',
asset: 'arm64.tar.gz'
},
{
repo: 'Hibbiki/chromium-win64',
asset: 'nosync.7z'
}
];
// Create a new MutationObserver
const observer = new MutationObserver(handleMutation);
// Start observing the body for changes
observer.observe(document.body, {
childList: true,
subtree: true
});