Vencord/src/plugins/noMosaic/index.ts

81 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-10-12 22:10:36 -04:00
/*
* Vencord, a Discord client mod
* Copyright (c) 2023 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
2023-10-12 22:10:36 -04:00
import { disableStyle, enableStyle } from "@api/Styles";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
2023-10-12 22:10:36 -04:00
import style from "./styles.css?managed";
const settings = definePluginSettings({
inlineVideo: {
description: "Play videos without carousel modal",
type: OptionType.BOOLEAN,
default: true,
restartNeeded: true
},
mediaLayoutType: {
description: "Choose media layout type",
type: OptionType.SELECT,
restartNeeded: true,
options: [
{ label: "STATIC, render loading image but image isn't resposive, no problem unless discord window width is too small", value: "STATIC", default: true },
{ label: "RESPONSIVE, image is responsive but not render loading image, cause messages shift when loaded", value: "RESPONSIVE" },
]
}
});
2023-10-12 22:10:36 -04:00
export default definePlugin({
name: "NoMosaic",
authors: [Devs.AutumnVN],
description: "Removes Discord new image mosaic",
tags: ["image", "mosaic", "media"],
settings,
2023-10-25 08:47:08 -04:00
patches: [
{
find: ".oneByTwoLayoutThreeGrid",
replacement: [{
2023-10-12 22:10:36 -04:00
match: /mediaLayoutType:\i\.\i\.MOSAIC/,
replace: "mediaLayoutType:$self.mediaLayoutType()",
2023-10-12 22:10:36 -04:00
},
{
match: /null!==\(\i=\i\.get\(\i\)\)&&void 0!==\i\?\i:"INVALID"/,
replace: '"INVALID"',
}]
},
{
find: "renderAttachments(",
predicate: () => settings.store.inlineVideo,
replacement: {
match: /url:(\i)\.url\}\);return /,
replace: "$&$1.content_type?.startsWith('image/')&&"
}
2023-10-25 08:47:08 -04:00
},
{
find: "Messages.REMOVE_ATTACHMENT_TOOLTIP_TEXT",
replacement: {
match: /\i===\i\.\i\.MOSAIC/,
replace: "true"
}
}
],
mediaLayoutType() {
return settings.store.mediaLayoutType;
},
2023-10-12 22:10:36 -04:00
start() {
enableStyle(style);
},
2023-10-12 22:10:36 -04:00
stop() {
disableStyle(style);
}
});