Skip to content

Commit

Permalink
\i-ification
Browse files Browse the repository at this point in the history
  • Loading branch information
Cynosphere committed Jan 9, 2025
1 parent fac2ccb commit 0c013eb
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 52 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@moonlight-mod/eslint-config": "github:moonlight-mod/eslint-config",
"esbuild": "^0.19.3",
"esbuild-copy-static-files": "^0.1.0",
"eslint": "^9.12.0",
"eslint": "^9.17.0",
"typescript": "^5.3.2"
},
"dependencies": {
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/allActivities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const patches: Patch[] = [
{
find: '"UserProfileFeaturedActivity"',
replace: {
match: /:function\(\){return (.)}/,
match: /:function\(\){return (\i)}/,
replacement: ':function(){return require("allActivities_activities").default}'
}
},
Expand All @@ -14,7 +14,7 @@ export const patches: Patch[] = [
{
find: '.STREAM_PREVIEW="StreamPreview"',
replace: {
match: /\(null==.\?void 0:.\.type\)!==.\.[a-zA-Z_$][\w$]*\.PLAYING&&/,
match: /\(null==\i\?void 0:\i\.type\)!==\i\.\i\.PLAYING&&/,
replacement: (orig: string) => orig + orig.replace("PLAYING", "COMPETING")
}
},
Expand All @@ -23,7 +23,7 @@ export const patches: Patch[] = [
{
find: '("use-user-profile-activity")',
replace: {
match: /\(0,.\.uniqWith\)/,
match: /\(0,\i\.uniqWith\)/,
replacement: "((inp)=>inp)"
}
},
Expand All @@ -32,7 +32,7 @@ export const patches: Patch[] = [
{
find: ".lostPermission",
replace: {
match: /name:null==.\?(\(0,.\.jsx\))\("span"/,
match: /name:null==\i\?(\(0,\i\.jsx\))\("span"/,
replacement: (orig, createElement) =>
`children:${createElement}(require("allActivities_icons").default,{user:arguments[0].user}),${orig}`
},
Expand Down
18 changes: 9 additions & 9 deletions src/chatTweaks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const patches: Patch[] = [
{
find: ',source:"message-actions"})',
replace: {
match: /,message:(.),shouldMention:(!(.)\.shiftKey&&!(.)),/,
match: /,message:(\i),shouldMention:(!(\i)\.shiftKey&&!(\i)),/,
replacement: (_, message, shouldMention, keyEvent, self) =>
`,message:${message},shouldMention:require("chatTweaks_noReplyPing")?.default?.(${message},${keyEvent},${self})??(${shouldMention}),`
}
Expand All @@ -17,7 +17,7 @@ export const patches: Patch[] = [
{
find: ",replyChainLength:",
replace: {
match: /=(.\.showThreadPromptOnReply)&&/,
match: /=(\i\.showThreadPromptOnReply)&&/,
replacement: (_, showThreadPromptOnReply) =>
`=(moonlight.getConfigOption("chatTweaks","noReplyChainNag")??true?false:${showThreadPromptOnReply})&&`
}
Expand All @@ -37,15 +37,15 @@ export const patches: Patch[] = [
{
find: ".BOT:default:",
replace: {
match: /case .\..{1,3}\.BOT:default:(.)=/,
match: /case \i\.\i\.BOT:default:(\i)=/,
replacement: (orig, tag) => `case 99:${tag}="WEBHOOK";break;${orig}`
},
prerequisite: webhookTag
},
{
find: ".Types.ORIGINAL_POSTER",
replace: {
match: /(.)=.\.Z\.Types\.ORIGINAL_POSTER\),/,
match: /(\i)=\i\.\i\.Types\.ORIGINAL_POSTER\),/,
replacement: (orig, type) =>
`${orig}(arguments[0].user?.bot&&arguments[0].message?.webhookId&&arguments[0].user?.isNonUserBot?.()&&(${type}=99)),`
},
Expand All @@ -56,8 +56,8 @@ export const patches: Patch[] = [
{
find: '("interactionAvatarProfile",',
replace: {
match: /&&\(.\?.\.Z.show\({.+?:(.)\.Z.jumpToMessage/,
replacement: (_, mod) => `&&(${mod}.Z.jumpToMessage`
match: /&&\(\i\?\i\.\i.show\({.+?:(\i\.\i).jumpToMessage/,
replacement: (_, mod) => `&&(${mod}.jumpToMessage`
},
prerequisite: () => moonlight.getConfigOption<boolean>("chatTweaks", "jumpToBlocked") ?? true
},
Expand All @@ -66,7 +66,7 @@ export const patches: Patch[] = [
{
find: 'key:"pending-upload-".concat(',
replace: {
match: /if\((.)\.type===(.\..{1,3})\.MESSAGE_GROUP_BLOCKED\|\|/,
match: /if\((\i)\.type===(\i\.\i)\.MESSAGE_GROUP_BLOCKED\|\|/,
replacement: (orig, message, types) =>
`if(${message}.type===${types}.MESSAGE_GROUP_BLOCKED&&(moonlight.getConfigOption("chatTweaks","hideBlocked")??false))return;if(${message}.type===${types}.MESSAGE_GROUP_IGNORED&&(moonlight.getConfigOption("chatTweaks","hideIgnored")??false))return;${orig}`
}
Expand All @@ -76,7 +76,7 @@ export const patches: Patch[] = [
{
find: ".lostPermission",
replace: {
match: /=>null!=(.)&&.&&null==/,
match: /=>null!=(\i)&&\i&&null==/,
replacement: (_, isOwner) =>
`=>null!=(${isOwner}=require("chatTweaks_ownerCrown").default(arguments[0]))&&${isOwner}&&null==`
}
Expand All @@ -86,7 +86,7 @@ export const patches: Patch[] = [
{
find: '.insertText("](".concat',
replace: {
match: /if\((null!=.&&null==.)\){/,
match: /if\((null!=\i&&null==\i)\){/,
replacement: (_, linkCheck) =>
`if((moonlight.getConfigOption("chatTweaks","noMaskedLinkPaste")??true)?false:${linkCheck}){`
}
Expand Down
18 changes: 9 additions & 9 deletions src/mediaTweaks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const patches: Patch[] = [
{
find: "allowLinks:!!",
replace: {
match: /,(\(null!=.\?.:.\)\.embeds\)\),)/,
match: /,(\(null!=\i\?\i:\i\)\.embeds\)\),)/,
replacement: (_, orig) => `,moonlight.getConfigOption("mediaTweaks","imageUrls")??true?{}:${orig}`
}
},
Expand All @@ -14,7 +14,7 @@ export const patches: Patch[] = [
{
find: ".TOGGLE_GIF_PICKER,handler:",
replace: {
match: /[A-Za-z_$][\w$]*===[A-Za-z_$][\w$]*\.[A-Za-z_$][\w$]*\.CREATE_FORUM_POST/,
match: /\i===\i\.\i\.CREATE_FORUM_POST/,
replacement: (orig: string) => `(moonlight.getConfigOption("mediaTweaks","noGifAutosend")??true?true:${orig})`
}
},
Expand All @@ -24,7 +24,7 @@ export const patches: Patch[] = [
find: "renderMetadata()",
replace: {
match:
/(?<=(.===.\.VIDEO)\?.+?(\(0,.\.jsx\))\("div",{className:(.+?\.overlayContentHidden]:).\|\|.\}\),children:.\(\)}\):null)]/,
/(?<=(\i===\i\.VIDEO)\?.+?(\(0,\i\.jsx\))\("div",{className:(.+?\.overlayContentHidden]:)\i\|\|\i\}\),children:\i\(\)}\):null)]/,
replacement: (_, videoCheck, createElement, className) =>
`,${videoCheck}&&(moonlight.getConfigOption("mediaTweaks","videoMetadata")??true)?${createElement}("div",{className:${className}this.state.playing&&!this.state.hovering}),children:${createElement}(require("mediaTweaks_videoMetadata").default,this.props)}):null]`
}
Expand All @@ -34,7 +34,7 @@ export const patches: Patch[] = [
{
find: 'location:"MessageAccessories"',
replace: {
match: /=(\(0,.\..{1,2}\))\((.),({shouldRedactExplicitContent:.,shouldHideMediaOptions:.}),("Media Mosaic")\),/,
match: /=(\(0,\i\.\i\))\((\i),({shouldRedactExplicitContent:\i,shouldHideMediaOptions:\i}),("Media Mosaic")\),/,
replacement: (_, createCarousel, attachments, props, analytics) =>
`=${createCarousel}((moonlight.getConfigOption("mediaTweaks","inlineMosaicPlayback")??true)?${attachments}.filter(x=>x.type!="VIDEO"):${attachments},${props},${analytics}),`
}
Expand All @@ -48,14 +48,14 @@ export const patches: Patch[] = [
replace: [
// Send the full item over
{
match: /,downloadURL:(.)\.downloadUrl,/,
match: /,downloadURL:(\i)\.downloadUrl,/,
replacement: (orig, item) => `,item:${item}${orig}`
},

// Add button
{
match:
/(?<=isVisualMediaType:.,channelId:.+?}=(.);.+?"MosaicItemHoverButtons"\);)(?=.&&null!=.&&(.)\.push\((\(0,.\.jsx\)))/,
/(?<=isVisualMediaType:\i,channelId:.+?}=(\i);.+?"MosaicItemHoverButtons"\);)(?=\i&&null!=\i&&(\i)\.push\((\(0,\i\.jsx\)))/,
replacement: (_, props, buttons, createElement) =>
`${buttons}.push(${createElement}(require("mediaTweaks_enlargeVideoButton").default,${props},"mediaTweaks_enlargeVideoButton"));`
}
Expand All @@ -72,9 +72,9 @@ export const patches: Patch[] = [

// No WebP and No Thumbnail Size
{
find: /\(.{1,2}\+="\?"\+.{1,2}\.stringify\(.{1,2}\)\)/,
find: /\(\i\+="\?"\+\i\.stringify\(\i\)\)/,
replace: {
match: /if\((.)\.sourceWidth<.\.targetWidth\){/,
match: /if\((\i)\.sourceWidth<.\.targetWidth\){/,
replacement: (orig, props) => `require("mediaTweaks_imagePropsProcessor").default(${props});${orig}`
}
},
Expand All @@ -83,7 +83,7 @@ export const patches: Patch[] = [
{
find: ',"chat input type must be set");',
replace: {
match: /(?<=!.&&\()(\(0,.\..{1,2}\)\(.+?\.drafts\.type\))\?/,
match: /(?<=!\i&&\()(\(0,\i\.\i\)\(.+?\.drafts\.type\))\?/,
replacement: (_, orig) => `((moonlight.getConfigOption("mediaTweaks","noStickerAutosend")??true)?true:${orig})?`
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/noRpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const patches: Patch[] = [
find: '"RunningGameStore"',
replace: [
{
match: /.\.[a-zA-Z]+\.dispatch(\({type:"RUNNING_GAMES_CHANGE",games:.,added:.,removed:.}\))/,
match: /\i\.\i\.dispatch(\({type:"RUNNING_GAMES_CHANGE",games:\i,added:\i,removed:\i}\))/,
// this isn't just a removal because haha removing breaks quietLoggers
// and i dont feel like fixing (nor should i even have to fix, if you
// pretend that im just a standard extension dev in this scenario)
Expand Down
22 changes: 11 additions & 11 deletions src/platformIcons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const patches: Patch[] = [
{
find: '},"new-member")),',
replace: {
match: /(?<=(\(0,.\.jsx\)).+?)\.BADGES]=(.);/,
match: /(?<=(\(0,\i\.jsx\)).+?)\.BADGES]=(.);/,
replacement: (_, createElement, badges) =>
`.BADGES]=[${createElement}(require("platformIcons_icons").default,{user:arguments[0].message.author,configKey:"messages",extraClasses:["platform-icons-message"],size:"sm"}),...${badges}];`
}
Expand All @@ -19,7 +19,7 @@ export const patches: Patch[] = [
{
find: ".lostPermission",
replace: {
match: /(\(0,.\.jsxs\))\(.\.Fragment,{children:\[.{1,2}\(\),/,
match: /(\(0,\i\.jsxs\))\(\i\.Fragment,{children:\[\i\(\),/,
replacement: (orig: string, createElement) =>
`${orig}${createElement}(require("platformIcons_icons").default,{user:arguments[0].user,configKey:"memberList",extraClasses:["platform-icons-member-list"]}),`
}
Expand All @@ -30,7 +30,7 @@ export const patches: Patch[] = [
{
find: ".interactiveSystemDM]:",
replace: {
match: /decorators:(.\.isSystemDM\(\)\?(\(0,.\.jsx\))\(.+?verified:!0}\):null)/,
match: /decorators:(\i\.isSystemDM\(\)\?(\(0,\i\.jsx\))\(.+?verified:!0}\):null)/,
replacement: (_, orig, createElement) =>
`decorators:[${orig},${createElement}(require("platformIcons_icons").default,{user:arguments[0].user,configKey:"directMessages",extraClasses:["platform-icons-private-message"]})]`
}
Expand All @@ -41,7 +41,7 @@ export const patches: Patch[] = [
{
find: ".userTagDiscriminator,hideBotTag:!0",
replace: {
match: /,(\(0,.\.jsx\))\(.\.ZP,{userId:(.)\.id,.+?(.)\.clanTag}\),/,
match: /,(\(0,\i\.jsx\))\(\i\.\i,{userId:(\i)\.id,.+?(\i)\.clanTag}\),/,
replacement: (orig: string, createElement, user, ProfileClasses) =>
`${orig}${createElement}(require("platformIcons_icons").default,{user:${user},configKey:"profiles",extraClasses:["platform-icons-profile", ${ProfileClasses}.clanTagContainer, ${ProfileClasses}.clanTag]}),`
}
Expand All @@ -51,7 +51,7 @@ export const patches: Patch[] = [
{
find: ".listCollapse",
replace: {
match: /(?<=(\(0,.\.jsxs\))\("div",{className:.\.iconGroup,onMouseEnter:.+?\(!1\)),children:\[/,
match: /(?<=(\(0,\i\.jsxs\))\("div",{className:\i\.iconGroup,onMouseEnter:.+?\(!1\)),children:\[/,
replacement: (_, createElement) =>
`,children:[${createElement}(require("platformIcons_voice").default,arguments[0]),`
}
Expand All @@ -61,7 +61,7 @@ export const patches: Patch[] = [
{
find: '"PresenceStore"',
replace: {
match: /(?<=return null!=.&&.\[.\..{1,3}\.MOBILE\])===.\..{1,3}\.ONLINE/,
match: /(?<=return null!=\i&&\i\[\i\.\i\.MOBILE\])===\i\.\i\.ONLINE/,
replacement: "!=null"
},
prerequisite: alwaysShowMobile
Expand All @@ -70,15 +70,15 @@ export const patches: Patch[] = [
find: '"getMaskId(): Unsupported type, size: "',
replace: [
{
match: /&&.===.\..{1,3}\.ONLINE/,
match: /&&\i===\i\.\i\.ONLINE/,
replacement: ""
},
{
match: /\|\|.===.\..{1,3}\.ONLINE&&/,
match: /\|\|\i===\i\.\i\.ONLINE&&/,
replacement: "&&"
},
{
match: /if\(.===.\..{1,3}\.ONLINE&&/,
match: /if\(\i===\i\.\i\.ONLINE&&/,
replacement: "if("
}
],
Expand All @@ -88,12 +88,12 @@ export const patches: Patch[] = [
find: ')("useStatusFillColor")',
replace: [
{
match: /(?<=\.STATUS_TYPING;)(switch.+?default:)(if\(.\)return .\.ZP\.Masks\.STATUS_ONLINE_MOBILE;)/,
match: /(?<=\.STATUS_TYPING;)(switch.+?default:)(if\(\i\)return \i\.\i\.Masks\.STATUS_ONLINE_MOBILE;)/,
replacement: (_, body, mobileCheck) => `${mobileCheck}${body}`
},
{
// why is this check there twice, are they stupid?
match: /.===.\..{1,3}\.ONLINE&&/g,
match: /\i===\i\.\i\.ONLINE&&/g,
replacement: ""
}
],
Expand Down
8 changes: 4 additions & 4 deletions src/platformStyles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { PlatformStyle, PlatformUtils } from "./types";

export const patches: Patch[] = [
{
find: /switch\((.{1,2})\){case (.{1,2})\.PlatformTypes\.WINDOWS:/g,
find: ".window.USE_OSX_NATIVE_TRAFFIC_LIGHTS",
replace: {
match: /switch\((.{1,2})\){case (.{1,2})\.PlatformTypes\.WINDOWS:/,
match: /switch\((\i)\){case (\i)\.PlatformTypes\.WINDOWS:/,
replacement: (_, platformType, platformUtils) =>
`${platformType}=require("platformStyles_helper").platformBorders(${platformUtils});switch(${platformType}){case ${platformUtils}.PlatformTypes.WINDOWS:`
}
},
{
find: '" platform-overlay"',
replace: {
match: /(.)="platform-web"\),/,
match: /(\i)="platform-web"\),/,
replacement: (orig, className) =>
`${orig}(${className}=require("platformStyles_helper").platformClass()??${className}),`
}
},
{
find: ".ensureIsInPosition=",
replace: {
match: /(.{1,2})=.{1,2}!==(.{1,2})\.PlatformTypes\.WEB&&this\.inPopout\?22:0;/,
match: /(\i)=\i!==(\i)\.PlatformTypes\.WEB&&this\.inPopout\?22:0;/,
replacement: (_, pipOffset, platformUtil) =>
`${pipOffset}=require("platformStyles_helper").platformBorders(${platformUtil})!==${platformUtil}.PlatformTypes.WEB&&this.inPopout?22:0;`
}
Expand Down
15 changes: 8 additions & 7 deletions src/unminifyReactErrors/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Patch, ExtensionWebpackModule } from "@moonlight-mod/types";

// @ts-expect-error
import ERROR_CODES from "./codes.json";

const ERROR_MATCH =
/function (.)\(.\){for\(var .="https:\/\/reactjs\.org\/docs\/error-decoder\.html\?invariant="\+.,.=1;.<arguments\.length;.\+\+\).\+="&args\[\]="\+encodeURIComponent\(arguments\[.\]\);return"Minified React error #"\+.\+"; visit "\+.\+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings\."}/;
/function (\i)\(\i\){for\(var \i="https:\/\/reactjs\.org\/docs\/error-decoder\.html\?invariant="\+\i,\i=1;\i<arguments\.length;\i\+\+\)\i\+="&args\[\]="\+encodeURIComponent\(arguments\[\i\]\);return"Minified React error #"\+\i\+"; visit "\+\i\+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings\."}/;

export const patches: Patch[] = [
{
Expand All @@ -22,11 +21,13 @@ export const webpackModules: Record<string, ExtensionWebpackModule> = {
run: function (module, exports, require) {
module.exports = function unminify(code: string, ...args: any[]) {
let index = 0;
return ERROR_CODES[code].replace(/%s/g, () => {
const arg = args[index];
index++;
return arg;
});
return (
(ERROR_CODES as Record<string, string>)[code]?.replace(/%s/g, () => {
const arg = args[index];
index++;
return arg;
}) ?? `<unknown code ${code}, React probably updated>`
);
};
}
}
Expand Down

0 comments on commit 0c013eb

Please sign in to comment.