Skip to content

Commit

Permalink
Allow to use all slots to save user styles and sent tabs #2833
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Mar 30, 2021
1 parent 5df2b41 commit 9f2486a
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9f2486a

Please sign in to comment.