-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (44 loc) · 1.9 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
const { Plugin } = require('powercord/entities');
const { getModule } = require('powercord/webpack');
const statusStore = getModule([ 'isMobileOnline' ], false);
const userSettings = getModule([ 'PreloadedUserSettingsActionCreators' ], false);
const Settings = require('./components/settings');
let prevStatus;
let prevDStatus;
let check = false;
module.exports = class AFKonExit extends Plugin {
startPlugin() {
this.cumIntoClient = this.cumIntoClient.bind(this);
this.throttledCum = _.debounce(this.cumIntoClient, 3000);
document.addEventListener('visibilitychange', this.throttledCum, false);
powercord.api.settings.registerSettings(this.entityID, {
label: 'AFK on Exit',
category: this.entityID,
render: Settings
});
}
updateStatus(status) {
userSettings.PreloadedUserSettingsActionCreators.updateAsync("status", s => s.status.value = status, 0);
}
cumIntoClient() {
const currentUser = getModule(['getCurrentUser'], false).getCurrentUser().id;
const restoreStatus = this.settings.get('restoreStatus', true);
if (restoreStatus && document.visibilityState === 'hidden' && check === false) {
prevDStatus = statusStore.getStatus(currentUser);
console.log('[AFK-on-exit] Restoring previous Status');
}
if (document.visibilityState === 'hidden' && prevStatus !== 'hidden') {
prevStatus = 'hidden';
check = true;
this.updateStatus(this.settings.get('closingStatus', {value: 'idle'}).value)
} else if (document.visibilityState === 'visible' && prevStatus === 'hidden') {
prevStatus = 'visible';
check = false;
this.updateStatus(restoreStatus ? prevDStatus : this.settings.get('openingStatus', {value: 'online'}).value);
}
}
pluginWillUnload() {
document.removeEventListener('visibilitychange', this.throttledCum, false);
powercord.api.settings.unregisterSettings(this.entityID);
}
};