From f31024f52843bf2b619dace47f9d841d29e00c3d Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 10:55:08 -0400 Subject: [PATCH 01/12] Create config for canned responses Fix config bug in signature map update --- src/EGO Forum Enhancement.ts | 79 +++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index f86ff8c..904e6e9 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -3,7 +3,7 @@ // @namespace https://github.com/blankdvth/eGOScripts/blob/master/src/EGO%20Forum%20Enhancement.ts // @downloadURL %DOWNLOAD_URL% // @updateURL %DOWNLOAD_URL% -// @version 4.3.1 +// @version 4.4.0 // @description Add various enhancements & QOL additions to the EdgeGamers Forums that are beneficial for Leadership members. // @author blank_dvth, Skle, MSWS // @match https://www.edgegamers.com/* @@ -35,6 +35,12 @@ interface OnHold_Map { explain: string; } +interface CannedResponses_Map { + name: string; + category?: string; + response: string; +} + declare var SteamIDConverter: any; const completedMap: Completed_Map[] = []; @@ -42,6 +48,7 @@ const signatureBlockList: string[] = []; const navbarURLs: NavbarURL_Map[] = []; const onHoldTemplates: OnHold_Map[] = []; const autoMentionForums: string[] = []; +const cannedResponses: CannedResponses_Map[] = []; const contestReportForums: string[] = ["1233", "1234", "1235", "1236"]; /** @@ -182,8 +189,7 @@ function setupForumsConfig() { }, "move-to-completed": { type: "hidden", - default: - "Contest a Ban ?$;1236\nReport a Player ?$;1235\nContact Leadership ?$;853", + default: "1234;1236\n1233;1235\n852;853", }, "signature-block-unchecked": { label: "Signature Block List", @@ -234,8 +240,8 @@ function setupForumsConfig() { "auto-mention-unchecked": { label: "Auto Mention (Subforum IDs)", section: [ - "Autofill", - "Autofill various content into the post editor.", + "Automention", + "Automatically mention the OP in the editor in certain forums", ], type: "textarea", save: false, @@ -255,6 +261,20 @@ function setupForumsConfig() { type: "checkbox", default: false, }, + "canned-responses-unchecked": { + label: "Canned Responses", + section: [ + "Canned Responses", + "See this guide on how to format your canned responses.", + ], + type: "textarea", + save: false, + default: "", + }, + "canned-responses": { + type: "hidden", + default: "", + }, }, events: { init: function () { @@ -275,6 +295,10 @@ function setupForumsConfig() { "auto-mention-unchecked", GM_config.get("auto-mention") ); + GM_config.set( + "canned-responses-unchecked", + GM_config.get("canned-responses") + ); }, open: function (doc) { GM_config.fields[ @@ -356,6 +380,25 @@ function setupForumsConfig() { ) GM_config.set("auto-mention", autoMention); }); + GM_config.fields[ + "canned-responses-unchecked" + ].node?.addEventListener("change", function () { + const cannedResponses = GM_config.get( + "canned-responses-unchecked", + true + ) as string; + // Check if entire config matches the regex by matching all and rejoining the matches, then comparing to the original + if ( + [ + ...cannedResponses.matchAll( + /(?:===\n|^)- (?.+)\n(?:- (?.+)\n)?(?(?:.|\n)+?)\n===/gm + ), + ] + .map((i) => i[0]) + .join("\n") === cannedResponses + ) + GM_config.set("canned-responses", cannedResponses); + }); }, save: function (forgotten) { if ( @@ -390,6 +433,13 @@ function setupForumsConfig() { alert( "Invalid auto mention list. Ensure each ID is on it's own line and all IDs are numerical." ); + if ( + forgotten["canned-responses-unchecked"] !== + GM_config.get("canned-responses") + ) + alert( + "Invalid canned responses list. Ensure each response is in the proper format (see the wiki for more information)." + ); }, }, css: "textarea {width: 100%; height: 160px; resize: vertical;}", @@ -507,6 +557,24 @@ function loadAutoMentionList() { }); } +/** + * Loads the canned responses from config + */ +function loadCannedResponses() { + const cannedResponsesRaw = GM_config.get("canned-responses") as string; + [ + ...cannedResponsesRaw.matchAll( + /(?:===\n|^)- (?.+)\n(?:- (?.+)\n)?(?(?:.|\n)+?)\n===/gm + ), + ].forEach((match) => { + cannedResponses.push({ + name: match.groups!.name, + category: match.groups?.category, + response: match.groups!.response, + }); + }); +} + /** * Adds a MAUL profile button to the given div * @param {HTMLDivElement} div Div to add to @@ -1419,6 +1487,7 @@ function blockSignatures() { loadNavbarURLs(); loadOnHoldTemplates(); loadAutoMentionList(); + loadCannedResponses(); // Determine what page we're on const url = window.location.href; From aaa76e4983e166015ddf5a2ee8a312b0b8d4fee9 Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 12:46:39 -0400 Subject: [PATCH 02/12] Make config work with categories --- src/EGO Forum Enhancement.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index 904e6e9..70b796a 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -35,9 +35,8 @@ interface OnHold_Map { explain: string; } -interface CannedResponses_Map { +interface CannedResponse { name: string; - category?: string; response: string; } @@ -48,7 +47,8 @@ const signatureBlockList: string[] = []; const navbarURLs: NavbarURL_Map[] = []; const onHoldTemplates: OnHold_Map[] = []; const autoMentionForums: string[] = []; -const cannedResponses: CannedResponses_Map[] = []; +const cannedResponsesCategories: {[category: string] : CannedResponse[]} = {}; +const cannedResponses: CannedResponse[] = []; const contestReportForums: string[] = ["1233", "1234", "1235", "1236"]; /** @@ -567,9 +567,17 @@ function loadCannedResponses() { /(?:===\n|^)- (?.+)\n(?:- (?.+)\n)?(?(?:.|\n)+?)\n===/gm ), ].forEach((match) => { - cannedResponses.push({ + const category = match.groups?.category; + var toPush; + if (category) { + if (!cannedResponsesCategories[category]) + cannedResponsesCategories[category] = []; + toPush = cannedResponsesCategories[category]; + } else { + toPush = cannedResponses; + } + toPush.push({ name: match.groups!.name, - category: match.groups?.category, response: match.groups!.response, }); }); From d404119c00aef3f1ee867e2731cde758dbe5b3cb Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 15:21:25 -0400 Subject: [PATCH 03/12] Create initial interface --- src/EGO Forum Enhancement.ts | 134 ++++++++++++++++++++++++++++------- 1 file changed, 109 insertions(+), 25 deletions(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index 70b796a..f84c194 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -47,8 +47,7 @@ const signatureBlockList: string[] = []; const navbarURLs: NavbarURL_Map[] = []; const onHoldTemplates: OnHold_Map[] = []; const autoMentionForums: string[] = []; -const cannedResponsesCategories: {[category: string] : CannedResponse[]} = {}; -const cannedResponses: CannedResponse[] = []; +const cannedResponses: { [category: string]: CannedResponse[] } = {}; const contestReportForums: string[] = ["1233", "1234", "1235", "1236"]; /** @@ -391,7 +390,7 @@ function setupForumsConfig() { if ( [ ...cannedResponses.matchAll( - /(?:===\n|^)- (?.+)\n(?:- (?.+)\n)?(?(?:.|\n)+?)\n===/gm + /(?:===\n|^)- (?.+)\n- (?.+)\n(?(?:.|\n)+?)\n===/gm ), ] .map((i) => i[0]) @@ -564,19 +563,12 @@ function loadCannedResponses() { const cannedResponsesRaw = GM_config.get("canned-responses") as string; [ ...cannedResponsesRaw.matchAll( - /(?:===\n|^)- (?.+)\n(?:- (?.+)\n)?(?(?:.|\n)+?)\n===/gm + /(?:===\n|^)- (?.+)\n- (?.+)\n(?(?:.|\n)+?)\n===/gm ), ].forEach((match) => { - const category = match.groups?.category; - var toPush; - if (category) { - if (!cannedResponsesCategories[category]) - cannedResponsesCategories[category] = []; - toPush = cannedResponsesCategories[category]; - } else { - toPush = cannedResponses; - } - toPush.push({ + const category = match.groups!.category; + if (!cannedResponses[category]) cannedResponses[category] = []; + cannedResponses[category].push({ name: match.groups!.name, response: match.groups!.response, }); @@ -830,6 +822,16 @@ function editPostBox(text: string, append: boolean = false) { } } +/** + * Get the ID of the current forum + * @returns {string} Forum ID + */ +function getForumId() { + return document + .getElementById("XF")! + .dataset.containerKey?.replace("node-", ""); +} + /** * Generates large, transparent text (basically a watermark) * @param {string} top CSS Top Style @@ -851,13 +853,10 @@ function generateRedText(top: string, str: string = "Confidential") { } /** - * Get the ID of the current forum - * @returns {string} Forum ID + * Fills in placeholders in a canned response string with the proper data then returns it */ -function getForumId() { - return document - .getElementById("XF")! - .dataset.containerKey?.replace("node-", ""); +function generateResponseText(response: string) { + return response; } /** @@ -1031,8 +1030,7 @@ function handleGenericThread() { for (let i = 0; i < mutation.addedNodes.length; i++) { const node = mutation.addedNodes[i]; - if (node.nodeName === "DIV") - handleAutoMention(observer); + if (node.nodeName === "DIV") handlePostBox(observer); } }); }); @@ -1069,6 +1067,7 @@ function handleGenericThread() { // LE Forums handleLeadership(); + handleCannedResponses(); blockSignatures(); } @@ -1226,13 +1225,23 @@ function autoMention(focus: boolean) { } /** - * Handles adding auto mention functionality to the post box - * @param {MutationObserver} observer + * Handles operations that should be performed when the post box is loaded + * @param observer */ -function handleAutoMention(observer: MutationObserver) { +function handlePostBox(observer: MutationObserver) { const postBox = document.querySelector("div.fr-box") as HTMLDivElement; if (!postBox) return; observer.disconnect(); + + handleAutoMention(); + handleCannedResponses(); +} + +/** + * Handles adding auto mention functionality to the post box + */ +function handleAutoMention() { + const postBox = document.querySelector("div.fr-box") as HTMLDivElement; if (GM_config.get("auto-mention-onclick")) { postBox.addEventListener("click", function () { autoMention(true); @@ -1243,6 +1252,81 @@ function handleAutoMention(observer: MutationObserver) { } } +/** + * Handles adding canned responses to the post box + */ +function handleCannedResponses() { + const bar = document.querySelector( + "div.formButtonGroup-extra" + ) as HTMLDivElement; + if (!bar) console.warn("Could not find post box button bar"); + Object.entries(cannedResponses).forEach((cannedResponse) => { + const [category, responses] = cannedResponse; + const dropdown = document.createElement("span"); + dropdown.classList.add("p-navEl-splitTrigger"); // Adds various styling for dropdowns, technically for the navbar but it works here + dropdown.style.float = "none"; // Class makes it float left, so we need to override it + dropdown.style.textAlign = "center"; + dropdown.style.lineHeight = bar.clientHeight + "px"; + dropdown.style.paddingLeft = "8px"; + dropdown.dataset.category = category; + dropdown.innerText = category; + + var dropdownMenu = document.createElement("div"); + dropdownMenu.classList.add( + "menu", + "menu--structural", + "menu--potentialFixed", + "menu--left" + ); + dropdownMenu.style.zIndex = "800"; + dropdownMenu.style.display = "none"; + dropdownMenu.style.position = "fixed"; + dropdownMenu.style.minWidth = "150px"; + dropdownMenu.style.overflowY = "scroll"; + dropdownMenu.hidden = true; + + dropdown.append(dropdownMenu); + dropdown.addEventListener("mouseover", function () { + var rect = dropdown.getBoundingClientRect(); + dropdownMenu.hidden = false; + dropdownMenu.style.display = "block"; + dropdownMenu.style.top = rect.bottom + "px"; + dropdownMenu.style.left = rect.left + "px"; + dropdownMenu.style.maxHeight = + window.innerHeight - rect.top - 25 + "px"; + dropdownContent.style.maxHeight = dropdownMenu.style.maxHeight; + dropdownMenu.classList.add("is-active"); + }); + dropdown.addEventListener("mouseout", function () { + dropdownMenu.hidden = true; + dropdownMenu.style.display = "none"; + dropdownMenu.classList.remove("is-active"); + }); + + const dropdownContent = document.createElement("div"); + dropdownContent.classList.add("menu-content"); + dropdownContent.style.overflowY = "none"; + dropdownMenu.append(dropdownContent); + bar.append(dropdown); + + responses.forEach((response) => { + const btn = document.createElement("a"); + btn.classList.add("menu-linkRow", "u-indentDepth0"); + btn.innerText = response.name; + btn.style.cursor = "pointer"; + btn.style.paddingLeft = "4px"; + btn.style.paddingRight = "0px"; + btn.style.paddingTop = "1px"; + btn.style.paddingBottom = "1px"; + btn.addEventListener("click", function () { + editPostBox(generateResponseText(response.response), true); + dropdown.dispatchEvent(new MouseEvent("mouseout")); + }); + dropdownContent.append(btn); + }); + }); +} + /** * Changes the target of the application links to open in a new tab * @returns void From 2862e2d9f4a014a06853c778255cb60e88f9984c Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 15:54:07 -0400 Subject: [PATCH 04/12] Add build dev for win (w/ GnuWin32) --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 5276c79..b93782b 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "scripts": { "build": "tsc", "build-dev": "tsc && for file in dist/*.js; do sed -i \"s/%RELEASE_TYPE%/ - Development/g\" \"$file\";done", + "build-dev-win": "tsc && sed -i \"s/%RELEASE_TYPE%/ - Development/g\" \"dist/*\" && del \"dist\\*.\"", "prettify": "prettier --tab-width 4 --write \"src/**/*.ts\"" }, "devDependencies": { From 859b30a8b25fce52629636e1d04f6e493aae4531 Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 16:08:14 -0400 Subject: [PATCH 05/12] Fix sizing, unneeded scroll bar, add focus option --- src/EGO Forum Enhancement.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index f84c194..bd02b2c 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -274,6 +274,11 @@ function setupForumsConfig() { type: "hidden", default: "", }, + "canned-response-focus": { + label: "Refocus after inserting canned response", + type: "checkbox", + default: true, + } }, events: { init: function () { @@ -1282,7 +1287,7 @@ function handleCannedResponses() { dropdownMenu.style.display = "none"; dropdownMenu.style.position = "fixed"; dropdownMenu.style.minWidth = "150px"; - dropdownMenu.style.overflowY = "scroll"; + dropdownMenu.style.overflowY = "auto"; dropdownMenu.hidden = true; dropdown.append(dropdownMenu); @@ -1321,6 +1326,9 @@ function handleCannedResponses() { btn.addEventListener("click", function () { editPostBox(generateResponseText(response.response), true); dropdown.dispatchEvent(new MouseEvent("mouseout")); + const postBox = getPostBoxEl(); + postBox.dispatchEvent(new Event("autosize:update")); + if (GM_config.get("canned-response-focus")) postBox.focus(); }); dropdownContent.append(btn); }); From 5def8b01dd8d754b0ff6f7976cbb23849c832c55 Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 16:38:16 -0400 Subject: [PATCH 06/12] Add placeholders --- src/EGO Forum Enhancement.ts | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index bd02b2c..e82d1c5 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -278,7 +278,7 @@ function setupForumsConfig() { label: "Refocus after inserting canned response", type: "checkbox", default: true, - } + }, }, events: { init: function () { @@ -837,6 +837,26 @@ function getForumId() { .dataset.containerKey?.replace("node-", ""); } +/** + * Get the username of the current user + * @returns {string} Username of current user + */ +function getUsername() { + return ( + document.querySelector( + "a.p-navgroup-link--user > span.p-navgroup-linkText" + ) as HTMLSpanElement | null + )?.innerText; +} + +/** + * Get the username of the OP of the current thread + * @returns {string} Username of the OP + */ +function getOP() { + return document.querySelector("a.username") as HTMLAnchorElement | null; +} + /** * Generates large, transparent text (basically a watermark) * @param {string} top CSS Top Style @@ -861,7 +881,9 @@ function generateRedText(top: string, str: string = "Confidential") { * Fills in placeholders in a canned response string with the proper data then returns it */ function generateResponseText(response: string) { - return response; + return response + .replaceAll("{{{username}}}", getUsername() ?? "") + .replaceAll("{{{op username}}}", getOP()?.innerText ?? ""); } /** @@ -1220,7 +1242,7 @@ function handleLeadership() { * @param focus Whether to focus the post box after mentioning the user */ function autoMention(focus: boolean) { - const user = document.querySelector("a.username") as HTMLAnchorElement; + const user = getOP(); if (!user) return; const username = user.innerText; const userId = user.dataset.userId; From 201073366471239c9512f1f64be953c51129a5d4 Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 16:45:17 -0400 Subject: [PATCH 07/12] Rename config --- src/EGO Forum Enhancement.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index e82d1c5..47a5ab6 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -256,7 +256,7 @@ function setupForumsConfig() { default: true, }, "auto-mention-focus": { - label: "Autofocus after mentioning (only on load mode)", + label: "Focus after mentioning (only on load mode)", type: "checkbox", default: false, }, @@ -275,7 +275,7 @@ function setupForumsConfig() { default: "", }, "canned-response-focus": { - label: "Refocus after inserting canned response", + label: "Focus after inserting canned response", type: "checkbox", default: true, }, From c7ed53a49dfbc2cb840fcd207f1a772d86758034 Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 17:02:12 -0400 Subject: [PATCH 08/12] Fix various bugs --- src/EGO Forum Enhancement.ts | 50 ++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index 47a5ab6..bfa8712 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -1050,25 +1050,6 @@ function handleGenericThread() { // Ban Contest or Report handleBanReportContest(); - if (autoMentionForums.includes(forumId)) { - const observer = new MutationObserver((mutations) => { - mutations.forEach((mutation) => { - if (!mutation.addedNodes) return; - - for (let i = 0; i < mutation.addedNodes.length; i++) { - const node = mutation.addedNodes[i]; - if (node.nodeName === "DIV") handlePostBox(observer); - } - }); - }); - observer.observe(document.body, { - childList: true, - subtree: true, - attributes: false, - characterData: false, - }); - } - const button_group = document.querySelector("div.buttonGroup"); for (var i = 0; i < completedMap.length; i++) { if (forumId == completedMap[i].originId) { @@ -1094,7 +1075,28 @@ function handleGenericThread() { // LE Forums handleLeadership(); - handleCannedResponses(); + const observer = new MutationObserver((mutations) => { + mutations.every((mutation) => { // Using every so that we can return false to stop observing + if (!mutation.addedNodes) return true; + + for (let i = 0; i < mutation.addedNodes.length; i++) { + const node = mutation.addedNodes[i]; + if (node.nodeName === "DIV") { + handlePostBox(observer); + return false; + } + } + + return true; + }); + }); + observer.observe(document.body, { + childList: true, + subtree: true, + attributes: false, + characterData: false, + }); + blockSignatures(); } @@ -1258,9 +1260,10 @@ function autoMention(focus: boolean) { function handlePostBox(observer: MutationObserver) { const postBox = document.querySelector("div.fr-box") as HTMLDivElement; if (!postBox) return; + const forumId = getForumId(); observer.disconnect(); - handleAutoMention(); + if (forumId && autoMentionForums.includes(forumId)) handleAutoMention(); handleCannedResponses(); } @@ -1286,7 +1289,10 @@ function handleCannedResponses() { const bar = document.querySelector( "div.formButtonGroup-extra" ) as HTMLDivElement; - if (!bar) console.warn("Could not find post box button bar"); + if (!bar) { + console.warn("Could not find post box button bar"); + return; + } Object.entries(cannedResponses).forEach((cannedResponse) => { const [category, responses] = cannedResponse; const dropdown = document.createElement("span"); From a5639b580f6f375001a5cb7a7faf863223c7d486 Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 17:08:34 -0400 Subject: [PATCH 09/12] Ensure automention runs properly when using a canned response --- src/EGO Forum Enhancement.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index bfa8712..8b4bb2e 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -279,6 +279,11 @@ function setupForumsConfig() { type: "checkbox", default: true, }, + "canned-response-trigger-automention": { + label: "Attempt to trigger automention before inserting canned response", + type: "checkbox", + default: true, + } }, events: { init: function () { @@ -1352,9 +1357,13 @@ function handleCannedResponses() { btn.style.paddingTop = "1px"; btn.style.paddingBottom = "1px"; btn.addEventListener("click", function () { + const postBox = getPostBoxEl(); + if (GM_config.get("canned-response-trigger-automention")) { + const forumId = getForumId(); + if (forumId && autoMentionForums.includes(forumId)) autoMention(false); + } editPostBox(generateResponseText(response.response), true); dropdown.dispatchEvent(new MouseEvent("mouseout")); - const postBox = getPostBoxEl(); postBox.dispatchEvent(new Event("autosize:update")); if (GM_config.get("canned-response-focus")) postBox.focus(); }); From cd7a0d7b878a5188bfdb9adf7d2d9c3baf6d1c89 Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 17:08:42 -0400 Subject: [PATCH 10/12] Prettify --- src/EGO Forum Enhancement.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index 8b4bb2e..eaaec89 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -283,7 +283,7 @@ function setupForumsConfig() { label: "Attempt to trigger automention before inserting canned response", type: "checkbox", default: true, - } + }, }, events: { init: function () { @@ -1081,7 +1081,8 @@ function handleGenericThread() { handleLeadership(); const observer = new MutationObserver((mutations) => { - mutations.every((mutation) => { // Using every so that we can return false to stop observing + mutations.every((mutation) => { + // Using every so that we can return false to stop observing if (!mutation.addedNodes) return true; for (let i = 0; i < mutation.addedNodes.length; i++) { @@ -1360,7 +1361,8 @@ function handleCannedResponses() { const postBox = getPostBoxEl(); if (GM_config.get("canned-response-trigger-automention")) { const forumId = getForumId(); - if (forumId && autoMentionForums.includes(forumId)) autoMention(false); + if (forumId && autoMentionForums.includes(forumId)) + autoMention(false); } editPostBox(generateResponseText(response.response), true); dropdown.dispatchEvent(new MouseEvent("mouseout")); From d5df55c082045cef626ac85a80f163a1edec9b28 Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 17:10:40 -0400 Subject: [PATCH 11/12] Ensure automention only runs once on click --- src/EGO Forum Enhancement.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index eaaec89..5d68a2c 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -1279,9 +1279,11 @@ function handlePostBox(observer: MutationObserver) { function handleAutoMention() { const postBox = document.querySelector("div.fr-box") as HTMLDivElement; if (GM_config.get("auto-mention-onclick")) { - postBox.addEventListener("click", function () { + function autoMentionListener() { autoMention(true); - }); + postBox.removeEventListener("click", autoMentionListener); + } + postBox.addEventListener("click", autoMentionListener); } else { postBox.click(); autoMention(GM_config.get("auto-mention-focus") as boolean); From 1f0f6f32076b865c337a9fc8a5201d7b7a5ea696 Mon Sep 17 00:00:00 2001 From: blankdvth Date: Wed, 29 Mar 2023 17:16:01 -0400 Subject: [PATCH 12/12] Ensure proper maxWidth, allow user to customize minWidth --- src/EGO Forum Enhancement.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/EGO Forum Enhancement.ts b/src/EGO Forum Enhancement.ts index 5d68a2c..6f9864f 100644 --- a/src/EGO Forum Enhancement.ts +++ b/src/EGO Forum Enhancement.ts @@ -274,6 +274,12 @@ function setupForumsConfig() { type: "hidden", default: "", }, + "canned-response-min-width": { + label: "Minimum width of dropdown (in pixels)", + type: "int", + min: 0, + default: 125, + }, "canned-response-focus": { label: "Focus after inserting canned response", type: "checkbox", @@ -1322,8 +1328,9 @@ function handleCannedResponses() { dropdownMenu.style.zIndex = "800"; dropdownMenu.style.display = "none"; dropdownMenu.style.position = "fixed"; - dropdownMenu.style.minWidth = "150px"; - dropdownMenu.style.overflowY = "auto"; + dropdownMenu.style.minWidth = + GM_config.get("canned-response-min-width") + "px"; + dropdownMenu.style.overflow = "auto"; dropdownMenu.hidden = true; dropdown.append(dropdownMenu); @@ -1335,6 +1342,8 @@ function handleCannedResponses() { dropdownMenu.style.left = rect.left + "px"; dropdownMenu.style.maxHeight = window.innerHeight - rect.top - 25 + "px"; + dropdownMenu.style.maxWidth = + window.innerWidth - rect.left - 25 + "px"; dropdownContent.style.maxHeight = dropdownMenu.style.maxHeight; dropdownMenu.classList.add("is-active"); }); @@ -1346,7 +1355,7 @@ function handleCannedResponses() { const dropdownContent = document.createElement("div"); dropdownContent.classList.add("menu-content"); - dropdownContent.style.overflowY = "none"; + dropdownContent.style.overflow = "none"; dropdownMenu.append(dropdownContent); bar.append(dropdown);