blob: 9cea0aacfc82ed66645bd7c21803c52d7065d0f5 [file] [log] [blame]
avm9996304def3e2016-11-27 22:53:05 +01001var HotKey = (function() {
2 return {
3 setup: function() {
4 // Default enable hot key for capture.
5 if (!localStorage.getItem('hot_key_enabled'))
6 localStorage.setItem('hot_key_enabled', true);
7
8 // Set default hot key of capture, R V H P.
9 if (!this.get('area'))
10 this.set('area', 'R');
11 if (!this.get('viewport'))
12 this.set('viewport', 'V');
13 if (!this.get('fullpage'))
14 this.set('fullpage', 'H');
15 if (!this.get('screen'))
16 this.set('screen', 'P');
17
18 var screenCaptureHotKey = this.get('screen');
19 if (this.isEnabled()) {
20 this.set('screen', '@'); // Disable hot key for screen capture.
21 }
22 },
23
24 /**
25 * Set hot key by type.
26 * @param {String} type Hot key type, must be area/viewport/fullpage/screen.
27 * @param {String} value
28 */
29 set: function(type, value) {
30 var key = type + '_capture_hot_key';
31 localStorage.setItem(key, value);
32 },
33
34 get: function(type) {
35 return localStorage.getItem(type + '_capture_hot_key');
36 },
37
38 getCharCode: function(type) {
39 return this.get(type).charCodeAt(0);
40 },
41
42 enable: function() {
43 localStorage.setItem('hot_key_enabled', true);
44 },
45
46 disable: function(bg) {
47 localStorage.setItem('hot_key_enabled', false);
48 },
49
50 isEnabled: function() {
51 return localStorage.getItem('hot_key_enabled') == 'true';
52 }
53 }
54})();