update
This commit is contained in:
parent
eb5b260d52
commit
cd540cffe8
7 changed files with 39 additions and 10 deletions
17
README.md
17
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.
|
14
fetch.js
14
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
7
types/GM_getValue.d.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* @param {string} storageKey
|
||||
* @returns {string}
|
||||
*/
|
||||
function GM_getValue(storageKey) {
|
||||
return "";
|
||||
}
|
5
types/GM_setValue.d.js
Normal file
5
types/GM_setValue.d.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* @param {string} storageKey
|
||||
* @param {string} value
|
||||
*/
|
||||
function GM_setValue(storageKey, value) {}
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue