Skip to content

Commit

Permalink
Merge pull request #1502 from gamebeaker/speedup-Library.js
Browse files Browse the repository at this point in the history
speedup Library.LibRenderSavedEpubs()
  • Loading branch information
gamebeaker authored Sep 23, 2024
2 parents f60893d + 317bbee commit 8f9b2a6
Showing 1 changed file with 21 additions and 11 deletions.
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

0 comments on commit 8f9b2a6

Please sign in to comment.