mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-08 14:13:01 -04:00
Updates
This commit is contained in:
commit
32b44e9822
15 changed files with 142 additions and 74 deletions
|
@ -11,7 +11,7 @@ import { get } from "@api/DataStore";
|
|||
import { definePluginSettings, migratePluginSettings, Settings } from "@api/Settings";
|
||||
import { EquicordDevs } from "@utils/constants";
|
||||
import { openModal } from "@utils/modal";
|
||||
import definePlugin, { OptionType, ReporterTestable } from "@utils/types";
|
||||
import definePlugin, { OptionType } from "@utils/types";
|
||||
import { extractAndLoadChunksLazy } from "@webpack";
|
||||
import { Menu } from "@webpack/common";
|
||||
import { User } from "discord-types/general";
|
||||
|
@ -76,7 +76,6 @@ export default definePlugin({
|
|||
description: "Lets you add a custom color to any user, anywhere! Highly recommend to use with typingTweaks and roleColorEverywhere",
|
||||
authors: [EquicordDevs.mochienya],
|
||||
contextMenus: { "user-context": userContextMenuPatch },
|
||||
reporterTestable: ReporterTestable.None,
|
||||
settings,
|
||||
requireSettingsMenu,
|
||||
getCustomColorString,
|
||||
|
@ -88,7 +87,8 @@ export default definePlugin({
|
|||
replacement: {
|
||||
match: /style:"username"===.{0,25}void 0/,
|
||||
replace: "style:{color:$self.colorIfServer(arguments[0])}"
|
||||
}
|
||||
},
|
||||
noWarn: true,
|
||||
},
|
||||
{
|
||||
predicate: () => settings.store.dmList,
|
||||
|
|
|
@ -16,8 +16,8 @@ export default definePlugin({
|
|||
{
|
||||
find: "SCALE_DOWN:",
|
||||
replacement: {
|
||||
match: /!\(null==(\i)\|\|0===\i\|\|null==(\i)\|\|0===\i\)/,
|
||||
replace: (_, width, height) => `!((null == ${width} || 0 === ${width}) && (null == ${height} || 0 === ${height}))`
|
||||
match: /(?<="IMAGE"===\i\?)\i(?=\?)/,
|
||||
replace: "true"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -26,10 +26,18 @@ export default definePlugin({
|
|||
patches: [
|
||||
{
|
||||
find: '"ChannelAttachButton"',
|
||||
replacement: {
|
||||
match: /\.attachButtonInner,"aria-label":.{0,50},onDoubleClick:(.+?:void 0),.{0,30}?\.\.\.(\i),/,
|
||||
replace: "$&onClick:$1,onContextMenu:$2.onClick,",
|
||||
},
|
||||
replacement: [
|
||||
{
|
||||
// FIXME(Bundler spread transform related): Remove old compatiblity once enough time has passed, if they don't revert
|
||||
match: /\.attachButtonInner,"aria-label":.{0,50},onDoubleClick:(.+?:void 0),.{0,30}?\.\.\.(\i),/,
|
||||
replace: "$&onClick:$1,onContextMenu:$2.onClick,",
|
||||
noWarn: true
|
||||
},
|
||||
{
|
||||
match: /\.attachButtonInner,"aria-label":.{0,50},onDoubleClick:(.+?:void 0),.{0,100}\},(\i)\).{0,100}children:\i/,
|
||||
replace: "$&,onClick:$1,onContextMenu:$2.onClick,",
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
|
@ -50,12 +50,24 @@ export default definePlugin({
|
|||
find: ".decorationGridItem,",
|
||||
replacement: [
|
||||
{
|
||||
match: /(?<==)\i=>{let{children.{20,100}decorationGridItem/,
|
||||
replace: "$self.DecorationGridItem=$&"
|
||||
// FIXME(Bundler spread transform related): Remove old compatiblity once enough time has passed, if they don't revert
|
||||
match: /(?<==)\i=>{let{children.{20,200}decorationGridItem/,
|
||||
replace: "$self.DecorationGridItem=$&",
|
||||
noWarn: true
|
||||
},
|
||||
{
|
||||
// FIXME(Bundler spread transform related): Remove old compatiblity once enough time has passed, if they don't revert
|
||||
match: /(?<==)\i=>{let{user:\i,avatarDecoration/,
|
||||
replace: "$self.DecorationGridDecoration=$&"
|
||||
replace: "$self.DecorationGridDecoration=$&",
|
||||
noWarn: true
|
||||
},
|
||||
{
|
||||
match: /(?<==)\i=>{var{children.{20,200}decorationGridItem/,
|
||||
replace: "$self.DecorationGridItem=$&",
|
||||
},
|
||||
{
|
||||
match: /(?<==)\i=>{var{user:\i,avatarDecoration/,
|
||||
replace: "$self.DecorationGridDecoration=$&",
|
||||
},
|
||||
// Remove NEW label from decor avatar decorations
|
||||
{
|
||||
|
|
|
@ -34,7 +34,7 @@ export default definePlugin({
|
|||
{
|
||||
find: "#{intl::FRIENDS_ALL_HEADER}",
|
||||
replacement: {
|
||||
match: /toString\(\)\}\);case (\i\.\i)\.BLOCKED/,
|
||||
match: /toString\(\)\}\);case (\i\.\i)\.PENDING/,
|
||||
replace: 'toString()});case $1.IMPLICIT:return "Implicit — "+arguments[1];case $1.BLOCKED'
|
||||
},
|
||||
},
|
||||
|
@ -50,7 +50,7 @@ export default definePlugin({
|
|||
{
|
||||
find: "#{intl::FRIENDS_SECTION_ONLINE}",
|
||||
replacement: {
|
||||
match: /,{id:(\i\.\i)\.BLOCKED,show:.+?className:(\i\.item)/,
|
||||
match: /,{id:(\i\.\i)\.PENDING,show:.+?className:(\i\.item)/,
|
||||
replace: (rest, relationShipTypes, className) => `,{id:${relationShipTypes}.IMPLICIT,show:true,className:${className},content:"Implicit"}${rest}`
|
||||
}
|
||||
},
|
||||
|
@ -58,7 +58,7 @@ export default definePlugin({
|
|||
{
|
||||
find: '"FriendsStore"',
|
||||
replacement: {
|
||||
match: /(?<=case (\i\.\i)\.BLOCKED:return (\i)\.type===\i\.\i\.BLOCKED)/,
|
||||
match: /(?<=case (\i\.\i)\.SUGGESTIONS:return \d+===(\i)\.type)/,
|
||||
replace: ";case $1.IMPLICIT:return $2.type===5"
|
||||
},
|
||||
},
|
||||
|
|
|
@ -65,10 +65,18 @@ export default definePlugin({
|
|||
patches: [
|
||||
{
|
||||
find: "{isSidebarVisible:",
|
||||
replacement: {
|
||||
match: /(?<=let\{className:(\i),.+?children):\[(\i\.useMemo[^}]+"aria-multiselectable")/,
|
||||
replace: ":[$1?.startsWith('members')?$self.render():null,$2"
|
||||
},
|
||||
replacement: [
|
||||
{
|
||||
// FIXME(Bundler spread transform related): Remove old compatiblity once enough time has passed, if they don't revert
|
||||
match: /(?<=let\{className:(\i),.+?children):\[(\i\.useMemo[^}]+"aria-multiselectable")/,
|
||||
replace: ":[$1?.startsWith('members')?$self.render():null,$2",
|
||||
noWarn: true
|
||||
},
|
||||
{
|
||||
match: /(?<=var\{className:(\i),.+?children):\[(\i\.useMemo[^}]+"aria-multiselectable")/,
|
||||
replace: ":[$1?.startsWith('members')?$self.render():null,$2",
|
||||
},
|
||||
],
|
||||
predicate: () => settings.store.memberList
|
||||
},
|
||||
{
|
||||
|
|
|
@ -85,8 +85,14 @@ export default definePlugin({
|
|||
find: ".USER_MENTION)",
|
||||
replacement: [
|
||||
{
|
||||
// FIXME(Bundler spread transform related): Remove old compatiblity once enough time has passed, if they don't revert
|
||||
match: /onContextMenu:\i,color:\i,\.\.\.\i(?=,children:)(?<=user:(\i),channel:(\i).{0,500}?)/,
|
||||
replace: "$&,color:$self.getColorInt($1?.id,$2?.id)"
|
||||
replace: "$&,color:$self.getColorInt($1?.id,$2?.id)",
|
||||
noWarn: true
|
||||
},
|
||||
{
|
||||
match: /(?<=onContextMenu:\i,color:)\i(?=\},\i\),\{children)(?<=user:(\i),channel:(\i).{0,500}?)/,
|
||||
replace: "$self.getColorInt($1?.id,$2?.id)",
|
||||
}
|
||||
],
|
||||
predicate: () => settings.store.chatMentions
|
||||
|
|
|
@ -218,6 +218,7 @@ export default definePlugin({
|
|||
},
|
||||
{
|
||||
// Make muted channels also appear as unread if hide unreads is false and the channel is hidden
|
||||
// FIXME(Bundler change related): Remove old compatiblity once enough time has passed
|
||||
predicate: () => settings.store.channelStyle === ChannelStyle.MutedUnread || settings.store.channelStyle === ChannelStyle.Unread,
|
||||
match: /(?<=\.LOCKED(?:;if\(|:))(?<={channel:(\i).+?)/,
|
||||
replace: (_, channel) => `!$self.isHiddenChannel(${channel})&&`
|
||||
|
@ -235,7 +236,7 @@ export default definePlugin({
|
|||
},
|
||||
{
|
||||
// Hide unreads
|
||||
match: /{channel:(\i),name:\i,.+?unread:(\i).+?;/,
|
||||
match: /\.subtitle,.+?;(?=return\(0,\i\.jsxs?\))(?<={channel:(\i),name:\i,.+?unread:(\i).+?)/,
|
||||
replace: (m, channel, unread) => `${m}${unread}=$self.isHiddenChannel(${channel})?false:${unread};`
|
||||
}
|
||||
]
|
||||
|
@ -516,7 +517,7 @@ export default definePlugin({
|
|||
}
|
||||
},
|
||||
{
|
||||
find: '="NowPlayingViewStore",',
|
||||
find: '"NowPlayingViewStore"',
|
||||
replacement: {
|
||||
// Make active now voice states on hidden channels
|
||||
match: /(getVoiceStateForUser.{0,150}?)&&\i\.\i\.canWithPartialContext.{0,20}VIEW_CHANNEL.+?}\)(?=\?)/,
|
||||
|
|
|
@ -27,12 +27,22 @@ export default definePlugin({
|
|||
authors: [Devs.Megu],
|
||||
patches: [{
|
||||
find: "#{intl::ACTIVITY_SETTINGS}",
|
||||
replacement: {
|
||||
match: /(?<=}\)([,;])(\i\.settings)\.forEach.+?(\i)\.push.+}\)}\))/,
|
||||
replace: (_, commaOrSemi, settings, elements) => "" +
|
||||
`${commaOrSemi}${settings}?.[0]==="CHANGELOG"` +
|
||||
`&&${elements}.push({section:"StartupTimings",label:"Startup Timings",element:$self.StartupTimingPage})`
|
||||
}
|
||||
replacement: [
|
||||
{
|
||||
// FIXME(Bundler spread transform related): Remove old compatiblity once enough time has passed, if they don't revert
|
||||
match: /(?<=}\)([,;])(\i\.settings)\.forEach.+?(\i)\.push.+}\)}\))/,
|
||||
replace: (_, commaOrSemi, settings, elements) => "" +
|
||||
`${commaOrSemi}${settings}?.[0]==="CHANGELOG"` +
|
||||
`&&${elements}.push({section:"StartupTimings",label:"Startup Timings",element:$self.StartupTimingPage})`,
|
||||
noWarn: true
|
||||
},
|
||||
{
|
||||
match: /(?<=}\)([,;])(\i\.settings)\.forEach.+?(\i)\.push.+\)\)\}\))(?=\)\})/,
|
||||
replace: (_, commaOrSemi, settings, elements) => "" +
|
||||
`${commaOrSemi}${settings}?.[0]==="CHANGELOG"` +
|
||||
`&&${elements}.push({section:"StartupTimings",label:"Startup Timings",element:$self.StartupTimingPage})`,
|
||||
},
|
||||
]
|
||||
}],
|
||||
StartupTimingPage
|
||||
});
|
||||
|
|
|
@ -41,11 +41,20 @@ export default definePlugin({
|
|||
},
|
||||
{
|
||||
find: '="SYSTEM_TAG"',
|
||||
replacement: {
|
||||
// Add next to username (compact mode)
|
||||
match: /className:\i\(\)\(\i\.className(?:,\i\.clickable)?,\i\)}\),(?=\i)/g,
|
||||
replace: "$&$self.CompactPronounsChatComponentWrapper(arguments[0]),"
|
||||
}
|
||||
replacement: [
|
||||
{
|
||||
// Add next to username (compact mode)
|
||||
// FIXME(Bundler spread transform related): Remove old compatiblity once enough time has passed, if they don't revert
|
||||
match: /className:\i\(\)\(\i\.className(?:,\i\.clickable)?,\i\)}\),(?=\i)/g,
|
||||
replace: "$&$self.CompactPronounsChatComponentWrapper(arguments[0]),",
|
||||
noWarn: true
|
||||
},
|
||||
{
|
||||
// Add next to username (compact mode)
|
||||
match: /className:\i\(\)\(\i\.className(?:,\i\.clickable)?,\i\)}\)\),(?=\i)/g,
|
||||
replace: "$&$self.CompactPronounsChatComponentWrapper(arguments[0]),",
|
||||
},
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
|
|
|
@ -193,10 +193,18 @@ export default definePlugin({
|
|||
// Avatar component used in User DMs "User Profile" popup in the right and Profiles Modal pfp
|
||||
{
|
||||
find: ".overlay:void 0,status:",
|
||||
replacement: {
|
||||
match: /avatarSrc:(\i),eventHandlers:(\i).+?"div",{...\2,/,
|
||||
replace: "$&style:{cursor:\"pointer\"},onClick:()=>{$self.openAvatar($1)},"
|
||||
},
|
||||
replacement: [
|
||||
{
|
||||
// FIXME(Bundler spread transform related): Remove old compatiblity once enough time has passed, if they don't revert
|
||||
match: /avatarSrc:(\i),eventHandlers:(\i).+?"div",{...\2,/,
|
||||
replace: "$&style:{cursor:\"pointer\"},onClick:()=>{$self.openAvatar($1)},",
|
||||
noWarn: true
|
||||
},
|
||||
{
|
||||
match: /avatarSrc:(\i),eventHandlers:(\i).+?"div",.{0,100}className:\i,/,
|
||||
replace: "$&style:{cursor:\"pointer\"},onClick:()=>{$self.openAvatar($1)},",
|
||||
}
|
||||
],
|
||||
all: true
|
||||
},
|
||||
// Banners
|
||||
|
|
|
@ -20,9 +20,9 @@ export function makeLazy<T>(factory: () => T, attempts = 5): () => T {
|
|||
let tries = 0;
|
||||
let cache: T;
|
||||
return () => {
|
||||
if (!cache && attempts > tries++) {
|
||||
if (cache === undefined && attempts > tries++) {
|
||||
cache = factory();
|
||||
if (!cache && attempts === tries)
|
||||
if (cache === undefined && attempts === tries)
|
||||
console.error("Lazy factory failed:", factory);
|
||||
}
|
||||
return cache;
|
||||
|
|
|
@ -41,7 +41,12 @@ export interface PatchReplacement {
|
|||
match: string | RegExp;
|
||||
/** The replacement string or function which returns the string for the patch replacement */
|
||||
replace: string | ReplaceFn;
|
||||
/** A function which returns whether this patch replacement should be applied */
|
||||
/** Do not warn if this replacement did no changes */
|
||||
noWarn?: boolean;
|
||||
/**
|
||||
* A function which returns whether this patch replacement should be applied.
|
||||
* This is ran before patches are registered, so if this returns false, the patch will never be registered.
|
||||
*/
|
||||
predicate?(): boolean;
|
||||
/** The minimum build number for this patch to be applied */
|
||||
fromBuild?: number;
|
||||
|
@ -61,7 +66,10 @@ export interface Patch {
|
|||
noWarn?: boolean;
|
||||
/** Only apply this set of replacements if all of them succeed. Use this if your replacements depend on each other */
|
||||
group?: boolean;
|
||||
/** A function which returns whether this patch should be applied */
|
||||
/**
|
||||
* A function which returns whether this patch replacement should be applied.
|
||||
* This is ran before patches are registered, so if this returns false, the patch will never be registered.
|
||||
*/
|
||||
predicate?(): boolean;
|
||||
/** The minimum build number for this patch to be applied */
|
||||
fromBuild?: number;
|
||||
|
|
|
@ -41,7 +41,7 @@ export const Switch = waitForComponent<t.Switch>("Switch", filters.componentByCo
|
|||
|
||||
const Tooltips = mapMangledModuleLazy(".tooltipTop,bottom:", {
|
||||
Tooltip: filters.componentByCode("this.renderTooltip()]"),
|
||||
TooltipContainer: filters.componentByCode('="div",')
|
||||
TooltipContainer: filters.componentByCode('="div"')
|
||||
}) as {
|
||||
Tooltip: t.Tooltip,
|
||||
TooltipContainer: t.TooltipContainer;
|
||||
|
|
|
@ -13,8 +13,8 @@ import { Patch, PatchReplacement } from "@utils/types";
|
|||
import { reporterData } from "debug/reporterData";
|
||||
|
||||
import { traceFunctionWithResults } from "../debug/Tracer";
|
||||
import { _blacklistBadModules, _initWebpack, factoryListeners, findModuleId, moduleListeners, waitForSubscriptions, wreq } from "./webpack";
|
||||
import { AnyModuleFactory, AnyWebpackRequire, MaybePatchedModuleFactory, ModuleExports, PatchedModuleFactory, WebpackRequire } from "./wreq.d";
|
||||
import { _blacklistBadModules, _initWebpack, factoryListeners, findModuleFactory, moduleListeners, waitForSubscriptions, wreq } from "./webpack";
|
||||
import { AnyModuleFactory, AnyWebpackRequire, MaybePatchedModuleFactory, PatchedModuleFactory, WebpackRequire } from "./wreq.d";
|
||||
|
||||
export const patches = [] as Patch[];
|
||||
|
||||
|
@ -28,28 +28,26 @@ export const patchTimings = [] as Array<[plugin: string, moduleId: PropertyKey,
|
|||
|
||||
export const getBuildNumber = makeLazy(() => {
|
||||
try {
|
||||
try {
|
||||
if (wreq.m[128014]?.toString().includes("Trying to open a changelog for an invalid build number")) {
|
||||
const hardcodedGetBuildNumber = wreq(128014).b as () => number;
|
||||
|
||||
if (typeof hardcodedGetBuildNumber === "function" && typeof hardcodedGetBuildNumber() === "number") {
|
||||
return hardcodedGetBuildNumber();
|
||||
}
|
||||
function matchBuildNumber(factoryStr: string) {
|
||||
const buildNumberMatch = factoryStr.match(/.concat\("(\d+?)"\)/);
|
||||
if (buildNumberMatch == null) {
|
||||
return -1;
|
||||
}
|
||||
} catch { }
|
||||
|
||||
const moduleId = findModuleId("Trying to open a changelog for an invalid build number");
|
||||
if (moduleId == null) {
|
||||
return -1;
|
||||
return Number(buildNumberMatch[1]);
|
||||
}
|
||||
|
||||
const exports = Object.values<ModuleExports>(wreq(moduleId));
|
||||
if (exports.length !== 1 || typeof exports[0] !== "function") {
|
||||
return -1;
|
||||
const hardcodedFactoryStr = String(wreq.m[128014]);
|
||||
if (hardcodedFactoryStr.includes("Trying to open a changelog for an invalid build number")) {
|
||||
const hardcodedBuildNumber = matchBuildNumber(hardcodedFactoryStr);
|
||||
|
||||
if (hardcodedBuildNumber !== -1) {
|
||||
return hardcodedBuildNumber;
|
||||
}
|
||||
}
|
||||
|
||||
const buildNumber = exports[0]();
|
||||
return typeof buildNumber === "number" ? buildNumber : -1;
|
||||
const moduleFactory = findModuleFactory("Trying to open a changelog for an invalid build number");
|
||||
return matchBuildNumber(String(moduleFactory));
|
||||
} catch {
|
||||
return -1;
|
||||
}
|
||||
|
@ -123,12 +121,12 @@ define(Function.prototype, "m", {
|
|||
return;
|
||||
}
|
||||
|
||||
patchThisInstance();
|
||||
|
||||
if (wreq == null && this.c != null) {
|
||||
logger.info("Main WebpackInstance found" + interpolateIfDefined` in ${fileName}` + ", initializing internal references to WebpackRequire");
|
||||
_initWebpack(this as WebpackRequire);
|
||||
}
|
||||
|
||||
patchThisInstance();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -479,23 +477,23 @@ function patchFactory(moduleId: PropertyKey, originalFactory: AnyModuleFactory):
|
|||
for (let i = 0; i < patches.length; i++) {
|
||||
const patch = patches[i];
|
||||
|
||||
const moduleMatches = typeof patch.find === "string"
|
||||
? code.includes(patch.find)
|
||||
: (patch.find.global && (patch.find.lastIndex = 0), patch.find.test(code));
|
||||
|
||||
if (!moduleMatches) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Eager patches cannot retrieve the build number because this code runs before the module for it is loaded
|
||||
const buildNumber = Settings.eagerPatches ? -1 : getBuildNumber();
|
||||
const shouldCheckBuildNumber = !Settings.eagerPatches && buildNumber !== -1;
|
||||
const buildNumber = getBuildNumber();
|
||||
const shouldCheckBuildNumber = buildNumber !== -1;
|
||||
|
||||
if (
|
||||
shouldCheckBuildNumber &&
|
||||
(patch.fromBuild != null && buildNumber < patch.fromBuild) ||
|
||||
(patch.toBuild != null && buildNumber > patch.toBuild)
|
||||
) {
|
||||
patches.splice(i--, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
const moduleMatches = typeof patch.find === "string"
|
||||
? code.includes(patch.find)
|
||||
: (patch.find.global && (patch.find.lastIndex = 0), patch.find.test(code));
|
||||
|
||||
if (!moduleMatches) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -537,7 +535,7 @@ function patchFactory(moduleId: PropertyKey, originalFactory: AnyModuleFactory):
|
|||
}
|
||||
|
||||
if (newCode === code) {
|
||||
if (!patch.noWarn) {
|
||||
if (!(patch.noWarn || replacement.noWarn)) {
|
||||
logger.warn(`Patch by ${patch.plugin} had no effect (Module id is ${String(moduleId)}): ${replacement.match}`);
|
||||
if (IS_DEV) {
|
||||
logger.debug("Function Source:\n", code);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue