Skip to content

Instantly share code, notes, and snippets.

@Glaived
Last active February 21, 2020 15:28
Show Gist options
  • Save Glaived/7548c7e86a0c9ac19a169ed9572e715d to your computer and use it in GitHub Desktop.
Save Glaived/7548c7e86a0c9ac19a169ed9572e715d to your computer and use it in GitHub Desktop.
Reload Discord every 6 hours if you are AFK
//META{"name":"ReloadOnIdle","website":"https://gist.github.com/Glaived/7548c7e86a0c9ac19a169ed9572e715d","source":"https://gist.github.com/Glaived/7548c7e86a0c9ac19a169ed9572e715d/raw/e87e9e0511fd22095ef847862062c10caf489269/ReloadOnIdle.plugin.js"}*//
class ReloadOnIdle {
getName() { return "ReloadOnIdle"; }
getShortName() { return "ReloadOnIdle"; }
getDescription() { return "Reload Discord every 6 hours if you are AFK"; }
getVersion() { return "1.0.1"; }
getAuthor() { return "Glaived"; }
constructor() {}
// Called when the plugin is loaded in to memory
load() { };
onMessage() {
// Called when a message is received
};
onSwitch() {
// Called every time the user navigates such as changing channel, changing servers, changing to friends list, etc.
};
observer(e) {
// Observer for the `document`. Better documentation than I can provide is found here: <https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver>
};
start() {
this.time;
this.events = [
'mousedown',
'mousemove',
'keypress',
'scroll',
'touchstart',
'click'
];
this.events.forEach(name => {
document.addEventListener(name, this.resetTimer, true);
});
console.info(`%c[ReloadOnIdle]%c`, "color: #3a71c1; font-weight: 700;", "", "Start…");
this.resetTimer();
};
stop() {
this.events.forEach(name => {
document.removeEventListener(name, this.resetTimer, true);
});
clearTimeout(this.time);
};
resetTimer() {
this.time = setTimeout(() => {
console.info(`%c[ReloadOnIdle]%c`, "color: #3a71c1; font-weight: 700;", "", "Reloading !");
require("electron").remote.getCurrentWindow().reload();
}, 6 * 60 * 60 * 1000);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment