This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
136 lines (109 loc) · 4.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const { React, getModule, contextMenu: { openContextMenu, closeContextMenu } } = require('powercord/webpack');
const { inject, uninject } = require('powercord/injector');
const { findInReactTree } = require('powercord/util');
const { Menu } = require('powercord/components');
const { Plugin } = require('powercord/entities');
const { clipboard } = require('electron');
module.exports = class PictureLink extends Plugin {
startPlugin() {
this.loadStylesheet('style.css');
this.promises = { cancelled: false };
this.patchAvatars();
this.patchBanners();
}
async patchAvatars() {
const ProfileModalHeader = await this.findLazy(m => m.default?.displayName == 'UserProfileModalHeader');
const classes = getModule(['relationshipButtons'], false);
if (this.promises.cancelled) return;
inject('pfp-link-profile', ProfileModalHeader, 'default', (args, res) => {
const avatar = findInReactTree(res, m => m?.props?.className == classes.avatar);
const image = args[0].user?.getAvatarURL?.(false, 4096, true)?.replace('.webp', '.png');
if (avatar && image) {
avatar.props.onClick = () => open(image);
avatar.props.onContextMenu = (e) => openContextMenu(e, () =>
React.createElement(Menu.Menu, { onClose: closeContextMenu },
React.createElement(Menu.MenuItem, {
label: 'Copy Avatar URL',
id: 'copy-avatar-url',
action: () => clipboard.writeText(image)
})
)
);
}
return res;
});
ProfileModalHeader.default.displayName = 'UserProfileModalHeader';
}
async patchBanners() {
const Banner = getModule(m => m.default?.displayName == 'UserBanner', false);
const Banners = getModule(['getUserBannerURL'], false);
inject('pfp-link-banner', Banner, 'default', (args, res) => {
const handler = findInReactTree(res.props.children, p => p?.onClick);
const image = args[0].displayProfile?.getBannerURL({
size: 4096,
canAnimate: true
})?.replace('.webp', '.png');
if (!handler?.children && image) {
res.props.onClick = () => {
open(image);
};
res.props.onContextMenu = (e) => openContextMenu(e, () =>
React.createElement(Menu.Menu, { onClose: closeContextMenu },
React.createElement(Menu.MenuItem, {
label: 'Copy Banner URL',
id: 'copy-banner-url',
action: () => clipboard.writeText(image)
})
)
);
res.props.className = [res.props.className, 'picture-link'].join(' ');
}
return res;
});
Banner.default.displayName = 'UserBanner';
}
findLazy(filter) {
const direct = getModule(filter, false);
if (direct) return direct;
let oldPush = window.webpackChunkdiscord_app.push;
return new Promise(resolve => {
const onPush = (chunk) => {
const [, modules] = chunk;
for (const id in modules) {
const orig = modules[id];
modules[id] = (module, exports, require) => {
Reflect.apply(orig, null, [module, exports, require]);
try {
const res = filter(exports);
if (res) {
window.webpackChunkdiscord_app.push = oldPush;
resolve(exports);
}
} catch { }
};
Object.assign(modules[id], orig, {
toString: () => orig.toString()
});
}
return Reflect.apply(oldPush, window.webpackChunkdiscord_app, [chunk]);
};
Object.defineProperty(window.webpackChunkdiscord_app, 'push', {
configurable: true,
set: (push) => {
oldPush = push;
Object.defineProperty(window.webpackChunkdiscord_app, 'push', {
value: onPush,
configurable: true,
writable: true
});
},
get: () => onPush
});
});
}
pluginWillUnload() {
this.promises.cancelled = false;
uninject('pfp-link-banner');
uninject('pfp-link-profile');
}
};