This commit is contained in:
Zyronon
2025-11-18 01:45:15 +08:00
parent 5fc0dbaa1d
commit 920ec425af
3 changed files with 37 additions and 6 deletions

View File

@@ -27,6 +27,8 @@
});
}
loadIDBKeyval(); // 确保 idb-keyval 已经加载
// 2⃣ 读取 IndexedDB
async function readAllStorageForMigration(db) {
// localStorage 数据

View File

@@ -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);

View File

@@ -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) => {