111 lines
3.6 KiB
JavaScript
111 lines
3.6 KiB
JavaScript
// ==UserScript==
|
||
// @name Click "Submit" arrow button on F12
|
||
// @namespace vm-click-submit-arrow
|
||
// @match https://*netacad.com/*
|
||
// @require https://cdn.jsdelivr.net/npm/@violentmonkey/shortcut@1
|
||
// @grant none
|
||
// @version 1.5
|
||
// @run-at document-end
|
||
// ==/UserScript==
|
||
|
||
(function () {
|
||
'use strict';
|
||
|
||
function findSubmitButton() {
|
||
// Primary search: light DOM + exact attributes & content
|
||
let btns = document.querySelectorAll('button[aria-label="submit"].submit-button');
|
||
|
||
for (const btn of btns) {
|
||
const innerDiv = btn.querySelector('div.submit');
|
||
if (innerDiv && innerDiv.textContent.trim() === 'Submit') {
|
||
console.log('[SubmitClick] Exact match found in light DOM');
|
||
return btn;
|
||
}
|
||
}
|
||
|
||
// Deep shadow DOM recursive search
|
||
function searchShadows(root) {
|
||
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
|
||
let node;
|
||
while ((node = walker.nextNode())) {
|
||
if (node.shadowRoot) {
|
||
const shadowBtns = node.shadowRoot.querySelectorAll('button[aria-label="submit"].submit-button');
|
||
for (const btn of shadowBtns) {
|
||
const innerDiv = btn.querySelector('div.submit');
|
||
if (innerDiv && innerDiv.textContent.trim() === 'Submit') {
|
||
console.log('[SubmitClick] Found in shadow root of:', node.tagName.toLowerCase());
|
||
return btn;
|
||
}
|
||
}
|
||
// Recurse deeper
|
||
const found = searchShadows(node.shadowRoot);
|
||
if (found) return found;
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
const shadowResult = searchShadows(document.body);
|
||
if (shadowResult) return shadowResult;
|
||
|
||
console.log('[SubmitClick] No Submit button detected yet (aria-label + div.submit + text "Submit")');
|
||
return null;
|
||
}
|
||
|
||
function triggerClick() {
|
||
const btn = findSubmitButton();
|
||
|
||
if (!btn) {
|
||
console.log('[SubmitClick] → Submit button not found yet');
|
||
return false;
|
||
}
|
||
|
||
console.log('[SubmitClick] → Found Submit button, clicking it');
|
||
|
||
// Synthetic click event
|
||
try {
|
||
const clickEvent = new MouseEvent('click', {
|
||
bubbles: true,
|
||
cancelable: true,
|
||
view: window,
|
||
detail: 1
|
||
});
|
||
btn.dispatchEvent(clickEvent);
|
||
} catch (err) {
|
||
console.warn('[SubmitClick] dispatchEvent failed', err);
|
||
}
|
||
|
||
// Direct .click() fallback
|
||
if (typeof btn.click === 'function') {
|
||
try {
|
||
btn.click();
|
||
} catch (err) {
|
||
console.warn('[SubmitClick] .click() failed', err);
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
VM.shortcut.register('f12', () => {
|
||
setTimeout(() => {
|
||
if (!triggerClick()) {
|
||
// Extra retry for slow-rendering elements
|
||
setTimeout(triggerClick, 400);
|
||
}
|
||
}, 60);
|
||
});
|
||
|
||
console.log('[SubmitClick] Loaded – press F12 to click the Submit button');
|
||
|
||
// Optional: uncomment for auto-click every ~1.5 seconds until success
|
||
/*
|
||
const autoInterval = setInterval(() => {
|
||
if (triggerClick()) {
|
||
clearInterval(autoInterval);
|
||
console.log('[SubmitClick] Auto-click successful – stopping checks');
|
||
}
|
||
}, 1500);
|
||
*/
|
||
})();
|