-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
87 lines (71 loc) · 3.24 KB
/
content.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Retrieve the current URL
const currentUrl = window.location.href;
// Retrieve the last visit time from local storage
chrome.storage.local.get(currentUrl, (result) => {
const lastVisitTime = result[currentUrl];
const articleTitleElement = document.querySelector('.article-title h1');
const practiceTitleElement = document.querySelector('.problems_header_content__title__L2cB2 h3')
const problemSolvedElement = document.querySelector('table .unstackable');
console.log(problemSolvedElement)
if (articleTitleElement) {
// Create a new title with last visit time
const originalTitle = articleTitleElement.innerText;
// Create a span element for the last visit time
const lastVisitElement = document.createElement('span');
articleTitleElement.appendChild(document.createElement('br'));
lastVisitElement.innerText = ` Last Visited: ${lastVisitTime || 'First Visit'}`;
lastVisitElement.style.fontSize = '14px';
lastVisitElement.style.color = 'red';
// Append the last visit element to the article title
articleTitleElement.appendChild(lastVisitElement);
// Update the article title
// articleTitleElement.innerText = newTitle;
}
if(practiceTitleElement){
const lastVisitElement = document.createElement('span');
practiceTitleElement.appendChild(document.createElement('br'));
lastVisitElement.innerText = ` Last Visited: ${lastVisitTime || 'First Visit'}`;
lastVisitElement.style.fontSize = '12px';
lastVisitElement.style.color = 'red';
// Append the last visit element to the article title
practiceTitleElement.appendChild(lastVisitElement);
if(problemSolvedElement){
const correctIconElement = document.createElement('img')
correctIconElement.src = 'https://i.postimg.cc/Hxr3cVNg/correct.png'
correctIconElement.style.width = '20px'
correctIconElement.style.height = '20px'
correctIconElement.style.marginLeft = '10px'
const solvedText = document.createElement('span')
solvedText.innerText = 'Solved'
practiceTitleElement.appendChild(solvedText)
practiceTitleElement.appendChild(correctIconElement)
}
}
// Update the last visit time in local storage
const currentTime = new Date().toLocaleString();
chrome.storage.local.set({ [currentUrl]: currentTime });
});
document.addEventListener('keydown', (event) => {
// Check if Ctrl + ' key is pressed
if (event.ctrlKey && event.key === "'") {
const compileButton = document.querySelector('.problems_compile_button__Lfluz');
const compileButtonCodeStudio = document.querySelector('.run-code-btn')
if(compileButtonCodeStudio){
compileButtonCodeStudio.click()
}
compileButton.click();
}
// Check if Ctrl key is pressed and Enter key is pressed without any modifiers
if (event.ctrlKey && event.key === 'Enter' && !event.shiftKey && !event.altKey && !event.metaKey) {
// console.log('world');
const submitButton = document.querySelector('.problems_submit_button__6QoNQ')
submitButton.click()
}
if(event.ctrlKey && event.shiftKey && !event.altKey && !event.metaKey && !(event.key === 'Enter')){
const submitButtonCodeStudio = document.querySelector('.zen-primary-cta')
console.log(submitButtonCodeStudio)
if(submitButtonCodeStudio){
submitButtonCodeStudio.click()
}
}
});