save
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
});
|
||||
}
|
||||
|
||||
loadIDBKeyval(); // 确保 idb-keyval 已经加载
|
||||
|
||||
// 2️⃣ 读取 IndexedDB
|
||||
async function readAllStorageForMigration(db) {
|
||||
// localStorage 数据
|
||||
|
||||
@@ -327,10 +327,10 @@
|
||||
|
||||
<script>
|
||||
// 旧域名地址
|
||||
const OLD_ORIGIN = 'https://2study.top';
|
||||
var OLD_ORIGIN = 'https://2study.top';
|
||||
|
||||
// 需要迁移的 IndexedDB key
|
||||
const IDB_KEYS = [
|
||||
var IDB_KEYS = [
|
||||
'type-words-app-version',
|
||||
'typing-word-dict',
|
||||
'typing-word-setting',
|
||||
@@ -338,7 +338,7 @@
|
||||
];
|
||||
|
||||
// 需要迁移的 localStorage key
|
||||
const LS_KEYS = [
|
||||
var LS_KEYS = [
|
||||
'PracticeSaveWord',
|
||||
'PracticeSaveArticle'
|
||||
];
|
||||
@@ -348,7 +348,7 @@
|
||||
return new Promise((resolve) => {
|
||||
if (window.idbKeyval) return resolve(window.idbKeyval);
|
||||
|
||||
const script = document.createElement('script');
|
||||
var script = document.createElement('script');
|
||||
script.src = 'https://cdn.jsdelivr.net/npm/idb-keyval@6.2.2/dist/umd.js';
|
||||
script.onload = () => resolve(window.idbKeyval);
|
||||
document.head.appendChild(script);
|
||||
@@ -367,8 +367,8 @@
|
||||
// 安全接收旧域名返回的数据
|
||||
function onMessage(event) {
|
||||
if (event.data?.type !== 'MIGRATION_RESULT') return;
|
||||
|
||||
const payload = event.data.payload;
|
||||
console.log('payload',payload)
|
||||
|
||||
// 写入 localStorage
|
||||
LS_KEYS.forEach(key => {
|
||||
@@ -396,7 +396,9 @@
|
||||
|
||||
// 等 iframe 加载完成再发请求
|
||||
iframe.onload = () => {
|
||||
iframe.contentWindow.postMessage({type: 'REQUEST_MIGRATION_DATA'}, OLD_ORIGIN);
|
||||
setTimeout(()=>{
|
||||
iframe.contentWindow.postMessage({type: 'REQUEST_MIGRATION_DATA'}, 'https://2study.top');
|
||||
},3000)
|
||||
};
|
||||
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
27
src/App.vue
27
src/App.vue
@@ -77,6 +77,33 @@ async function init() {
|
||||
|
||||
onMounted(init)
|
||||
|
||||
onMounted(()=>{
|
||||
return
|
||||
// const iframe = document.createElement('iframe');
|
||||
// iframe.style.display = 'none';
|
||||
// iframe.src = `https://2study.top/migrate.html`;
|
||||
// function onMessage(event) {
|
||||
// if (event.data?.type !== 'MIGRATION_RESULT') return;
|
||||
//
|
||||
// const payload = event.data.payload;
|
||||
// console.log('payload',payload)
|
||||
// }
|
||||
//
|
||||
// window.addEventListener('message', onMessage);
|
||||
// iframe.onload = () => {
|
||||
// setTimeout(()=>{
|
||||
// iframe.contentWindow.postMessage({type: 'REQUEST_MIGRATION_DATA'}, 'https://2study.top');
|
||||
// },3000)
|
||||
// };
|
||||
// document.body.appendChild(iframe);
|
||||
//
|
||||
// (async () => {
|
||||
// const db = await loadIDBKeyval(); // 确保 idb-keyval 已经加载
|
||||
// const data = await readAllStorageForMigration(db);
|
||||
// console.log('data',data)
|
||||
// })()
|
||||
})
|
||||
|
||||
// let transitionName = $ref('go')
|
||||
// const route = useRoute()
|
||||
// watch(() => route.path, (to, from) => {
|
||||
|
||||
Reference in New Issue
Block a user