This repository was archived by the owner on May 10, 2026. It is now read-only.
forked from martinkadlec0/Smart-RSS
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathapp.js
More file actions
146 lines (128 loc) · 5.53 KB
/
Copy pathapp.js
File metadata and controls
146 lines (128 loc) · 5.53 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/**
* @module App
*/
define([
'controllers/comm',
'layouts/Layout', 'collections/Actions', 'layouts/FeedsLayout', 'layouts/ArticlesLayout',
'layouts/ContentLayout', 'staticdb/shortcuts', 'preps/extendNative'
],
function (comm, Layout, Actions, FeedsLayout, ArticlesLayout, ContentLayout, shortcuts) {
document.documentElement.style.fontSize = bg.settings.get('uiFontSize') + '%';
document.addEventListener('contextmenu', function (event) {
if (!event.target.matches('#content header, #content header *')) {
event.preventDefault();
}
});
chrome.runtime.onMessage.addListener(onMessage);
function changeUserStyle() {
document.querySelector('[data-custom-style]').innerHTML = bg.settings.get('userStyle');
}
function onMessage(message) {
if (message.action === 'changeUserStyle') {
changeUserStyle();
}
}
const app = window.app = new (Layout.extend({
el: 'body',
fixURL: function (url) {
return url.search(/[a-z]+:\/\//) === -1 ? 'https://' + url : url;
},
events: {
'mousedown': 'handleMouseDown'
},
initialize: function () {
this.actions = new Actions();
window.addEventListener('blur', (event) => {
this.hideContextMenus();
if (event.target instanceof window.Window) {
comm.trigger('stop-blur');
}
});
bg.settings.on('change:layout', this.handleLayoutChange, this);
bg.sources.on('clear-events', this.handleClearEvents, this);
},
handleClearEvents: function (id) {
if (window == null || id === tabID) {
bg.settings.off('change:layout', this.handleLayoutChange, this);
bg.sources.off('clear-events', this.handleClearEvents, this);
}
},
handleLayoutChange: function () {
if (bg.settings.get('layout') === 'vertical') {
this.layoutToVertical();
this.articles.enableResizing(bg.settings.get('layout'), bg.settings.get('posC'));
} else {
this.layoutToHorizontal();
this.articles.enableResizing(bg.settings.get('layout'), bg.settings.get('posB'));
}
},
layoutToVertical: function () {
document.querySelector('#second-pane').classList.add('vertical');
},
layoutToHorizontal: function () {
document.querySelector('#second-pane').classList.remove('vertical');
},
handleMouseDown: function (event) {
if (!event.target.matches('.context-menu, .context-menu *')) {
this.hideContextMenus();
}
},
hideContextMenus: function () {
comm.trigger('hide-overlays', {blur: true});
},
start: function () {
this.attach('feeds', new FeedsLayout);
this.attach('articles', new ArticlesLayout);
this.attach('content', new ContentLayout);
this.feeds.enableResizing('horizontal', bg.settings.get('posA'));
this.articles.enableResizing('horizontal', bg.settings.get('posB'));
changeUserStyle();
this.handleLayoutChange();
},
handleKeyDown: function (event) {
const activeElement = document.activeElement;
const hotkeys = bg.settings.get('hotkeys');
if (activeElement && (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA')) {
return;
}
let shortcut = '';
if (event.ctrlKey) {
shortcut += 'ctrl+';
}
if (event.altKey) {
shortcut += 'alt+';
}
if (event.shiftKey) {
shortcut += 'shift+';
}
if (event.keyCode > 46 && event.keyCode < 91) {
shortcut += String.fromCharCode(event.keyCode).toLowerCase();
} else if (event.keyCode in shortcuts.keys) {
shortcut += shortcuts.keys[event.keyCode];
} else {
return;
}
const activeRegion = activeElement.closest('.region');
const activeRegionName = activeRegion ? activeRegion.id : null;
if (activeRegionName && activeRegionName in hotkeys) {
if (shortcut in hotkeys[activeRegionName]) {
app.actions.execute(hotkeys[activeRegionName][shortcut], event);
event.preventDefault();
return false;
}
}
if (shortcut in hotkeys.global) {
app.actions.execute(hotkeys.global[shortcut], event);
event.preventDefault();
return false;
}
}
}));
if (typeof browser !== 'undefined') {
window.addEventListener('unload', () => {
bg.reloadExt();
});
}
document.addEventListener('keydown', app.handleKeyDown);
return app;
});