mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
Remove unused code in background.js
This commit is contained in:
+2
-84
@@ -1,61 +1,5 @@
|
|||||||
/*global chrome*/
|
/*global chrome*/
|
||||||
|
|
||||||
export const openDB = () => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const request = indexedDB.open('MyDatabase', 1);
|
|
||||||
|
|
||||||
request.onupgradeneeded = (event) => {
|
|
||||||
const db = event.target.result;
|
|
||||||
db.createObjectStore('backgrounds', { keyPath: 'id' });
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onsuccess = () => {
|
|
||||||
resolve(request.result);
|
|
||||||
};
|
|
||||||
|
|
||||||
request.onerror = (event) => {
|
|
||||||
reject('Error opening database: ' + event.target.errorCode);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const writeData = async (type, data) => {
|
|
||||||
const db = await openDB();
|
|
||||||
|
|
||||||
const tx = db.transaction('backgrounds', 'readwrite');
|
|
||||||
const store = tx.objectStore('backgrounds');
|
|
||||||
const request = await store.put({ id: 'customBackground', type, data });
|
|
||||||
|
|
||||||
return request.result;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const readData = () => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
openDB()
|
|
||||||
.then(db => {
|
|
||||||
const tx = db.transaction('backgrounds', 'readonly');
|
|
||||||
const store = tx.objectStore('backgrounds');
|
|
||||||
|
|
||||||
// Retrieve the custom background
|
|
||||||
const getRequest = store.get('customBackground');
|
|
||||||
|
|
||||||
// Attach success and error event handlers
|
|
||||||
getRequest.onsuccess = function(event) {
|
|
||||||
resolve(event.target.result);
|
|
||||||
};
|
|
||||||
|
|
||||||
getRequest.onerror = function(event) {
|
|
||||||
console.error('An error occurred:', event);
|
|
||||||
reject(event);
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('An error occurred:', error);
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function ReloadSEQTAPages() {
|
function ReloadSEQTAPages() {
|
||||||
chrome.tabs.query({}, function (tabs) {
|
chrome.tabs.query({}, function (tabs) {
|
||||||
for (let tab of tabs) {
|
for (let tab of tabs) {
|
||||||
@@ -120,13 +64,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
case 'sendNews':
|
case 'sendNews':
|
||||||
GetNews(sendResponse);
|
GetNews(sendResponse);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
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');
|
||||||
}
|
}
|
||||||
@@ -304,24 +242,4 @@ chrome.runtime.onInstalled.addListener(function (event) {
|
|||||||
chrome.storage.local.set({ justupdated: true });
|
chrome.storage.local.set({ justupdated: true });
|
||||||
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
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user