From cd540cffe86ca044de3af13ce1dbc4388c71fe7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Thu, 23 May 2024 19:03:41 +0200 Subject: [PATCH] update --- README.md | 17 +++++++++++++++++ fetch.js | 14 ++++++++------ main.user.js | 2 +- types/{awnser.d.js => Awnser.d.js} | 0 types/GM_getValue.d.js | 7 +++++++ types/GM_setValue.d.js | 5 +++++ types/GM_xmlhttpRequest.d.js | 4 +--- 7 files changed, 39 insertions(+), 10 deletions(-) rename types/{awnser.d.js => Awnser.d.js} (100%) create mode 100644 types/GM_getValue.d.js create mode 100644 types/GM_setValue.d.js diff --git a/README.md b/README.md index 266c7d7..6a21702 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file diff --git a/fetch.js b/fetch.js index 5d76b3e..a1a2e03 100644 --- a/fetch.js +++ b/fetch.js @@ -1,4 +1,4 @@ -const IS_QUESTION_REGEX = /^[0-9]+\. (.*)$/; +const QUESTION_REGEX = /^[0-9]+\. (.*)$/; /** * Fetches answers from the specified URL. @@ -36,7 +36,7 @@ function parseAnswers(response, resolve) { for (let child of Array.from(allAnswersElement.children)) { index++; const result = parseAnswerElement(index, child, allAnswersElement); - if(result != undefined){ + if (result != undefined) { results.push(result); } } @@ -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) { @@ -91,7 +93,7 @@ function parseAnswerElement(index, element, allAnswersElement) { // Get Awsners const answersElement = getAnswersElement(index, allAnswersElement); if (answersElement === null || answersElement.tagName !== "UL") return; - + return { question: questionText, answers: getAnswers(answersElement), @@ -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; } diff --git a/main.user.js b/main.user.js index c651a03..83e8277 100644 --- a/main.user.js +++ b/main.user.js @@ -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== diff --git a/types/awnser.d.js b/types/Awnser.d.js similarity index 100% rename from types/awnser.d.js rename to types/Awnser.d.js diff --git a/types/GM_getValue.d.js b/types/GM_getValue.d.js new file mode 100644 index 0000000..d0bd584 --- /dev/null +++ b/types/GM_getValue.d.js @@ -0,0 +1,7 @@ +/** + * @param {string} storageKey + * @returns {string} + */ +function GM_getValue(storageKey) { + return ""; +} diff --git a/types/GM_setValue.d.js b/types/GM_setValue.d.js new file mode 100644 index 0000000..a003dd5 --- /dev/null +++ b/types/GM_setValue.d.js @@ -0,0 +1,5 @@ +/** + * @param {string} storageKey + * @param {string} value + */ +function GM_setValue(storageKey, value) {} diff --git a/types/GM_xmlhttpRequest.d.js b/types/GM_xmlhttpRequest.d.js index 39635a5..b2382da 100644 --- a/types/GM_xmlhttpRequest.d.js +++ b/types/GM_xmlhttpRequest.d.js @@ -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.