2023-10-13 09:10:36 +07:00
|
|
|
/*
|
|
|
|
* Vencord, a Discord client mod
|
|
|
|
* Copyright (c) 2023 Vendicated and contributors
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
2023-11-03 07:57:39 +07:00
|
|
|
import { definePluginSettings } from "@api/Settings";
|
2023-10-13 09:10:36 +07:00
|
|
|
import { disableStyle, enableStyle } from "@api/Styles";
|
|
|
|
import { Devs } from "@utils/constants";
|
2023-11-03 07:57:39 +07:00
|
|
|
import definePlugin, { OptionType } from "@utils/types";
|
2023-10-13 09:10:36 +07:00
|
|
|
|
|
|
|
import style from "./styles.css?managed";
|
|
|
|
|
2024-04-09 09:04:09 +07:00
|
|
|
const MAX_WIDTH = 550;
|
|
|
|
const MAX_HEIGHT = 350;
|
|
|
|
|
2023-11-03 07:57:39 +07:00
|
|
|
const settings = definePluginSettings({
|
|
|
|
inlineVideo: {
|
|
|
|
description: "Play videos without carousel modal",
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
default: true,
|
|
|
|
restartNeeded: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-10-13 09:10:36 +07:00
|
|
|
export default definePlugin({
|
|
|
|
name: "NoMosaic",
|
|
|
|
authors: [Devs.AutumnVN],
|
|
|
|
description: "Removes Discord new image mosaic",
|
|
|
|
tags: ["image", "mosaic", "media"],
|
2023-11-03 07:57:39 +07:00
|
|
|
|
|
|
|
settings,
|
|
|
|
|
2023-10-25 19:47:08 +07:00
|
|
|
patches: [
|
|
|
|
{
|
|
|
|
find: ".oneByTwoLayoutThreeGrid",
|
|
|
|
replacement: [{
|
2023-10-13 09:10:36 +07:00
|
|
|
match: /mediaLayoutType:\i\.\i\.MOSAIC/,
|
2024-04-09 09:04:09 +07:00
|
|
|
replace: "mediaLayoutType:'RESPONSIVE'",
|
2023-10-13 09:10:36 +07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
match: /null!==\(\i=\i\.get\(\i\)\)&&void 0!==\i\?\i:"INVALID"/,
|
|
|
|
replace: '"INVALID"',
|
2023-11-03 07:57:39 +07:00
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
find: "renderAttachments(",
|
|
|
|
predicate: () => settings.store.inlineVideo,
|
|
|
|
replacement: {
|
|
|
|
match: /url:(\i)\.url\}\);return /,
|
|
|
|
replace: "$&$1.content_type?.startsWith('image/')&&"
|
|
|
|
}
|
2023-10-25 19:47:08 +07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
find: "Messages.REMOVE_ATTACHMENT_TOOLTIP_TEXT",
|
2024-04-09 09:04:09 +07:00
|
|
|
replacement: [{
|
2023-10-25 19:47:08 +07:00
|
|
|
match: /\i===\i\.\i\.MOSAIC/,
|
|
|
|
replace: "true"
|
2024-04-09 09:04:09 +07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
match: /\i!==\i\.\i\.MOSAIC/,
|
|
|
|
replace: "false"
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
find: ".messageAttachment,",
|
|
|
|
replacement: {
|
|
|
|
match: /\{width:\i,height:\i\}=(\i).*?(?=className:\i\(\)\(\i\.messageAttachment,)/,
|
|
|
|
replace: "$&style:$self.style($1),"
|
2023-10-25 19:47:08 +07:00
|
|
|
}
|
2023-11-03 07:57:39 +07:00
|
|
|
}
|
|
|
|
],
|
|
|
|
|
2024-04-09 09:04:09 +07:00
|
|
|
style({ width, height }) {
|
|
|
|
if (!width || !height) return {};
|
|
|
|
|
|
|
|
if (width > MAX_WIDTH || height > MAX_HEIGHT) {
|
|
|
|
if (width / height > MAX_WIDTH / MAX_HEIGHT) {
|
|
|
|
height = Math.ceil(MAX_WIDTH / (width / height));
|
|
|
|
width = MAX_WIDTH;
|
|
|
|
} else {
|
|
|
|
width = Math.ceil(MAX_HEIGHT * (width / height));
|
|
|
|
height = MAX_HEIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
maxWidth: width,
|
|
|
|
width: "100%",
|
|
|
|
aspectRatio: `${width} / ${height}`
|
|
|
|
};
|
|
|
|
|
2023-11-03 07:57:39 +07:00
|
|
|
},
|
|
|
|
|
2023-10-13 09:10:36 +07:00
|
|
|
start() {
|
|
|
|
enableStyle(style);
|
|
|
|
},
|
2023-11-03 07:57:39 +07:00
|
|
|
|
2023-10-13 09:10:36 +07:00
|
|
|
stop() {
|
|
|
|
disableStyle(style);
|
|
|
|
}
|
|
|
|
});
|