forked from terkelg/ramme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowser.js
133 lines (103 loc) · 3.18 KB
/
browser.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
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';
const electron = require('electron');
const config = require('./config');
const elementReady = require('element-ready');
const ipcRenderer = electron.ipcRenderer;
const $ = document.querySelector.bind(document);
var post = 0;
const selectors = {
root: '#react-root ._onabe',
loginButton: '#react-root ._fcn8k'
};
ipcRenderer.on('toggle-dark-mode', () => {
config.set('darkMode', !config.get('darkMode'));
setDarkMode();
});
ipcRenderer.on('navigate-home', () => {
const home = $('._n7q2c ._r1svv:nth-child(1) a');
if(home) {
home.click();
}
});
ipcRenderer.on('navigate-discover', () => {
const discover = $('._n7q2c ._r1svv:nth-child(2) a');
if(discover) {
discover.click();
}
});
ipcRenderer.on('navigate-notifications', () => {
const notifications = $('._n7q2c ._r1svv:nth-child(3) a');
if(notifications) {
notifications.click();
}
});
ipcRenderer.on('navigate-profile', () => {
const profile = $('._n7q2c ._r1svv:nth-child(4) a');
console.log(profile);
if(profile) {
profile.click();
}
});
ipcRenderer.on('navigate-up', () => {
if (post > 1 ){
post -= 1;
var title = $('#react-root > section > main > section > div > div:nth-child(1) > article:nth-child('+post+') > header');
var rect = title.getBoundingClientRect();
window.scrollBy(0,rect.top);
}
});
ipcRenderer.on('navigate-down', () => {
post += 1;
var title = $('#react-root > section > main > section > div > div:nth-child(1) > article:nth-child('+post+') > header');
var rect = title.getBoundingClientRect();
window.scrollBy(0,rect.top);
});
function backButton() {
const body = $('body');
const link = document.createElement('a');
const element = document.createElement('div');
link.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22.84 17.39"><polygon points="22.84 8.22 1.82 8.22 9.37 0.67 8.7 0 0 8.7 8.7 17.39 9.37 16.72 1.82 9.17 22.84 9.17 22.84 8.22"/></svg>'
element.classList.add('back-btn', 'inactive');
element.appendChild(link);
body.appendChild(element);
link.addEventListener('click', event => {
ipcRenderer.send('back');
});
ipcRenderer.on('set-button-state', (event, enabled) => {
if (enabled) {
element.classList.remove('inactive');
} else {
element.classList.add('inactive');
}
});
}
function login(elm) {
elm.addEventListener('click', (e) => {
elm.classList.toggle('goback');
process.nextTick(() => {
if (elm.classList.contains('goback')) {
elm.innerText = 'Go back';
} else {
elm.innerText = 'Log In';
}
});
});
}
function setDarkMode() {
document.documentElement.classList.toggle('dark-mode', config.get('darkMode'));
}
function init() {
backButton();
setDarkMode();
// Prevent flash of white on startup when in dark mode
// TODO: Find solution to this with pure css
if (config.get('darkMode')) {
document.documentElement.style.backgroundColor = '#192633';
}
}
document.addEventListener('DOMContentLoaded', (event) => {
// enable OS specific styles
document.documentElement.classList.add(`os-${process.platform}`);
elementReady(selectors.root).then(init);
elementReady(selectors.loginButton).then(login);
});