-
Notifications
You must be signed in to change notification settings - Fork 0
/
TamperMonkeyScript,js
76 lines (73 loc) · 2.49 KB
/
TamperMonkeyScript,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 EDTell Quiz Helper
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Extract the Questions and Answers to a temp. text file
// @author AnonAnom
// @match https://founders.edtell.com/samigo-app/jsf/delivery/deliverAssessment.faces
// @match https://founders.edtell.com/samigo-app/jsf/delivery/beginTakingAssessment.faces
// @icon https://founders.edtell.com/favicon.ico
// @grant none
// ==/UserScript==
const bookmarkletScript = `javascript:(function() {
const startText = '10 Points';
const endText = 'Reset Selection';
const selection = window.getSelection();
const range = document.createRange();
let startNode, endNode;
const walker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_TEXT,
null,
false
);
while ((node = walker.nextNode())) {
if (node.textContent.trim() === startText) {
startNode = node;
} else if (node.textContent.trim() === endText) {
endNode = node;
break;
}
}
if (startNode && endNode) {
range.setStartAfter(startNode);
range.setEndBefore(endNode);
selection.removeAllRanges();
selection.addRange(range);
const selectedText = selection.toString().replace(startText, '').replace(endText, '').trim();
if (selectedText) {
const questionCount = localStorage.getItem('questionCount') || 1;
localStorage.setItem('questionCount', Number(questionCount) + 1);
let fileContent = localStorage.getItem('ExtractedData') || '';
fileContent += \`Question \${questionCount}: \${selectedText}\\n\`;
localStorage.setItem('ExtractedData', fileContent);
console.log('Text appended to temporary file.');
const nextButton = document.getElementById('takeAssessmentForm:next');
if (nextButton) {
nextButton.click();
} else {
console.log('Next button not found.');
}
} else {
console.log('No text found between the specified markers.');
}
selection.removeAllRanges();
} else {
console.log('Failed to extract the text.');
}
})();`;
let count = 0;
const intervalId = setInterval(() => {
if (count >= 0.2) {
clearInterval(intervalId);
console.log('Script executed 10 times.');
return;
}
count++;
console.log(`Executing script for the ${count}th time.`);
setTimeout(() => {
const bookmarkletLink = document.createElement('a');
bookmarkletLink.href = bookmarkletScript;
bookmarkletLink.click();
}, 500);
}, 300);