-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
87 lines (76 loc) · 2.48 KB
/
preload.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
const { contextBridge, webFrame } = require('electron')
// Hardcoded API key
const FINNHUB_API_KEY = 'cue3j69r01qiosq1h4bgcue3j69r01qiosq1h4c0';
// Function to remove sidebar
const removeSidebar = () => {
console.log('Starting sidebar removal process');
// Insert CSS to hide content during load
webFrame.insertCSS(`
html.loading * {
visibility: hidden !important;
}
html.loading::before {
visibility: visible !important;
content: '';
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: var(--background-dark, #fff);
}
`);
// Add loading class immediately
document.documentElement.classList.add('loading');
// Function to remove sidebar and show content
const removeAndShow = () => {
try {
const sidebar = document.querySelector('div.hidden.md\\:block');
if (sidebar) {
console.log('Found and removing sidebar');
sidebar.remove();
}
// Remove loading class to show content
document.documentElement.classList.remove('loading');
console.log('Content made visible');
} catch (error) {
console.error('Error in removeAndShow:', error);
}
};
// Execute as soon as DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', removeAndShow);
} else {
removeAndShow();
}
// Backup removal attempts
setTimeout(removeAndShow, 0);
setTimeout(removeAndShow, 100);
};
// Wait for document to be available
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', removeSidebar);
} else {
removeSidebar();
}
// Expose necessary APIs
contextBridge.exposeInMainWorld('env', {
FINNHUB_API_KEY: FINNHUB_API_KEY
})
contextBridge.exposeInMainWorld('finnhub', {
getQuote: async (symbol) => {
try {
const response = await fetch(
`https://finnhub.io/api/v1/quote?symbol=${symbol}&token=${FINNHUB_API_KEY}`
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching quote:', error);
throw error;
}
}
})