forked from klaudiosinani/ao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnav.js
121 lines (96 loc) · 2.65 KB
/
nav.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
const {webFrame} = require('electron');
const {is} = require('./util');
const settings = require('./settings');
class Nav {
constructor() {
this._defaultZoomFactor = 1.0;
this._listItem = '.listItem';
this._lists = '.lists';
this._lowerZoomLimit = 0.7;
this._myDayList = '.todayToolbar-item';
this._selectedListItem = '.active';
this._upperZoomLimit = 1.3;
this._zoomStep = 0.05;
}
get _lastIdx() {
return this._getLists().length - 1;
}
_clickClass(x) {
document.querySelector(`.${x}`).click();
}
_clickId(x) {
document.getElementById(x).click();
}
_currentIdx() {
let currentIdx = 0;
const lists = this._getLists();
const selectedList = this.select(this._selectedListItem);
for (let i = 0; i < lists.length; i++) {
if (lists[i] === selectedList) {
currentIdx += i;
}
}
return currentIdx;
}
_getLists() {
const myDayList = this.select(this._myDayList);
return [myDayList, ...document.querySelector(this._lists).querySelectorAll(this._listItem)];
}
click(x) {
document.querySelector(x).click();
}
jumpToList(event) {
const comboKey = is.darwin ? event.metaKey : event.ctrlKey;
if (!comboKey) {
return null;
}
const n = parseInt(event.key, 10);
if (n > 0 && n < 10) {
this.selectList(n - 1);
}
}
sideBar() {
document.documentElement.classList.toggle('side-bar-hidden', settings.get('sideBarHidden'));
}
nextList() {
const idx = this._currentIdx();
this.selectList(idx === this._lastIdx ? 0 : idx + 1);
}
previousList() {
const idx = this._currentIdx();
return this.selectList(idx === 0 ? this._lastIdx : idx - 1);
}
select(x) {
return document.querySelector(x);
}
selectList(idx) {
if (idx >= 0 && idx <= this._lastIdx) {
const lists = this._getLists();
const {id, className} = lists[idx];
return id ? this._clickId(id) : this._clickClass(className);
}
}
zoomIn() {
const zoomFactor = webFrame.getZoomFactor() + this._zoomStep;
if (zoomFactor < this._upperZoomLimit) {
webFrame.setZoomFactor(zoomFactor);
settings.set('zoomFactor', zoomFactor);
}
}
zoomReset() {
webFrame.setZoomFactor(this._defaultZoomFactor);
settings.set('zoomFactor', this._defaultZoomFactor);
}
zoomRestore() {
webFrame.setZoomFactor(settings.get('zoomFactor'));
}
zoomOut() {
const zoomFactor = webFrame.getZoomFactor() - this._zoomStep;
if (zoomFactor > this._lowerZoomLimit) {
webFrame.setZoomFactor(zoomFactor);
settings.set('zoomFactor', zoomFactor);
}
}
}
module.exports = new Nav();