-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
27 lines (24 loc) · 1.17 KB
/
content.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
// Function to set CSS variables on ytd-rich-grid-renderer
function setGridItemsPerRow(gridItemsValue, slimItemsValue) {
const gridRenderer = document.querySelector('ytd-rich-grid-renderer');
if (gridRenderer) {
gridRenderer.style.setProperty('--ytd-rich-grid-items-per-row', gridItemsValue);
gridRenderer.style.setProperty('--ytd-rich-grid-slim-items-per-row', slimItemsValue);
}
}
// Retrieve and apply the stored values on DOM content loaded
function applyStoredGridItemsPerRow() {
chrome.storage.sync.get(['gridItemsPerRow', 'slimItemsPerRow'], (data) => {
setGridItemsPerRow(data.gridItemsPerRow || 6, data.slimItemsPerRow || 5); // Default to 6 if not set
});
}
document.addEventListener('DOMContentLoaded', applyStoredGridItemsPerRow);
document.addEventListener('yt-navigate-finish', applyStoredGridItemsPerRow);
// Listen for changes from the popup and apply them
chrome.storage.onChanged.addListener((changes, namespace) => {
if (namespace === 'sync') {
chrome.storage.sync.get(['gridItemsPerRow', 'slimItemsPerRow'], (data) => {
setGridItemsPerRow(data.gridItemsPerRow || 6, data.slimItemsPerRow || 5);
});
}
});