1
1
Fork 0
This commit is contained in:
Dominik Säume 2024-05-23 19:03:41 +02:00
parent eb5b260d52
commit cd540cffe8
Signed by: SZUT-Dominik
GPG key ID: 67D15BB250B41E7C
7 changed files with 39 additions and 10 deletions

View file

@ -1,2 +1,19 @@
# CCNA Autofill Userscript
A Userscript for autofilling the Answers on the **CCNA**.
inspired by [Merlinfuchs/ccna-extension](https://github.com/merlinfuchs/ccna-extension).
## Installation
Use a userscript client like [ViolentMonkey](https://violentmonkey.github.io/), [Tampermonkey](https://www.tampermonkey.net/).
[![Install USerscript](https://img.shields.io/badge/Install_Userscript-Install_Userscript?style=for-the-badge&logo=tampermonkey&logoColor=brown&color=lightgray)](https://git.euph.dev/SZUT-Dominik/CCNA_Autofill_Userscript/raw/branch/main/main.user.js)
## Status
This Userscript is only tested with [ViolentMonkey](https://violentmonkey.github.io/) on the **CCNAv7**.
## Usage
- **p**: Paste your answer-URL from [ItexamAnswers](https://itexamanswers.net) for the **CCNAv7** use [these](https://itexamanswers.net/ccna-1-v7-modules-1-3-basic-network-connectivity-and-communications-exam-answers.html).
- **a**: Try autofilling the current answer. There won't be any visual feedback when it fails.
- **n**: Go to the next Question.

View file

@ -1,4 +1,4 @@
const IS_QUESTION_REGEX = /^[0-9]+\. (.*)$/;
const QUESTION_REGEX = /^[0-9]+\. (.*)$/;
/**
* Fetches answers from the specified URL.
@ -67,7 +67,10 @@ function getAllAnswersElement(response) {
*/
function parseAnswerElement(index, element, allAnswersElement) {
// Check for Possible Tags
if (!(element.tagName === "P" || element.tagName === "STRONG") || !element.innerHTML) {
if (
!(element.tagName === "P" || element.tagName === "STRONG") ||
!element.innerHTML
) {
return;
}
@ -81,7 +84,6 @@ function parseAnswerElement(index, element, allAnswersElement) {
questionElement = element;
}
// Get Question
const questionText = parseQuestion(questionElement);
if (questionText === null) {
@ -104,7 +106,7 @@ function parseAnswerElement(index, element, allAnswersElement) {
*/
function parseQuestion(questionElement) {
const textContent = questionElement.textContent.trim();
const matches = textContent.match(IS_QUESTION_REGEX);
const matches = textContent.match(QUESTION_REGEX);
return matches !== null ? matches[1] : null;
}

View file

@ -10,7 +10,7 @@
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_xmlhttpRequest
// @version 0.0.18
// @version 0.0.19
// @author Dominik Säume
// ==/UserScript==

7
types/GM_getValue.d.js Normal file
View file

@ -0,0 +1,7 @@
/**
* @param {string} storageKey
* @returns {string}
*/
function GM_getValue(storageKey) {
return "";
}

5
types/GM_setValue.d.js Normal file
View file

@ -0,0 +1,5 @@
/**
* @param {string} storageKey
* @param {string} value
*/
function GM_setValue(storageKey, value) {}

View file

@ -8,9 +8,7 @@
* @param {Function} [details.onerror] - Optional. Will be called if an error occurs while processing the request. Passed one argument, the Response Object.
* @returns {undefined}
*/
function GM_xmlhttpRequest(details) {
// Implementation is not necessary for a declaration file
}
function GM_xmlhttpRequest(details) {}
/**
* Response object for the HTTP request.