-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
155 lines (143 loc) · 5.13 KB
/
Copy pathcontent.js
File metadata and controls
155 lines (143 loc) · 5.13 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// content.js (your content script)
document.addEventListener("keydown", function (event) {
// Check if the Enter key is pressed
if (event.key === "Enter" || event.code === "Enter") {
chrome.storage?.sync.get({ interaleksEnableEnter: true }, (data) => {
if (!data?.interaleksEnableEnter) return;
event.preventDefault(); // Prevent default Enter behavior
handleEnterKeyPress();
});
}
});
// Detect ALEKS cookie-block page and redirect to login based on preference
function checkAndRedirect() {
try {
const pageTitle = (document.title || "").toLowerCase();
const bodyText = (document.body?.innerText || "").toLowerCase();
const titleIndicators = [
"session closed",
"aleks - session closed",
"aleks - sorry, this page cannot be displayed due to your browser setting.",
];
const bodyIndicators = [
"cookies are blocked or not supported.",
"sorry, this page cannot be displayed due to your browser setting.",
"session closed",
"this session is closed",
];
const titleMatch = titleIndicators.some((phrase) =>
pageTitle.includes(phrase)
);
const bodyMatch = bodyIndicators.some((phrase) =>
bodyText.includes(phrase)
);
const isBlockedPage = titleMatch || bodyMatch;
if (!isBlockedPage) return;
console.log("InterALEKS: Redirecting...");
chrome.storage?.sync.get({ interaleksLoginMethod: "aleks" }, (data) => {
const method = data?.interaleksLoginMethod || "aleks";
const targets = {
aleks: "https://www.aleks.com/login",
mcgrawhill: "https://my.mheducation.com/login/",
};
const targetUrl = targets[method] || targets.aleks;
if (typeof window !== "undefined" && targetUrl) {
window.location.replace(targetUrl);
}
});
} catch (err) {
console.error("InterALEKS redirect error", err);
}
}
// Wait for page to be fully loaded before checking
function runCheckWithDelay() {
chrome.storage?.sync.get(
{ interaleksEnableRedirect: true, interaleksRedirectDelayMs: 3000 },
(data) => {
if (!data?.interaleksEnableRedirect) return;
checkAndRedirect();
const delay = Number(data?.interaleksRedirectDelayMs) || 0;
if (delay > 0) setTimeout(checkAndRedirect, delay);
}
);
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", runCheckWithDelay);
} else if (document.readyState === "interactive") {
// DOM is loaded but resources might still be loading
window.addEventListener("load", runCheckWithDelay);
} else {
// Page is already fully loaded
runCheckWithDelay();
}
function handleEnterKeyPress() {
// Check if blocking element is present and visible
const blockingElement = document.getElementById("ej9lur1fx5");
if (
blockingElement &&
blockingElement.style.display !== "none" &&
blockingElement.offsetParent !== null
) {
return; // Disable Enter system when blocking element is visible
}
// Check if Calculator heading is visible
const calculatorHeadings = document.querySelectorAll(
'[role="heading"][aria-level="2"]'
);
for (const heading of calculatorHeadings) {
if (
heading.textContent.trim() === "Calculator" &&
heading.style.display !== "none" &&
heading.offsetParent !== null
) {
const shouldBlock = true; // honor popup toggle if present
if (shouldBlock) return; // Disable Enter system when Calculator is visible
}
}
// Helper function to check if button is visible and clickable
function isButtonClickable(el) {
if (!el) return false;
if (el.disabled) return false;
if (el.style.display === "none") return false;
if (el.offsetParent === null) return false; // Check if element is actually visible
return true;
}
// Priority order as requested: Start now, Submit, Start, Continue my path, Check, Next, Try another, Check, Continue
const idsInPriorityOrder = [
// Start now
"smt_bottomnav_button_input_goto_placement",
// Submit
"smt_bottomnav_button_input_nextItemAssess",
"smt_bottomnav_button_input_submit",
// Start
"smt_bottomnav_button_input_startAssignment",
"smt_bottomnav_button_input_startPrep",
// Continue my path
"smt_bottomnav_button_input_newItem",
// Check (both variants)
"smt_bottomnav_button_input_checkAnswer",
"smt_bottomnav_button_input_nextItem",
// Continue (variants)
"smt_bottomnav_button_input_startItem",
"smt_bottomnav_button_input_continue",
// Next (several variants)
"smt_bottomnav_button_input_learningCorrect",
"smt_bottomnav_button_input_nextQuestionAssignment",
"smt_bottomnav_button_input_next",
"smt_bottomnav_button_input_nextPage",
"smt_bottomnav_button_input_nextSurvey",
// Try another - moved higher in priority for completed problems
"smt_bottomnav_button_input_tryAnother",
// Check again (fallback)
"smt_bottomnav_button_input_checkAnswer",
// Generic learning/next
"smt_bottomnav_button_input_learning",
];
for (const id of idsInPriorityOrder) {
const el = document.getElementById(id);
if (isButtonClickable(el)) {
el.click();
return;
}
}
}