• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NikkelM / Random-YouTube-Video / 6913636532

18 Nov 2023 11:27AM UTC coverage: 94.189% (-0.1%) from 94.292%
6913636532

push

github

web-flow
Added animations to custom API key input (#235)

263 of 299 branches covered (0.0%)

16 of 20 new or added lines in 2 files covered. (80.0%)

1248 of 1325 relevant lines covered (94.19%)

516.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.65
/src/chromeStorage.js
1
// Contains all interaction with the Chrome storage API
1✔
2
import { configSyncDefaults } from "./config.js";
1✔
3

1✔
4
// ----- Storage -----
1✔
5
// Validate the config in sync storage
1✔
6
await validateConfigSync();
1✔
7

1✔
8
export let configSync = await chrome.storage.sync.get();
1✔
9

1✔
10
/* c8 ignore start - This event listener cannot really be tested */
1✔
11
// Whenever someone changes a value in sync storage, we need to be notified to update the global configSync object
1✔
12
chrome.storage.onChanged.addListener(async function (changes, namespace) {
1✔
13
        // We only care about changes to the sync storage
1✔
14
        if (namespace !== "sync") {
1✔
15
                return;
1✔
16
        }
1✔
17
        for (const [key, value] of Object.entries(changes)) {
1✔
18
                configSync[key] = value.newValue;
1✔
19
        }
1✔
20
});
1✔
21
/* c8 ignore stop */
1✔
22

1✔
23
// This function also exists in background.js
1✔
24
export async function setSyncStorageValue(key, value) {
1✔
25
        configSync[key] = value;
2,259✔
26

2,259✔
27
        await chrome.storage.sync.set({ [key]: value });
2,259✔
28
}
2,259✔
29

1✔
30
export async function removeSyncStorageValue(key) {
1✔
NEW
31
        delete configSync[key];
×
NEW
32

×
NEW
33
        await chrome.storage.sync.remove(key);
×
NEW
34
}
×
35

1✔
36
// Returns the number of requests the user can still make to the Youtube API today
1✔
37
export async function getUserQuotaRemainingToday() {
1✔
38
        // The quota gets reset at midnight
918✔
39
        if (configSync.userQuotaResetTime < Date.now()) {
918✔
40
                await setSyncStorageValue("userQuotaRemainingToday", 200);
2✔
41
                await setSyncStorageValue("userQuotaResetTime", new Date(new Date().setHours(24, 0, 0, 0)).getTime());
2✔
42
        }
2✔
43
        return configSync.userQuotaRemainingToday;
918✔
44
}
918✔
45

1✔
46
// -- Private --
1✔
47
async function validateConfigSync() {
1✔
48
        const configSyncValues = await chrome.storage.sync.get();
1✔
49

1✔
50
        // Set default values for config values that do not exist in sync storage
1✔
51
        for (const [key, value] of Object.entries(configSyncDefaults)) {
1✔
52
                if (configSyncValues[key] === undefined) {
19✔
53
                        await chrome.storage.sync.set({ [key]: value });
19✔
54
                }
19✔
55
        }
19✔
56

1✔
57
        // Remove old config values from sync storage
1✔
58
        for (const [key, value] of Object.entries(configSyncValues)) {
1✔
59
                if (configSyncDefaults[key] === undefined) {
20✔
60
                        await chrome.storage.sync.remove(key);
1✔
61
                }
1✔
62
        }
20✔
63
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc