This repository has been archived by the owner on Aug 28, 2022. It is now read-only.
/
index.js
49 lines (44 loc) · 1.85 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
const { Plugin } = require('powercord/entities');
const { getModule, FluxDispatcher } = require('powercord/webpack');
const settings = require('./Components/Settings');
const { getChannel } = getModule(['getChannel', 'getDMFromUserId'], false)
function handleChannel({ channelId }) {
const channel = getChannel(channelId);
const blockedChannels = this.settings.get('Blocked')?.filter(obj => obj.id === channel.id || obj.id === channel.recipients[0]);
const blurChannels = this.settings.get('Blur')?.filter(obj => obj.id === channel.id || obj.id === channel.recipients[0]);
if (blockedChannels?.[0]?.id?.includes(channelId) || blockedChannels?.[0]?.id?.includes(channel.recipients[0])) return;
else if (
channel.nsfw ||
(this.settings.get('blurInDm') && channel.type === 1) ||
(this.settings.get('blurInGroup') && channel.type === 3) ||
blurChannels?.[0]?.id?.includes(channel.id) ||
blurChannels?.[0]?.id?.includes(channel.recipients[0])
)
blurChannel();
else document.body.classList.remove('blur');
}
function blurChannel() {
console.log('nsfw channel!')
const blur = this.settings.get('blurEffect', 10);
const timing = this.settings.get('blurTiming', 1);
document.body.style.setProperty('--blur-effect', `blur(${blur}px)`);
document.body.style.setProperty('--blur-timing', `${timing}s`);
document.body.classList.add('blur');
}
module.exports = class BlurNSFW extends Plugin {
startPlugin() {
this.loadStylesheet('style.css');
powercord.api.settings.registerSettings(this.entityID, {
category: this.entityID,
label: 'Blur NSFW',
render: settings,
});
handleChannel = handleChannel.bind(this);
blurChannel = blurChannel.bind(this);
FluxDispatcher.subscribe('CHANNEL_SELECT', handleChannel);
}
pluginWillUnload() {
powercord.api.settings.unregisterSettings(this.entityID);
FluxDispatcher.unsubscribe('CHANNEL_SELECT', handleChannel);
}
};