Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inactivity (#203) #5395

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions lib/modules/inactivity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* @flow */

import { Module } from '../core/module';
import * as Notifications from './notifications';

export const module: Module<*> = new Module('inactivity');

module.moduleName = 'inactivityName';
module.category = 'productivityCategory';
module.description = 'inactivityDesc';
module.disabledByDefault = true;
module.options = {
timeout: {
type: 'text',
value: '300',
description: 'inactivityTimeoutDesc',
title: 'inactivityTimeoutTitle',
},
};

module.beforeLoad = () => {
inactivity();
};

function inactivity() {
let time;
window.onload = resetTimer;
/* $FlowIgnore[1] */
document.onmousemove = resetTimer;
/* $FlowIgnore[1] */
document.onkeydown = resetTimer;

function notify() {
Notifications.showNotification({
header: 'Inactivity',
message: 'You\'ve gone inactive!',
moduleID: module.moduleID,
notificationID: 'inactivity',
closeDelay: Infinity,
});

if (!document.getElementsByClassName('res-inactive').length) {
const div = document.createElement('div');
div.setAttribute('class', 'res-inactive');
div.setAttribute('style', 'background-color: rgba(0,0,0,0.5); width: auto; height: auto; top: 0; right: 0; bottom: 0; left: 0; padding: 1em; z-index: 101; position: fixed; overflow: hidden;');
div.addEventListener('click', (e: Event) => {
e.preventDefault();
/* $FlowIgnore[1] */
div.parentNode.removeChild(div);
});
document.body.appendChild(div);
}
}

function resetTimer() {
clearTimeout(time);
time = setTimeout(() => {
notify();
}, parseInt(module.options.timeout.value, 10) / 1000);
}
}
12 changes: 12 additions & 0 deletions locales/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4399,6 +4399,18 @@
"imgurImageResolutionDesc": {
"message": "Which size of imgur images should be loaded?"
},
"inactivityName": {
"message": "Inactivity"
},
"inactivityTimeoutTitle": {
"message": "Timeout"
},
"inactivityTimeoutDesc": {
"message": "The timeout for inactivity, expressed in seconds."
},
"inactivityDesc": {
"message": "Tells you when you've gone inactive after a specified amount of time."
},
"userInfoUserTag": {
"message": "User Tag:"
},
Expand Down