AnimeHay

Tự động lưu và khôi phục lịch sử xem phim khi AnimeHay đổi tên miền mới

当前为 2024-05-04 提交的版本,查看 最新版本

// ==UserScript==
// @name        AnimeHay
// @namespace   https://gf.qytechs.cn/en/scripts/492147-animehay
// @match       *://animehay.*/*
// @grant       GM_getValue
// @grant       GM_setValue
// @version     1.2
// @author      HVD
// @icon        https://animehay.blog/themes/img/favicon.ico
// @description Tự động lưu và khôi phục lịch sử xem phim khi AnimeHay đổi tên miền mới
// @license MIT
// ==/UserScript==

let prevDomain = GM_getValue('prevDomain', '');

if (prevDomain == window.location.host) {
    if (window.location.pathname.includes('/xem-phim/')) {
        let watchedAnime = GM_getValue('watchedAnime', '[]');
        watchedAnime = JSON.parse(watchedAnime);

        let newAnime = window.location.pathname.replace(/\/xem-phim\/|\.html/g, '');
        watchedAnime = new Set(watchedAnime);
        watchedAnime.add(newAnime);

        GM_setValue('watchedAnime', JSON.stringify([...watchedAnime]));
        GM_setValue('dataHistory', localStorage.getItem("data_history") ?? '[]');

        console.log('[AnimeHay] Đã lưu phim!');
    }

    return;
}

GM_setValue('prevDomain', window.location.host);

if (window.location.pathname.includes('/xem-phim/')) {
    window.location.href = window.location.origin;
    return;
}

if (window.location.pathname == '/' || window.location.pathname.includes('/thong-tin-phim/')) {

    let dataHistory = GM_getValue('dataHistory', '[]');
    if (dataHistory != '[]') {
        localStorage.setItem("data_history", dataHistory);
    }

    let watchedAnime = GM_getValue('watchedAnime', '[]');
    watchedAnime = JSON.parse(watchedAnime);
    if (watchedAnime.length > 0) {
        let currentHref = window.location.href;
        for (let i = 0; i < watchedAnime.length; i++) {
            history.replaceState({}, '', window.location.origin + '/xem-phim/' + watchedAnime[i] + '.html');
        }
        history.replaceState({}, '', currentHref);
    }

    console.log('[AnimeHay] Đã khôi phục lịch sử xem phim!');
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址