mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-12 08:03:06 -04:00
Merge remote-tracking branch 'upstream/main'
This commit is contained in:
commit
283ede5c7f
4 changed files with 20 additions and 97 deletions
|
@ -16,9 +16,10 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<ButtonItem>,
|
||||
Component: React.ComponentType<ButtonItem>,
|
||||
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(message);
|
||||
if (item) {
|
||||
item.key ??= identifier;
|
||||
items.push(<PopoverButton {...item} />);
|
||||
items.push(
|
||||
<ErrorBoundary noop>
|
||||
<Component {...item} />
|
||||
</ErrorBoundary>
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error(`[${identifier}]`, err);
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
return <>{items}</>;
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ 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}),`
|
||||
match: /\.jsx\)\((\i\.\i),\{label:\i\.\i\.Messages\.MESSAGE_ACTION_REPLY.{0,200}?"reply-self".{0,50}?\}\):null(?=,.+?message:(\i))/,
|
||||
replace: "$&,Vencord.Api.MessagePopover._buildPopoverElements($1,$2)"
|
||||
}
|
||||
}],
|
||||
});
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2023 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { Devs } from "@utils/constants.js";
|
||||
import definePlugin from "@utils/types";
|
||||
import { findByPropsLazy } from "@webpack";
|
||||
|
||||
const linkRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
||||
|
||||
const SlateTransforms = findByPropsLazy("insertText", "selectCommandOption");
|
||||
|
||||
export default definePlugin({
|
||||
name: "MaskedLinkPaste",
|
||||
authors: [Devs.TheSun],
|
||||
description: "Pasting a link while having text selected will paste a hyperlink",
|
||||
patches: [
|
||||
{
|
||||
find: ".selection,preventEmojiSurrogates:",
|
||||
replacement: {
|
||||
match: /(?<=\i.delete.{0,50})(\i)\.insertText\((\i)\)/,
|
||||
replace: "$self.handlePaste($1, $2, () => $&)"
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
handlePaste(editor, content: string, originalBehavior: () => void) {
|
||||
if (content && linkRegex.test(content) && editor.operations?.[0]?.type === "remove_text") {
|
||||
SlateTransforms.insertText(
|
||||
editor,
|
||||
`[${editor.operations[0].text}](${content})`
|
||||
);
|
||||
}
|
||||
else originalBehavior();
|
||||
}
|
||||
});
|
|
@ -19,7 +19,6 @@
|
|||
* along with AdGuard's Block YouTube Ads. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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);
|
||||
};
|
||||
/**
|
||||
|
@ -195,68 +194,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();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue