Merge branch 'dev' into immediate-finds-modules-proxy
This commit is contained in:
commit
ed32b7964d
|
@ -16,9 +16,10 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import ErrorBoundary from "@components/ErrorBoundary";
|
||||||
import { Logger } from "@utils/Logger";
|
import { Logger } from "@utils/Logger";
|
||||||
import { Channel, Message } from "discord-types/general";
|
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");
|
const logger = new Logger("MessagePopover");
|
||||||
|
|
||||||
|
@ -48,22 +49,26 @@ export function removeButton(identifier: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function _buildPopoverElements(
|
export function _buildPopoverElements(
|
||||||
msg: Message,
|
Component: React.ComponentType<ButtonItem>,
|
||||||
PopoverButton: ComponentType<ButtonItem>,
|
message: Message
|
||||||
) {
|
) {
|
||||||
const items = [] as ReactElement[];
|
const items: React.ReactNode[] = [];
|
||||||
|
|
||||||
for (const [identifier, getItem] of buttons.entries()) {
|
for (const [identifier, getItem] of buttons.entries()) {
|
||||||
try {
|
try {
|
||||||
const item = getItem(msg);
|
const item = getItem(message);
|
||||||
if (item) {
|
if (item) {
|
||||||
item.key ??= identifier;
|
item.key ??= identifier;
|
||||||
items.push(<PopoverButton {...item} />);
|
items.push(
|
||||||
|
<ErrorBoundary noop>
|
||||||
|
<Component {...item} />
|
||||||
|
</ErrorBoundary>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(`[${identifier}]`, err);
|
logger.error(`[${identifier}]`, err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return <>{items}</>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,9 @@ export default definePlugin({
|
||||||
patches: [{
|
patches: [{
|
||||||
find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL",
|
find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /"reply-self".+?Fragment,{children:\[(?=.+?\((\i\.\i),{label:)(?<=message:(\i).+?)/,
|
// foo && !bar ? createElement(reactionStuffs)... createElement(blah,...makeElement(reply-other))
|
||||||
replace: (m, PopoverButton, msg) => `${m}...Vencord.Api.MessagePopover._buildPopoverElements(${msg},${PopoverButton}),`
|
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),$&"
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
* along with AdGuard's Block YouTube Ads. If not, see <http://www.gnu.org/licenses/>.
|
* along with AdGuard's Block YouTube Ads. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const LOGO_ID = "block-youtube-ads-logo";
|
|
||||||
const hiddenCSS = [
|
const hiddenCSS = [
|
||||||
"#__ffYoutube1",
|
"#__ffYoutube1",
|
||||||
"#__ffYoutube2",
|
"#__ffYoutube2",
|
||||||
|
@ -98,7 +97,7 @@ const hideElements = () => {
|
||||||
}
|
}
|
||||||
const rule = selectors.join(", ") + " { display: none!important; }";
|
const rule = selectors.join(", ") + " { display: none!important; }";
|
||||||
const style = document.createElement("style");
|
const style = document.createElement("style");
|
||||||
style.innerHTML = rule;
|
style.textContent = rule;
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
|
@ -193,68 +192,25 @@ const jsonOverride = (propertyName, overrideValue) => {
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
// Override Response.prototype.json
|
// Override Response.prototype.json
|
||||||
const nativeResponseJson = Response.prototype.json;
|
Response.prototype.json = new Proxy(Response.prototype.json, {
|
||||||
Response.prototype.json = new Proxy(nativeResponseJson, {
|
async apply(...args) {
|
||||||
apply(...args) {
|
|
||||||
// Call the target function, get the original Promise
|
// 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
|
// Create a new one and override the JSON inside
|
||||||
return new Promise((resolve, reject) => {
|
overrideObject(result, propertyName, overrideValue);
|
||||||
promise.then(data => {
|
return result;
|
||||||
overrideObject(data, propertyName, overrideValue);
|
|
||||||
resolve(data);
|
|
||||||
}).catch(error => reject(error));
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
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
|
// Removes ads metadata from YouTube XHR requests
|
||||||
jsonOverride("adPlacements", []);
|
jsonOverride("adPlacements", []);
|
||||||
jsonOverride("playerAds", []);
|
jsonOverride("playerAds", []);
|
||||||
// Applies CSS that hides YouTube ad elements
|
// Applies CSS that hides YouTube ad elements
|
||||||
hideElements();
|
hideElements();
|
||||||
// Some changes should be re-evaluated on every page change
|
// Some changes should be re-evaluated on every page change
|
||||||
addAdGuardLogo();
|
|
||||||
hideDynamicAds();
|
hideDynamicAds();
|
||||||
autoSkipAds();
|
autoSkipAds();
|
||||||
observeDomChanges(() => {
|
observeDomChanges(() => {
|
||||||
addAdGuardLogo();
|
|
||||||
hideDynamicAds();
|
hideDynamicAds();
|
||||||
autoSkipAds();
|
autoSkipAds();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue