Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speedup Library.LibRenderSavedEpubs() #1502

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions plugin/js/Library.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Library {
document.getElementById("includeInReadingListCheckbox").click();
}
chrome.storage.local.get(null, async function(items) {
let CurrentLibStoryURLKeys = await Library.LibGetAllLibStorageKeys("LibStoryURL");
let CurrentLibStoryURLKeys = await Library.LibGetAllLibStorageKeys("LibStoryURL", Object.keys(items));
let LibidURL = -1;
for (let i = 0; i < CurrentLibStoryURLKeys.length; i++) {
if (items[CurrentLibStoryURLKeys[i]] == document.getElementById("startingUrlInput").value) {
Expand Down Expand Up @@ -242,7 +242,7 @@ class Library {

static Libdeleteall(){
chrome.storage.local.get(null, async function(items) {
let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub");
let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub", Object.keys(items));
let storyurls = [];
for (let i = 0; i < CurrentLibKeys.length; i++) {
CurrentLibKeys[i] = CurrentLibKeys[i].replace("LibEpub","");
Expand All @@ -263,7 +263,7 @@ class Library {
static LibRenderSavedEpubs(){
chrome.storage.local.get(null, async function(items) {
let ShowAdvancedOptions = document.getElementById("LibShowAdvancedOptionsCheckbox").checked;
let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub");
let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub", Object.keys(items));
let LibRenderResult = document.getElementById("LibRenderResult");
let LibRenderString = "";
let LibTemplateDeleteEpub = document.getElementById("LibTemplateDeleteEpub").innerHTML;
Expand Down Expand Up @@ -682,7 +682,7 @@ class Library {

static Libexportall(){
chrome.storage.local.get(null, async function(items) {
let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub");
let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub", Object.keys(items));
var retobj = {};
retobj.Library = [];
for (let i = 0; i < CurrentLibKeys.length; i++) {
Expand Down Expand Up @@ -762,18 +762,28 @@ class Library {
document.getElementById("LibURLWarning"+obj.dataset.libepubid).innerHTML = "<tr><td></td></tr>";
}

static async LibGetAllLibStorageKeys(Substring){
static async LibGetAllLibStorageKeys(Substring, AllStorageKeysList){
return new Promise((resolve) => {
chrome.storage.local.get(null, function(items){
let AllStorageKeys = Object.keys(items);
if (AllStorageKeysList == undefined) {
chrome.storage.local.get(null, function(items){
let AllStorageKeys = Object.keys(items);
let AllLibStorageKeys = [];
for (let i = 0, end = AllStorageKeys.length; i < end; i++) {
if(AllStorageKeys[i].includes(Substring)){
AllLibStorageKeys.push(AllStorageKeys[i]);
}
}
resolve(AllLibStorageKeys);
});
} else {
let AllLibStorageKeys = [];
for (let i = 0, end = AllStorageKeys.length; i < end; i++) {
if(AllStorageKeys[i].includes(Substring)){
AllLibStorageKeys.push(AllStorageKeys[i]);
for (let i = 0, end = AllStorageKeysList.length; i < end; i++) {
if(AllStorageKeysList[i].includes(Substring)){
AllLibStorageKeys.push(AllStorageKeysList[i]);
}
}
resolve(AllLibStorageKeys);
});
}
});
}

Expand Down
Loading