From fe716f31c7747aa7ea1396247c92ab4138e4b762 Mon Sep 17 00:00:00 2001
From: bananarama92 <bananarama921@outlook.com>
Date: Sat, 29 Mar 2025 21:47:36 +0100
Subject: [PATCH] BUG: Fix the new chat room header icons not producing text
 upon copy/pasting

---
 BondageClub/CSS/chat.css                      |  6 +-
 .../Screens/Online/ChatRoom/ChatRoom.js       | 61 ++++++++++++++-----
 2 files changed, 52 insertions(+), 15 deletions(-)

diff --git a/BondageClub/CSS/chat.css b/BondageClub/CSS/chat.css
index e37c2557fe..bb736831e6 100644
--- a/BondageClub/CSS/chat.css
+++ b/BondageClub/CSS/chat.css
@@ -31,7 +31,7 @@
 }
 
 .chat-room-sep-header {
-  user-select: text !important;
+  user-select: all !important;
   align-content: center;
   justify-content: center;
   display: flex;
@@ -47,6 +47,10 @@
   margin-block: 0.1em;
 }
 
+.chat-room-no-copy {
+  user-select: none;
+}
+
 .chat-room-sep-collapse {
   font-weight: bold;
   text-align: center;
diff --git a/BondageClub/Screens/Online/ChatRoom/ChatRoom.js b/BondageClub/Screens/Online/ChatRoom/ChatRoom.js
index 0dcc1fd096..64b74dcc20 100644
--- a/BondageClub/Screens/Online/ChatRoom/ChatRoom.js
+++ b/BondageClub/Screens/Online/ChatRoom/ChatRoom.js
@@ -907,6 +907,25 @@ var ChatRoomSep = {
 	 */
 	ActiveElem: null,
 
+	/**
+	 * @private
+	 * @type {(this: HTMLDivElement, event: ClipboardEvent) => void}
+	 */
+	_CopyHeader: function _CopyHeader(ev) {
+		let txt = "";
+		for (const el of this.childNodes) {
+			if (!(el instanceof Element)) {
+				txt += el.textContent;
+				continue;
+			} else if (el.classList.contains("chat-room-no-copy")) {
+				continue;
+			}
+			txt += el.textContent || (el.getAttribute("aria-label") ?? "");
+		}
+		ev.clipboardData.setData("text/plain", txt);
+		ev.preventDefault();
+	},
+
 	/**
 	 * Click event listener for collapsing one or more chat room separators
 	 * @private
@@ -948,20 +967,34 @@ var ChatRoomSep = {
 	_GetDisplayName: function _GetDisplayName(button) {
 		const namespace = FriendListIconMapping[button.dataset.space];
 		return [
-			namespace ? [ElementCreate({
-				tag: "div",
-				attributes: { role: "img", "aria-label": InterfaceTextGet(`ChatRoomSpace${button.dataset.space || "F"}`) },
-				classList: ["chat-room-sep-image"],
-				style: { mask: `url(${namespace.src}) center/contain` },
-			}), " - "] : undefined,
-			button.dataset.private === "true" ? [ElementCreate({
-				tag: "div",
-				attributes: { role: "img", "aria-label": InterfaceTextGet("Private") },
-				classList: ["chat-room-sep-image"],
-				style: { mask: `url(${FriendListIconMapping.Private.src}) center/contain` },
-			}), " - "] : undefined,
+			namespace ? [
+				ElementCreate({
+					tag: "div",
+					attributes: { role: "img", "aria-label": InterfaceTextGet(`ChatRoomSpace${button.dataset.space || "F"}`) },
+					classList: ["chat-room-sep-image"],
+					style: { mask: `url(${namespace.src}) center/contain` },
+					eventListeners: { copy: ChatRoomSep._CopyImage },
+				}),
+				" - ",
+			] : undefined,
+			button.dataset.private === "true" ? [
+				ElementCreate({
+					tag: "div",
+					attributes: { role: "img", "aria-label": InterfaceTextGet("Private") },
+					classList: ["chat-room-sep-image"],
+					style: { mask: `url(${FriendListIconMapping.Private.src}) center/contain` },
+					eventListeners: { copy: ChatRoomSep._CopyImage },
+				}),
+				" - ",
+			] : undefined,
 			ChatRoomHTMLEntities(ChatSearchMuffle(button.dataset.room)),
-			button.dataset.messages ? ["✉", ElementCreate({ tag: "sup", children: [button.dataset.messages] })] : undefined,
+			button.dataset.messages ? [
+				ElementCreate({
+					tag: "span",
+					classList: ["chat-room-no-copy"],
+					children: [" ✉", { tag: "sup", children: [button.dataset.messages] }],
+				}),
+			] : undefined,
 		].flat().filter(Boolean);
 	},
 
@@ -994,7 +1027,7 @@ var ChatRoomSep = {
 						),
 						ElementButton.Create(
 							`chat-room-sep-header-${now}`, this._ClickScrollUp, { noStyling: true },
-							{ button: { classList: ["chat-room-sep-header"] } },
+							{ button: { classList: ["chat-room-sep-header"], eventListeners: { copy: ChatRoomSep._CopyHeader } } },
 						),
 					],
 				},