-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheory_Test_Ireland_Enhancements.js
181 lines (153 loc) · 5.76 KB
/
Theory_Test_Ireland_Enhancements.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
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
179
180
181
// ==UserScript==
// @name Theory Test Ireland Enhancements (outdated)
// @icon https://www.google.com/s2/favicons?sz=128&domain=https://theorytestireland.org
// @namespace https://github.com/Lyushen
// @author Lyushen
// @license GNU
// @version 1.0055
// @description Several enhancements for Theory Test Ireland site, such as autoplay audio questions and answers, roll-up top bar for more space and block useless elements
// @homepageURL https://github.com/Lyushen/TMEnchancments
// @supportURL https://github.com/Lyushen/TMEnchancments/issues
// @updateURL https://raw.githubusercontent.com/Lyushen/TMEnchancments/main/Theory_Test_Ireland_Enhancements.js
// @downloadURL https://raw.githubusercontent.com/Lyushen/TMEnchancments/main/Theory_Test_Ireland_Enhancements.js
// @grant none
// @match https://theorytestireland.org/*
// ==/UserScript==
(function() {
'use strict';
const blockTabletElement = () => {
const tabletElement = document.querySelector('.tablet');
if (tabletElement) {
tabletElement.style.display = 'none';
}
};
// Call the function to block the tablet element
blockTabletElement();
const questionHeader = document.querySelector('i[class="question-prompt"]');
if (questionHeader) {
questionHeader.remove();
}
const questionButtonsElement = document.querySelector('.question-buttons');
if (questionButtonsElement) {
questionButtonsElement.style.marginBottom = '0px';
}
// Function to block the specified elements
const blockElements = () => {
// Block element with the class 'rt-cta-1'
const rtCtaElement = document.querySelector('.rt-cta-1');
if (rtCtaElement) {
rtCtaElement.style.display = 'none';
}
// Block footer area
const footerElement = document.querySelector('footer');
if (footerElement) {
footerElement.style.display = 'none';
}
};
// Call the function to block the specified elements
blockElements();
const enemyScript = document.querySelector('#content > script');
if (enemyScript) {
enemyScript.remove();
}
// Disable the scrollToTop functionality
document.addEventListener('click', function(e) {
if (e.target && (e.target.classList.contains('scrollToTop') || e.target.parentElement.classList.contains('scrollToTop'))) {
e.preventDefault();
}
}, true);
window.addEventListener('scroll', function(e) {
const scrollToTopElem = document.querySelector('.scrollToTop');
if (scrollToTopElem && scrollToTopElem.style.display !== 'none') {
e.preventDefault();
e.stopPropagation();
}
}, true);
// Simulate clicking the audio buttons sequentially with a delay after each audio finishes
const clickAudioButtonsSequentially = () => {
const audioIcons = document.querySelectorAll('.question-audio > i');
const audioElements = document.querySelectorAll('.test-audio');
if (audioIcons.length < 5 || audioElements.length < 5) return;
let currentIconIndex = 0;
const clickNextIcon = () => {
audioIcons[currentIconIndex].click();
audioElements[currentIconIndex].addEventListener('ended', function() {
if (currentIconIndex < 4) {
currentIconIndex++;
setTimeout(clickNextIcon, -500); // -500ms delay between audios
}
});
};
clickNextIcon();
};
// Start clicking the audio buttons sequentially
clickAudioButtonsSequentially();
// Click the sixth audio button when the "Check Answer" button is pressed
const checkAnswerBtn = document.getElementById("pd-single-question-check");
if (checkAnswerBtn) {
checkAnswerBtn.addEventListener('click', function() {
const sixthIcon = document.querySelectorAll('.question-audio > i')[5];
if (sixthIcon) {
sixthIcon.click();
}
});
}
// Hide header & mobile menu functionality
const elementsToHide = [
document.getElementById('masthead'),
document.getElementById('meanmenu')
];
elementsToHide.forEach(element => {
if (element) {
element.removeAttribute('style');
element.style.transition = 'top 0.5s';
element.style.position = 'fixed';
element.style.width = '100%';
element.style.top = '-100%';
element.style.zIndex = '9999';
}
});
window.addEventListener('scroll', () => {
elementsToHide.forEach(element => {
if (element) {
element.style.top = '-100%';
}
});
});
window.addEventListener('mousemove', (e) => {
if (e.clientY < 20) {
elementsToHide.forEach(element => {
if (element) {
element.style.top = '0';
}
});
}
});
elementsToHide.forEach(element => {
if (element) {
element.addEventListener('mouseleave', () => {
element.style.top = '-100%';
});
}
});
// Mobile touch events
window.addEventListener('touchstart', (e) => {
touchStartY = e.touches[0].clientY;
});
window.addEventListener('touchmove', (e) => {
let touchEndY = e.touches[0].clientY;
if (touchEndY - touchStartY > 50) { // Swipe down
elementsToHide.forEach(element => {
if (element) {
element.style.top = '0';
}
});
} else if (touchStartY - touchEndY > 50) { // Swipe up
elementsToHide.forEach(element => {
if (element) {
element.style.top = '-100%';
}
});
}
})();
})();