-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
26 lines (24 loc) · 1.04 KB
/
Copy pathbackground.js
File metadata and controls
26 lines (24 loc) · 1.04 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
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
func: () => {
const url = window.location.href;
if (url.endsWith('.json')) {
fetch(url)
.then(response => response.json())
.then(json => {
const jsonElement = document.createElement('pre');
jsonElement.textContent = JSON.stringify(json, null, 2);
document.body.innerHTML = '';
document.body.appendChild(jsonElement);
const theme = localStorage.getItem('selectedTheme') || 'light';
const themedJson = applyJsonTheme(json, theme);
jsonElement.innerHTML = themedJson;
})
.catch(e => console.error('Error loading JSON:', e));
} else {
console.warn('This page is not a JSON file.');
}
}
});
});