update
This commit is contained in:
parent
9545544472
commit
b10972bd0d
2 changed files with 80 additions and 6 deletions
|
@ -1,5 +1,79 @@
|
||||||
function hello(){
|
function fetchAwnsers(awnserURL = "") {
|
||||||
console.log("hello");
|
return new Promise((resolve, reject) => {
|
||||||
|
GM_xmlhttpRequest({
|
||||||
|
method: "GET",
|
||||||
|
url: awnserURL,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "text/html",
|
||||||
|
},
|
||||||
|
onload: function (response) {
|
||||||
|
awnserImgs = new Map();
|
||||||
|
const results = [];
|
||||||
|
const parser = new DOMParser();
|
||||||
|
const virtDom = parser.parseFromString(
|
||||||
|
response.responseText,
|
||||||
|
"text/html"
|
||||||
|
);
|
||||||
|
|
||||||
|
let answersDom = virtDom.querySelector(".pf-content");
|
||||||
|
if (!answersDom) {
|
||||||
|
answersDom = virtDom.querySelector(".thecontent");
|
||||||
}
|
}
|
||||||
|
|
||||||
window.hello = hello;
|
let index = -1;
|
||||||
|
for (let childDom of answersDom.children) {
|
||||||
|
index++;
|
||||||
|
|
||||||
|
if (childDom.tagName === "P" || childDom.tagName === "STRONG") {
|
||||||
|
// maybe a question question
|
||||||
|
let innerDom = childDom.querySelector("strong");
|
||||||
|
if (innerDom === null) {
|
||||||
|
if (!childDom.textContent) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
innerDom = childDom;
|
||||||
|
}
|
||||||
|
|
||||||
|
const textContent = innerDom.textContent.trim();
|
||||||
|
const matches = textContent.match(/^[0-9]+\. (.*)$/);
|
||||||
|
if (matches !== null) {
|
||||||
|
const questionText = matches[1];
|
||||||
|
|
||||||
|
// most likely a question
|
||||||
|
let nextChild = answersDom.children[index + 1];
|
||||||
|
|
||||||
|
if (nextChild.tagName === "P") {
|
||||||
|
nextChild = answersDom.children[index + 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextChild === null) continue;
|
||||||
|
|
||||||
|
if (nextChild.tagName === "UL") {
|
||||||
|
// most likely the awnser
|
||||||
|
const answers = [];
|
||||||
|
for (let answerDom of nextChild.querySelectorAll("strong")) {
|
||||||
|
let answerText = answerDom.textContent.trim();
|
||||||
|
if (answerText.endsWith("*")) {
|
||||||
|
answerText = answerText.substring(0, answerText.length - 1);
|
||||||
|
}
|
||||||
|
answers.push(answerText);
|
||||||
|
}
|
||||||
|
|
||||||
|
results.push({
|
||||||
|
question: questionText,
|
||||||
|
answers: answers,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resolve(results);
|
||||||
|
},
|
||||||
|
onerror: function(error) {
|
||||||
|
reject(error)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.fetchAwnsers = fetchAwnsers;
|
|
@ -10,7 +10,7 @@
|
||||||
// @grant GM_getValue
|
// @grant GM_getValue
|
||||||
// @grant GM_xmlhttpRequest
|
// @grant GM_xmlhttpRequest
|
||||||
// @grant GM_log
|
// @grant GM_log
|
||||||
// @version 0.0.9
|
// @version 0.0.10
|
||||||
// @author Dominik Säume
|
// @author Dominik Säume
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue