From 9f2486a88fa4367bd47341aa3bb7762696101fa8 Mon Sep 17 00:00:00 2001 From: "YUKI \"Piro\" Hiroshi" Date: Tue, 30 Mar 2021 11:46:51 +0900 Subject: [PATCH] Allow to use all slots to save user styles and sent tabs #2833 --- webextensions/common/common.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/webextensions/common/common.js b/webextensions/common/common.js index 2ffbd484b..9f3a91168 100644 --- a/webextensions/common/common.js +++ b/webextensions/common/common.js @@ -525,23 +525,18 @@ export function getChunkedConfig(key) { } export function setChunkedConfig(key, value) { - let largestSlot = 0; - let count = 0; - while (true) { - if (!(`${key}${count}` in configs)) { - largestSlot = count - 1; - break; - } - count++; + let slotsSize = 0; + while (`${key}${slotsSize}` in configs.$default) { + slotsSize++; } const chunks = chunkString(value, Constants.kSYNC_STORAGE_SAFE_QUOTA); - if (chunks.length >= largestSlot) + if (chunks.length > slotsSize) throw new Error('too large data'); [...chunks, - ...Array.from(new Uint8Array(largestSlot), _ => '')] - .slice(0, largestSlot) + ...Array.from(new Uint8Array(slotsSize), _ => '')] + .slice(0, slotsSize) .forEach((chunk, index) => { const slotKey = `${key}${index}`; if (slotKey in configs)