mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 11:44:40 +00:00
added auto updating colour and darkmode
This commit is contained in:
+26
-20
@@ -97,10 +97,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
ReloadSEQTAPages();
|
ReloadSEQTAPages();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'IndexedDB':
|
|
||||||
HandleIntexedDB(request, sendResponse);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'currentTab':
|
case 'currentTab':
|
||||||
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
||||||
chrome.tabs.sendMessage(tabs[0].id, request, function (response) {
|
chrome.tabs.sendMessage(tabs[0].id, request, function (response) {
|
||||||
@@ -124,28 +120,18 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
case 'sendNews':
|
case 'sendNews':
|
||||||
GetNews(sendResponse);
|
GetNews(sendResponse);
|
||||||
return true;
|
return true;
|
||||||
// eslint-disable-next-line no-unreachable
|
|
||||||
break;
|
case 'downloadBackground':
|
||||||
|
downloadBackgroundFromUrl(request.url, request.filename).then((fileId) => {
|
||||||
|
sendResponse({ fileId });
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log('Unknown request type');
|
console.log('Unknown request type');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function HandleIntexedDB(request, sendResponse) {
|
|
||||||
switch (request.action) {
|
|
||||||
case 'write':
|
|
||||||
writeData(request.data.type, request.data.data);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'read':
|
|
||||||
readData().then((data) => {
|
|
||||||
sendResponse(data);
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetNews(sendResponse) {
|
function GetNews(sendResponse) {
|
||||||
// Gets the current date
|
// Gets the current date
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
@@ -318,3 +304,23 @@ chrome.runtime.onInstalled.addListener(function (event) {
|
|||||||
migrateOldStorage();
|
migrateOldStorage();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const downloadBackgroundFromUrl = async (url, filename) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(url);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`Network response was not ok: ${response.statusText}`);
|
||||||
|
}
|
||||||
|
const blob = await response.blob(); // Create a blob from the response
|
||||||
|
const fileType = blob.type.split('/')[0]; // Assuming that the file type is always the first part of the mime type
|
||||||
|
const fileId = `${Date.now()}-${filename}`; // Unique ID for the file
|
||||||
|
|
||||||
|
await writeData(fileId, fileType, blob); // Write data to your storage system
|
||||||
|
|
||||||
|
// Return the generated file ID
|
||||||
|
return fileId;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('There was an error downloading the background:', error);
|
||||||
|
throw error; // Rethrow the error so that it can be handled by the caller
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import localforage from 'localforage';
|
import localforage from 'localforage';
|
||||||
|
import { updateAllColors } from '../ui/colors/Manager.js';
|
||||||
|
|
||||||
let currentThemeClass = '';
|
let currentThemeClass = '';
|
||||||
|
|
||||||
@@ -19,11 +20,11 @@ const themeExistsInDB = async (themeName) => {
|
|||||||
return (await localforage.getItem(`css_${themeName}`)) !== null;
|
return (await localforage.getItem(`css_${themeName}`)) !== null;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch theme details (CSS, images, className) from a given URL
|
// Fetch theme details (CSS, images, className, darkMode, defaultColour) from a given URL
|
||||||
const fetchThemeJSON = async (url) => {
|
const fetchThemeJSON = async (url) => {
|
||||||
const { css, images, className } = await fetchJSON(url);
|
const { css, images, className, darkMode, defaultColour } = await fetchJSON(url);
|
||||||
const cssText = await fetchText(css);
|
const cssText = await fetchText(css);
|
||||||
return { css: cssText, images, className };
|
return { css: cssText, images, className, darkMode, defaultColour };
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save individual image to IndexedDB
|
// Save individual image to IndexedDB
|
||||||
@@ -44,9 +45,9 @@ const saveToIndexedDB = async (theme, themeName) => {
|
|||||||
await Promise.all(Object.entries(theme.images).map(([cssVar, imageUrl]) => saveImageToDB(themeName, cssVar, imageUrl)));
|
await Promise.all(Object.entries(theme.images).map(([cssVar, imageUrl]) => saveImageToDB(themeName, cssVar, imageUrl)));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply theme from storage via localForage to document
|
// Apply theme from storage via localForage to document, including dark mode and default color
|
||||||
const applyTheme = async (themeName) => {
|
const applyTheme = async (themeName) => {
|
||||||
const { css, className, images } = await localforage.getItem(`css_${themeName}`);
|
const { css, className, images, darkMode, defaultColour } = await localforage.getItem(`css_${themeName}`);
|
||||||
|
|
||||||
const newStyle = document.createElement('style');
|
const newStyle = document.createElement('style');
|
||||||
newStyle.innerHTML = css;
|
newStyle.innerHTML = css;
|
||||||
@@ -75,6 +76,9 @@ const applyTheme = async (themeName) => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update colors based on theme settings
|
||||||
|
updateAllColors(darkMode, defaultColour);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const listThemes = async () => {
|
export const listThemes = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user