ストレージ権限を削除
This commit is contained in:
parent
2a94e1124c
commit
0e1869aacf
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "YT Playlist Features",
|
"name": "YT Playlist Features",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Extract and work with YouTube playlist data",
|
"description": "Extract and work with YouTube playlist data",
|
||||||
"permissions": ["storage"],
|
"permissions": [],
|
||||||
"background": {
|
"background": {
|
||||||
"service_worker": "background/service-worker.js"
|
"service_worker": "background/service-worker.js"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "YT Playlist Features",
|
"name": "YT Playlist Features",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "Extract and work with YouTube playlist data",
|
"description": "Extract and work with YouTube playlist data",
|
||||||
"permissions": ["storage"],
|
"permissions": [],
|
||||||
"background": {
|
"background": {
|
||||||
"scripts": ["background/service-worker.js"]
|
"scripts": ["background/service-worker.js"]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import browser from "webextension-polyfill";
|
import browser from "webextension-polyfill";
|
||||||
import type { Message } from "../shared/messages";
|
import type { Message } from "../shared/messages";
|
||||||
import { savePlaylist, getPlaylist } from "../shared/storage";
|
|
||||||
|
|
||||||
const LOG_PREFIX = "[yt-playlist-features:bg]";
|
const LOG_PREFIX = "[yt-playlist-features:bg]";
|
||||||
|
|
||||||
|
|
@ -11,15 +10,8 @@ browser.runtime.onMessage.addListener(
|
||||||
if (msg.type === "PLAYLIST_EXTRACTED") {
|
if (msg.type === "PLAYLIST_EXTRACTED") {
|
||||||
console.log(
|
console.log(
|
||||||
LOG_PREFIX,
|
LOG_PREFIX,
|
||||||
`Saving playlist: "${msg.data.metadata.title}" (${msg.data.extractedCount} videos)`,
|
`Playlist: "${msg.data.metadata.title}" (${msg.data.extractedCount} videos)`,
|
||||||
);
|
);
|
||||||
await savePlaylist(msg.data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.type === "GET_PLAYLIST") {
|
|
||||||
const data = await getPlaylist(msg.playlistId);
|
|
||||||
return { type: "PLAYLIST_RESPONSE", data } satisfies Message;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
import type { PlaylistData } from "../types/playlist";
|
import type { PlaylistData } from "../types/playlist";
|
||||||
|
|
||||||
export type Message =
|
export type Message = { type: "PLAYLIST_EXTRACTED"; data: PlaylistData };
|
||||||
| { type: "PLAYLIST_EXTRACTED"; data: PlaylistData }
|
|
||||||
| { type: "GET_PLAYLIST"; playlistId: string }
|
|
||||||
| { type: "PLAYLIST_RESPONSE"; data: PlaylistData | null };
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
import browser from "webextension-polyfill";
|
|
||||||
import type { PlaylistData } from "../types/playlist";
|
|
||||||
|
|
||||||
const STORAGE_PREFIX = "playlist:";
|
|
||||||
|
|
||||||
export async function savePlaylist(data: PlaylistData): Promise<void> {
|
|
||||||
await browser.storage.local.set({
|
|
||||||
[STORAGE_PREFIX + data.metadata.playlistId]: data,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getPlaylist(
|
|
||||||
playlistId: string,
|
|
||||||
): Promise<PlaylistData | null> {
|
|
||||||
const key = STORAGE_PREFIX + playlistId;
|
|
||||||
const result = await browser.storage.local.get(key);
|
|
||||||
return (result[key] as PlaylistData) ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getAllPlaylists(): Promise<PlaylistData[]> {
|
|
||||||
const all = await browser.storage.local.get(null);
|
|
||||||
return Object.entries(all)
|
|
||||||
.filter(([key]) => key.startsWith(STORAGE_PREFIX))
|
|
||||||
.map(([, value]) => value as PlaylistData);
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user