Hanime Resumer and Hider

Store video timespamps locally when pausing, hide videos that have a timespamp

Verze ze dne 12. 11. 2022. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Hanime Resumer and Hider
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Store video timespamps locally when pausing, hide videos that have a timespamp
// @author       You
// @match        https://player.hanime.tv/*
// @match        https://hanime.tv/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=hanime.tv
// @grant        GM.setValue
// @grant        GM.getValue
// @license MIT
// ==/UserScript==

function l(...args){
    console.log('[Resumer]', ...args)
}

function key(){
    let key = document.URL.split(',')[2]
    return key
}

if(document.URL.includes('player.hanime')){
    //Resumer
    let once = false
    //Observe changes to the DOM
    const observer = new MutationObserver(async (mutationsList, observer) => {
        if(!once){
            //Get video element
            let video = document.querySelector('video')
            if(video){
                //Resume
                let previousTime = await GM.getValue(key())
                if(previousTime){
                    video.currentTime = previousTime
                    l(`resuming ${key()} ${video.currentTime}`)
                }
                //Save currentTime
                video.onpause = () => {
                    l(`saving ${key()} ${video.currentTime}`)
                    GM.setValue(key(), video.currentTime)
                }
                once = true
            }
        }
    })
    observer.observe(document, {subtree:true, childList:true, attributes:true})
}else{
    async function hide(a){
        let name = a.href.replace('https://hanime.tv/videos/hentai/', '')
        name = name.split('?')[0] //to remove ?playlist
        let previousTime = await GM.getValue(name)
        if(previousTime){
            l(name, previousTime)
            a.style.filter = 'brightness(0.1)'
        }
    }
    //Hider
    const observer = new MutationObserver((mutationsList, observer) => {
        for(let mutation of mutationsList){
            //home page
            if(mutation.target.className == 'lazy hvc__media__cover' && mutation.removedNodes.length == 0){
                hide(mutation.target.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement)
            }else if(mutation.target.className == 'lazy relative hvc2__lazy' && mutation.removedNodes.length == 0){
                hide(mutation.target.parentElement.parentElement)
            }else if(mutation.target.id == 'related_content' && mutation.removedNodes.length == 0){ //video page
                for(let a of mutation.target.querySelectorAll('.video__item a')){
                    hide(a)
                }
                break
            }
        }
        //playlists (inefficient)
        if(document.URL.includes('/playlists/')){
            for(let a of document.querySelectorAll('.video__item a')){
                hide(a)
            }
        }

    })
    observer.observe(document, {subtree:true, childList:true})
}