|
1 | 1 | // ==UserScript== |
2 | 2 | // @name EdgeGamers Forum Enhancement%RELEASE_TYPE% |
3 | 3 | // @namespace https://github.com/blankdvth/eGOScripts/blob/master/src/EGO%20Forum%20Enhancement.ts |
4 | | -// @version 4.11.4 |
| 4 | +// @version 4.11.5 |
5 | 5 | // @description Add various enhancements & QOL additions to the EdgeGamers Forums that are beneficial for Leadership members. |
6 | 6 | // @author blank_dvth, Skle, MSWS, PixeL |
7 | 7 | // @match https://www.edgegamers.com/* |
@@ -629,12 +629,19 @@ function setupForumsConfig() { |
629 | 629 | }); |
630 | 630 |
|
631 | 631 | const profileMenu = document.querySelector("div.js-visitorMenuBody"); |
632 | | - if (profileMenu) |
633 | | - profileMenu.addEventListener( |
634 | | - "DOMNodeInserted", |
635 | | - handleProfileDropdown, |
636 | | - false, |
637 | | - ); |
| 632 | + if (profileMenu) { |
| 633 | + const profileMenuObserver = new MutationObserver((mutations) => { |
| 634 | + mutations.every((mutation) => { |
| 635 | + mutation.addedNodes.forEach((node) => { |
| 636 | + handleProfileDropdown(node as HTMLElement); |
| 637 | + }); |
| 638 | + }); |
| 639 | + }); |
| 640 | + profileMenuObserver.observe(profileMenu, { |
| 641 | + childList: true, |
| 642 | + subtree: true, |
| 643 | + }); |
| 644 | + } |
638 | 645 | } |
639 | 646 |
|
640 | 647 | /** |
@@ -1623,10 +1630,8 @@ function generateResponseText(response: string) { |
1623 | 1630 | * @param {HTMLElementEventMap} event |
1624 | 1631 | * @returns void |
1625 | 1632 | */ |
1626 | | -function tooltipMAULListener(event: Event) { |
| 1633 | +function tooltipMAULListener(target: HTMLElement) { |
1627 | 1634 | // Make sure this specific event is the node we want |
1628 | | - if (!event.target) return; |
1629 | | - const target = event.target as HTMLElement; |
1630 | 1635 | if ( |
1631 | 1636 | target.nodeName != "DIV" || |
1632 | 1637 | !target.classList.contains("tooltip-content-inner") |
@@ -1697,11 +1702,10 @@ function handleThreadMovePage(hash: string) { |
1697 | 1702 | ).checked = false; |
1698 | 1703 | ( |
1699 | 1704 | checkArr |
1700 | | - .find( |
1701 | | - (el) => |
1702 | | - el.textContent?.startsWith( |
1703 | | - "Notify thread starter of this action.", |
1704 | | - ), |
| 1705 | + .find((el) => |
| 1706 | + el.textContent?.startsWith( |
| 1707 | + "Notify thread starter of this action.", |
| 1708 | + ), |
1705 | 1709 | ) |
1706 | 1710 | ?.querySelector("label > input") as HTMLInputElement |
1707 | 1711 | ).checked = false; |
@@ -1918,9 +1922,7 @@ function handleBanAppealReport(report: boolean = false) { |
1918 | 1922 | * @param {HTMLElementEventMap} event |
1919 | 1923 | * @returns void |
1920 | 1924 | */ |
1921 | | -function handleOnHold(event: Event) { |
1922 | | - if (!event.target) return; |
1923 | | - const target = event.target as HTMLElement; |
| 1925 | +function handleOnHold(target: HTMLElement) { |
1924 | 1926 | if ( |
1925 | 1927 | target.nodeName != "DIV" || |
1926 | 1928 | !target.classList.contains("overlay-container") || |
@@ -1976,9 +1978,7 @@ function handleOnHold(event: Event) { |
1976 | 1978 | * @param {HTMLElementEventMap} event |
1977 | 1979 | * @returns void |
1978 | 1980 | */ |
1979 | | -function handleProfileDropdown(event: Event) { |
1980 | | - if (!event.target) return; |
1981 | | - const target = event.target as HTMLElement; |
| 1981 | +function handleProfileDropdown(target: HTMLElement) { |
1982 | 1982 | if (target.nodeName != "UL" || !target.classList.contains("tabPanes")) |
1983 | 1983 | return; |
1984 | 1984 | const btn = document.createElement("a"); |
@@ -2313,21 +2313,25 @@ function blockSignatures() { |
2313 | 2313 | const signature = post.querySelector( |
2314 | 2314 | "aside.message-signature > div", |
2315 | 2315 | ) as HTMLDivElement; |
2316 | | - // iframe's are added after page load, using a DOMNodeInserted event to work around that |
2317 | | - function signatureEvent(event: Event) { |
2318 | | - if (!event.target) return; |
2319 | | - if (!((event.target as HTMLElement).nodeName === "IFRAME")) |
2320 | | - return; |
2321 | | - (event.target as HTMLIFrameElement).dataset.src = ( |
2322 | | - event.target as HTMLIFrameElement |
| 2316 | + // iframe's are added after page load, using a MutationObserver to work around that |
| 2317 | + function signatureEvent(target: HTMLElement) { |
| 2318 | + if (!(target.nodeName === "IFRAME")) return; |
| 2319 | + (target as HTMLIFrameElement).dataset.src = ( |
| 2320 | + target as HTMLIFrameElement |
2323 | 2321 | ).src; |
2324 | | - (event.target as HTMLIFrameElement).src = "about:blank"; |
| 2322 | + (target as HTMLIFrameElement).src = "about:blank"; |
2325 | 2323 | } |
2326 | | - signature.addEventListener( |
2327 | | - "DOMNodeInserted", |
2328 | | - signatureEvent, |
2329 | | - false, |
2330 | | - ); |
| 2324 | + const signatureObserver = new MutationObserver((mutations) => { |
| 2325 | + mutations.every((mutation) => { |
| 2326 | + mutation.addedNodes.forEach((node) => { |
| 2327 | + signatureEvent(node as HTMLElement); |
| 2328 | + }); |
| 2329 | + }); |
| 2330 | + }); |
| 2331 | + signatureObserver.observe(signature, { |
| 2332 | + childList: true, |
| 2333 | + subtree: true, |
| 2334 | + }); |
2331 | 2335 | // Set the SRC of content to nothing (data:,), empty string is not used as it may cause additional requests to the page |
2332 | 2336 | // Issue originated back in 2009, unsure if it is still a problem but best to lean on the safe side. |
2333 | 2337 | // Was fixed in FireFox a while ago, not sure about Chrome |
@@ -2388,11 +2392,7 @@ function blockSignatures() { |
2388 | 2392 | source.src = source.dataset.src as string; |
2389 | 2393 | delete source.dataset.src; |
2390 | 2394 | }); |
2391 | | - signature.removeEventListener( |
2392 | | - "DOMNodeInserted", |
2393 | | - signatureEvent, |
2394 | | - false, |
2395 | | - ); |
| 2395 | + signatureObserver.disconnect(); |
2396 | 2396 | btn.remove(); |
2397 | 2397 | }; |
2398 | 2398 | btn.innerHTML = "Load Signature"; |
@@ -2420,12 +2420,29 @@ function blockSignatures() { |
2420 | 2420 | const url = window.location.href; |
2421 | 2421 | const hash = window.location.hash; |
2422 | 2422 |
|
2423 | | - document.body.addEventListener( |
2424 | | - "DOMNodeInserted", |
2425 | | - tooltipMAULListener, |
2426 | | - false, |
2427 | | - ); |
2428 | | - document.body.addEventListener("DOMNodeInserted", handleOnHold, false); |
| 2423 | + const tooltipObserver = new MutationObserver((mutations) => { |
| 2424 | + mutations.every((mutation) => { |
| 2425 | + mutation.addedNodes.forEach((node) => { |
| 2426 | + tooltipMAULListener(node as HTMLElement); |
| 2427 | + }); |
| 2428 | + }); |
| 2429 | + }); |
| 2430 | + tooltipObserver.observe(document.body, { |
| 2431 | + childList: true, |
| 2432 | + subtree: true, |
| 2433 | + }); |
| 2434 | + |
| 2435 | + const onHoldObserver = new MutationObserver((mutations) => { |
| 2436 | + mutations.every((mutation) => { |
| 2437 | + mutation.addedNodes.forEach((node) => { |
| 2438 | + handleOnHold(node as HTMLElement); |
| 2439 | + }); |
| 2440 | + }); |
| 2441 | + }); |
| 2442 | + onHoldObserver.observe(document.body, { |
| 2443 | + childList: true, |
| 2444 | + subtree: true, |
| 2445 | + }); |
2429 | 2446 |
|
2430 | 2447 | // Add Helpful Links to the Navigation Bar |
2431 | 2448 | const nav_list = document.querySelector(".p-nav-list") as HTMLUListElement; |
|
0 commit comments