diff --git a/src/components/Fav.js b/src/components/Fav.js index 66e30d36..4e9c21b0 100644 --- a/src/components/Fav.js +++ b/src/components/Fav.js @@ -27,6 +27,7 @@ import KeyboardArrowRight from '@mui/icons-material/KeyboardArrowRight'; import LastPageIcon from '@mui/icons-material/LastPage'; import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles'; import { zhCN } from '@mui/material/locale'; +import Tooltip from '@mui/material/Tooltip'; const theme = createTheme( { @@ -260,9 +261,15 @@ export const Fav = (function ({ FavList, onSongIndexChange, onAddOneFromFav, han whiteSpace: 'nowrap' }} style={{ paddingLeft: '40px', paddingRight: '8px' }}> - onAddOneFromFav([song])} /> - handleAddToFavClick(currentFavList.info.id, song)} /> - handleDelteFromSearchList(currentFavList.info.id, index)} /> + + onAddOneFromFav([song])} /> + + + handleAddToFavClick(currentFavList.info.id, song)} /> + + + handleDelteFromSearchList(currentFavList.info.id, index)} /> + )} diff --git a/src/components/FavList.js b/src/components/FavList.js index 77a54903..62bb688e 100644 --- a/src/components/FavList.js +++ b/src/components/FavList.js @@ -14,6 +14,9 @@ import PlaylistPlayIcon from '@mui/icons-material/PlaylistPlay'; import AlbumOutlinedIcon from '@mui/icons-material/AlbumOutlined'; import AddBoxOutlinedIcon from '@mui/icons-material/AddBoxOutlined'; import DeleteOutlineOutlinedIcon from '@mui/icons-material/DeleteOutlineOutlined'; +import DownloadIcon from '@mui/icons-material/Download'; +import FileUploadIcon from '@mui/icons-material/FileUpload'; +import Tooltip from '@mui/material/Tooltip'; import Typography from '@mui/material/Typography'; import Divider from '@mui/material/Divider'; import AddIcon from '@mui/icons-material/Add'; @@ -166,6 +169,14 @@ export const FavList = memo(function ({ onSongListChange, onPlayOneFromFav, onPl onAddFavToList(FavList.songList) } + const exportFav = () => { + StorageManager.exportStorage() + } + + const importFav = () => { + StorageManager.importStorage() + } + return ( @@ -182,7 +193,15 @@ export const FavList = memo(function ({ onSongListChange, onPlayOneFromFav, onPl - setOpenNewDialog(true)} /> + + setOpenNewDialog(true)} /> + + + exportFav()} /> + + + importFav()} /> + - handlePlayListClick(searchList)} /> - handleAddPlayListClick(searchList)} /> - handleAddToFavClick(searchList.info.id)} /> - + + handlePlayListClick(searchList)} /> + + + handleAddPlayListClick(searchList)} /> + + + handleAddToFavClick(searchList.info.id)} /> + + + + @@ -229,10 +256,18 @@ export const FavList = memo(function ({ onSongListChange, onPlayOneFromFav, onPl - handlePlayListClick(v)} /> - handleAddPlayListClick(v)} /> - handleAddToFavClick(v.info.id)} /> - handleDeleteFavClick(v.info.id)} /> + + handlePlayListClick(v)} /> + + + handleAddPlayListClick(v)} /> + + + handleAddToFavClick(v.info.id)} /> + + + handleDeleteFavClick(v.info.id)} /> + diff --git a/src/objects/Storage.js b/src/objects/Storage.js index 3fd26384..398d2971 100644 --- a/src/objects/Storage.js +++ b/src/objects/Storage.js @@ -161,6 +161,48 @@ export default class StorageManager { async setPlayerSetting(newSettings) { chrome.storage.local.set({ [PLAYER_SETTINGS]: newSettings }) } + + async exportStorage() { + chrome.storage.local.get(null, function (items) { // null implies all items + // Convert object to a string. + let result = JSON.stringify(items); + const bytes = new TextEncoder().encode(result); + const blob = new Blob([bytes], { + type: "application/json;charset=utf-8" + }); + + const href = window.URL.createObjectURL(blob); + const link = document.createElement('a') + link.href = href + link.download = 'AzusaPlayerStorage_' + new Date().toISOString().slice(0, 10) + '.json' + document.body.appendChild(link) + link.click() + }); + } + + async importStorage() { + const _self = this + const upload = document.createElement('input') + upload.type = "file" + document.body.appendChild(upload) + + upload.addEventListener("change", handleFiles, false); + function handleFiles() { + let fileReader = new FileReader(); + fileReader.onload = function () { + let parsedJSON = JSON.parse(fileReader.result); + console.log(parsedJSON); + // your code to consume the json + chrome.storage.local.clear(() => { + chrome.storage.local.set(parsedJSON, () => { + _self.initFavLists() + }) + }) + } + fileReader.readAsText(this.files[0]); + } + upload.click() + } } diff --git a/src/utils/Data.js b/src/utils/Data.js index 4e31ca8d..10b9b99e 100644 --- a/src/utils/Data.js +++ b/src/utils/Data.js @@ -183,6 +183,6 @@ export const searchLyric = async (searchMID, setLyric) => { return } const data = json.lyric - console.log(data) + // console.log(data) setLyric(data) } \ No newline at end of file