Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modules['nightTimer'] = {
- moduleID: 'nightTimer',
- moduleName: 'Night Timer',
- category: 'UI',
- options: {
- startTime: {
- type: 'text',
- value: [21],
- description: "Start time for night mode (as an hour). Example, 21 for 9pm."
- },
- endTime: {
- type: 'text',
- value: [6],
- description: "End time for night mode (as an hour). Example, 6 for 6am."
- },
- checkInterval: {
- type: 'text',
- value: [5],
- description: "The interval, in minutes, to check for day/night changeover."
- }
- },
- description: 'Automatically turn night mode on/off at the specified times.',
- isEnabled: function() {
- return RESConsole.getModulePrefs(this.moduleID);
- },
- include: new Array(/https?:\/\/([a-z]+).reddit.com\/[\?]*/i),
- isMatchURL: function() {
- return RESUtils.isMatchURL(this.moduleID);
- },
- flipSwitch: function() {
- var now, theSwitch;
- var start = +(this.options.startTime.value);
- var end = +(this.options.endTime.value);
- if (document.querySelector('#lightSwitchToggle')) {
- theSwitch = document.querySelector('#lightSwitchToggle');
- now = new Date().getHours();
- if (start > end) {
- if (now >= start) {
- if (!theSwitch.className.match(/enabled/)) {
- RESUtils.click(modules['styleTweaks'].lightSwitch);
- }
- }
- if ((now < start) && (now >= end)) {
- if (theSwitch.className.match(/enabled/)) {
- RESUtils.click(modules['styleTweaks'].lightSwitch);
- }
- }
- }
- if (start < end) {
- if ((now >= start) && (now < end)) {
- if (!theSwitch.className.match(/enabled/)) {
- RESUtils.click(modules['styleTweaks'].lightSwitch);
- }
- }
- if ((now > end) || (now < start)) {
- if (theSwitch.className.match(/enabled/)) {
- RESUtils.click(modules['styleTweaks'].lightSwitch);
- }
- }
- }
- }
- },
- go: function() {
- if ((this.isEnabled()) && (this.isMatchURL())) {
- if (RESUtils.getOptions('styleTweaks').lightSwitch.value === true) {
- var delay = +((this.options.checkInterval.value) * 60000);
- modules['nightTimer'].flipSwitch();
- window.setInterval(function checkTime() {
- modules['nightTimer'].flipSwitch();
- }, delay);
- } //
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement