Repository navigation
Expand file tree
/
Copy pathpopup.js
More file actions
55 lines (44 loc) · 1.98 KB
/
Copy pathpopup.js
File metadata and controls
55 lines (44 loc) · 1.98 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
/*
IMPORTANT: This file is responsible for handling the user interface interactions
in the popup window of the CSS Injector extension. It initializes the UI,
handles user inputs, opens new style windows, and toggles CSS injection.
*/
import { initializeUI } from './js/uiManager.js';
import { createEditButton, createDeleteButton } from './js/styleListEntryUI.js';
document.addEventListener('DOMContentLoaded', () => {
initializeUI();
const addNewStyleButton = document.getElementById('add-new-style');
addNewStyleButton.addEventListener('click', () => {
//add current tab hostnames to the url
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
const tab = tabs[0];
const url = new URL(tab.url);
const site = url.hostname;
const newStyleWindowUrl = chrome.runtime.getURL('new-style.html') +
`?site=${encodeURIComponent(site)}`;
// Calculate left and top for centering the window
const width = 400;
const height = 600;
const left = (window.innerWidth / 2) - (width / 2);
const top = (window.innerHeight / 2) - (height / 2);
// Open the window in the center of the screen
const newWindow = window.open(newStyleWindowUrl, 'editStyleWindow', `width=${width},height=${height},left=${left},top=${top}`);
}
);
});
});
function getCurrentTab(callback) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
callback(tabs.length ? tabs[0] : null);
});
}
export function openEditStyleWindow(styleId, site, css) {
const editStyleWindowUrl = chrome.runtime.getURL('new-style.html') +
`?styleId=${encodeURIComponent(styleId)}&site=${encodeURIComponent(site)}&css=${encodeURIComponent(css)}`;
window.open(editStyleWindowUrl, 'editStyleWindow', 'width=400,height=600');
}
chrome.storage.onChanged.addListener(function(changes) {
if (changes.customCSS || changes.enabledSites) {
initializeUI();
}
});