-
Notifications
You must be signed in to change notification settings - Fork 0
/
theCrag - Replaces ascent icons and some more.js
88 lines (75 loc) · 3.08 KB
/
theCrag - Replaces ascent icons and some more.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
// ==UserScript==
// @name theCrag - Replace Icon with Local Image
// @namespace your.namespace
// @version 1.6
// @description Replaces ascent icons and some more
// @match https://www.thecrag.com/
// @match https://www.thecrag.com/dashboard
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Define an object with class names as keys and corresponding custom spans as values
var customSpans = {
"gear-style-sport": '<span class="tags sport">LD</span>',
"gear-style-second": '<span class="tags second">2D</span>',
"gear-style-trad": '<span class="tags trad">TD</span>',
"gear-style-boulder": '<span class="tags boulder">BD</span>',
"gear-style-top-rope": '<span class="tags toprope">TR</span>'
// Add more class names and custom spans as needed
};
// Function to replace the icons with custom spans and remove specific elements
function replaceIcons() {
for (var className in customSpans) {
var icons = Array.from(document.getElementsByClassName(className));
var customSpan = customSpans[className];
for (var i = 0; i < icons.length; i++) {
var icon = icons[i];
icon.outerHTML = customSpan;
}
}
// Remove specific elements by content
var contentsToRemove = [
'Deportiva',
'Búlder'
];
for (var i = 0; i < contentsToRemove.length; i++) {
var contentToRemove = contentsToRemove[i];
var elements = Array.from(document.querySelectorAll('.tags'));
for (var j = 0; j < elements.length; j++) {
var element = elements[j];
if (element.innerText === contentToRemove) {
element.remove();
}
}
}
// Remove elements with class name "bolts iblock"
var boltsElements = Array.from(document.querySelectorAll('.bolts.iblock'));
for (var k = 0; k < boltsElements.length; k++) {
var boltsElement = boltsElements[k];
boltsElement.remove();
}
// Remove comma from route length elements
var lengthElements = Array.from(document.querySelectorAll('.attr'));
for (var l = 0; l < lengthElements.length; l++) {
var lengthElement = lengthElements[l];
lengthElement.textContent = lengthElement.textContent.replace(/,/g, '');
}
}
// Function to observe changes in the DOM and trigger replacements
function observeDOM() {
var targetNode = document.body;
var config = { childList: true, subtree: true };
var observer = new MutationObserver(function(mutationsList) {
for (var mutation of mutationsList) {
if (mutation.type === 'childList') {
replaceIcons();
}
}
});
observer.observe(targetNode, config);
}
// Start observing DOM changes
observeDOM();
})();