-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode-coach.js
34 lines (28 loc) · 1.24 KB
/
code-coach.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
const user = "Logan";
console.log("Code coach");
function formatQuestion(questionText) {
let questionParts = questionText.split(" ");
// regex from https://stackoverflow.com/questions/26156292/trim-specific-character-from-a-string
let number = questionParts[0].replace(/\.+$/g, "");
questionParts.forEach((value, i, array) => array[i] = value.toLowerCase());
let title = questionParts.slice(1).join("-");
let url = window.location.href;
return {url, number, title}
}
function waitForQuestionTitle() {
let questionTitleElements = document.querySelectorAll("[data-cy='question-title']");
if (questionTitleElements.length < 1) {
window.requestAnimationFrame(waitForQuestionTitle);
} else {
let questionText = questionTitleElements[0].textContent
console.log(questionText);
let question = formatQuestion(questionText)
console.log(question);
let backgroundConnection = browser.runtime.connect({name: `content++${question.url}`});
backgroundConnection.postMessage(
{event: "pageLoad", questionName: question.title, questionUrl: question.url, user}
);
}
}
waitForQuestionTitle();
// Here need to implement listeners for test, success, fail, and abandon