From 8274b6759776299b8519ae2dee097d609a826b6b Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 3 Aug 2024 11:02:26 +0200 Subject: [PATCH 1/3] fix message hover buttons --- src/api/MessagePopover.tsx | 19 ++++++++++++------- src/plugins/_api/messagePopover.ts | 5 +++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/api/MessagePopover.tsx b/src/api/MessagePopover.tsx index 454716498..0a4a05402 100644 --- a/src/api/MessagePopover.tsx +++ b/src/api/MessagePopover.tsx @@ -16,9 +16,10 @@ * along with this program. If not, see . */ +import ErrorBoundary from "@components/ErrorBoundary"; import { Logger } from "@utils/Logger"; import { Channel, Message } from "discord-types/general"; -import type { ComponentType, MouseEventHandler, ReactElement } from "react"; +import type { ComponentType, MouseEventHandler } from "react"; const logger = new Logger("MessagePopover"); @@ -48,22 +49,26 @@ export function removeButton(identifier: string) { } export function _buildPopoverElements( - msg: Message, - PopoverButton: ComponentType, + Component: React.ComponentType, + props: { message: Message; } ) { - const items = [] as ReactElement[]; + const items: React.ReactNode[] = []; for (const [identifier, getItem] of buttons.entries()) { try { - const item = getItem(msg); + const item = getItem(props.message); if (item) { item.key ??= identifier; - items.push(); + items.push( + + + + ); } } catch (err) { logger.error(`[${identifier}]`, err); } } - return items; + return <>{items}; } diff --git a/src/plugins/_api/messagePopover.ts b/src/plugins/_api/messagePopover.ts index d29b9b2d0..9998a46b0 100644 --- a/src/plugins/_api/messagePopover.ts +++ b/src/plugins/_api/messagePopover.ts @@ -26,8 +26,9 @@ export default definePlugin({ patches: [{ find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL", replacement: { - match: /"reply-self".+?Fragment,{children:\[(?=.+?\((\i\.\i),{label:)(?<=message:(\i).+?)/, - replace: (m, PopoverButton, msg) => `${m}...Vencord.Api.MessagePopover._buildPopoverElements(${msg},${PopoverButton}),` + // foo && !bar ? createElement(reactionStuffs)... createElement(blah,...makeElement(reply-other)) + match: /\i&&!\i\?\(0,\i\.jsxs?\)\(.{0,200}renderEmojiPicker:.{0,500}\?\(0,\i\.jsx\)\((\i\.\i).{0,200}\.\.\.(\i)\},"reply-other"/, + replace: "Vencord.Api.MessagePopover._buildPopoverElements($1,$2),$&" } }], }); From d1996034b7dcb5dd5cd2e78bfbd3b3f805c8a1c0 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 3 Aug 2024 15:18:35 +0200 Subject: [PATCH 2/3] fix YoutubeAdblock not working for some users --- src/plugins/youtubeAdblock.desktop/adguard.js | 56 ++----------------- 1 file changed, 6 insertions(+), 50 deletions(-) diff --git a/src/plugins/youtubeAdblock.desktop/adguard.js b/src/plugins/youtubeAdblock.desktop/adguard.js index 722e4816e..8f809c3d3 100644 --- a/src/plugins/youtubeAdblock.desktop/adguard.js +++ b/src/plugins/youtubeAdblock.desktop/adguard.js @@ -19,7 +19,6 @@ * along with AdGuard's Block YouTube Ads. If not, see . */ -const LOGO_ID = "block-youtube-ads-logo"; const hiddenCSS = [ "#__ffYoutube1", "#__ffYoutube2", @@ -98,7 +97,7 @@ const hideElements = () => { } const rule = selectors.join(", ") + " { display: none!important; }"; const style = document.createElement("style"); - style.innerHTML = rule; + style.textContent = rule; document.head.appendChild(style); }; /** @@ -193,68 +192,25 @@ const jsonOverride = (propertyName, overrideValue) => { return obj; }; // Override Response.prototype.json - const nativeResponseJson = Response.prototype.json; - Response.prototype.json = new Proxy(nativeResponseJson, { - apply(...args) { + Response.prototype.json = new Proxy(Response.prototype.json, { + async apply(...args) { // Call the target function, get the original Promise - const promise = Reflect.apply(...args); + const result = await Reflect.apply(...args); // Create a new one and override the JSON inside - return new Promise((resolve, reject) => { - promise.then(data => { - overrideObject(data, propertyName, overrideValue); - resolve(data); - }).catch(error => reject(error)); - }); + overrideObject(result, propertyName, overrideValue); + return result; }, }); }; -const addAdGuardLogoStyle = () => { }; -const addAdGuardLogo = () => { - if (document.getElementById(LOGO_ID)) { - return; - } - const logo = document.createElement("span"); - logo.innerHTML = "__logo_text__"; - logo.setAttribute("id", LOGO_ID); - if (window.location.hostname === "m.youtube.com") { - const btn = document.querySelector("header.mobile-topbar-header > button"); - if (btn) { - btn.parentNode?.insertBefore(logo, btn.nextSibling); - addAdGuardLogoStyle(); - } - } else if (window.location.hostname === "www.youtube.com") { - const code = document.getElementById("country-code"); - if (code) { - code.innerHTML = ""; - code.appendChild(logo); - addAdGuardLogoStyle(); - } - } else if (window.location.hostname === "music.youtube.com") { - const el = document.querySelector(".ytmusic-nav-bar#left-content"); - if (el) { - el.appendChild(logo); - addAdGuardLogoStyle(); - } - } else if (window.location.hostname === "www.youtube-nocookie.com") { - const code = document.querySelector("#yt-masthead #logo-container .content-region"); - if (code) { - code.innerHTML = ""; - code.appendChild(logo); - addAdGuardLogoStyle(); - } - } -}; // Removes ads metadata from YouTube XHR requests jsonOverride("adPlacements", []); jsonOverride("playerAds", []); // Applies CSS that hides YouTube ad elements hideElements(); // Some changes should be re-evaluated on every page change -addAdGuardLogo(); hideDynamicAds(); autoSkipAds(); observeDomChanges(() => { - addAdGuardLogo(); hideDynamicAds(); autoSkipAds(); }); From 021d9bf179476f630552a9418b683143f0482f31 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 3 Aug 2024 17:54:25 +0200 Subject: [PATCH 3/3] fix message hover buttons... again --- src/api/MessagePopover.tsx | 6 +++--- src/plugins/_api/messagePopover.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/MessagePopover.tsx b/src/api/MessagePopover.tsx index 0a4a05402..eb68ed2d6 100644 --- a/src/api/MessagePopover.tsx +++ b/src/api/MessagePopover.tsx @@ -50,18 +50,18 @@ export function removeButton(identifier: string) { export function _buildPopoverElements( Component: React.ComponentType, - props: { message: Message; } + message: Message ) { const items: React.ReactNode[] = []; for (const [identifier, getItem] of buttons.entries()) { try { - const item = getItem(props.message); + const item = getItem(message); if (item) { item.key ??= identifier; items.push( - + ); } diff --git a/src/plugins/_api/messagePopover.ts b/src/plugins/_api/messagePopover.ts index 9998a46b0..2b0b0c797 100644 --- a/src/plugins/_api/messagePopover.ts +++ b/src/plugins/_api/messagePopover.ts @@ -27,7 +27,7 @@ export default definePlugin({ find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL", replacement: { // foo && !bar ? createElement(reactionStuffs)... createElement(blah,...makeElement(reply-other)) - match: /\i&&!\i\?\(0,\i\.jsxs?\)\(.{0,200}renderEmojiPicker:.{0,500}\?\(0,\i\.jsx\)\((\i\.\i).{0,200}\.\.\.(\i)\},"reply-other"/, + match: /\i&&!\i\?\(0,\i\.jsxs?\)\(.{0,200}renderEmojiPicker:.{0,500}\?\(0,\i\.jsx\)\((\i\.\i).{0,200},"reply-other"(?<=message:(\i).+?)/, replace: "Vencord.Api.MessagePopover._buildPopoverElements($1,$2),$&" } }],