Greasy Fork

Greasy Fork is available in English.

哔哩哔哩播放记录

try to take over the world!

目前为 2020-10-28 提交的版本。查看 最新版本

// ==UserScript==
// @name         哔哩哔哩播放记录
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  try to take over the world!
// @author       You
// @match        https://www.bilibili.com/*
// @grant        none
// ==/UserScript==

(function() {
window.onload = function () {
    setTimeout(() => {
        /*
    保存哔哩哔哩上次播放的集数
    */
        //如果没有localStorage.getItem('b_localStorage') 就新建一个存在本地中
        if (localStorage.getItem('b_localStorage') == null) {
            localStorage.setItem('b_localStorage', JSON.stringify({
                'author': 'ly'
            }));
        }
        //获取页面的url
        var b_url = window.location.href.split('?')[0];
        //获取当前页面视频的id
        var b_id = window.location.href.split('video/')[1].split('?')[0];
        //获取当前页面的集数
        var b_p = window.location.href.split('p=')[1];
        //获取当前页面第b_p集所对用的标题
        var bb_p;
        if (JSON.parse(localStorage.getItem('b_localStorage'))[b_id] == null) {
            bb_p = 1;
        } else {
            bb_p = parseInt(JSON.parse(localStorage.getItem('b_localStorage'))[b_id]);
        }
        var list_box = document.querySelector('.list-box').querySelectorAll('li');
        var b_title = list_box[parseInt(bb_p) - 1].querySelector('a').title;
        console.log(list_box);
        ////////////////////////////////////////////////
        //显示浏览记录
        var ly_div = document.createElement('div');
        var ly_div_son1 = document.createElement('div');
        var ly_div_son2 = document.createElement('div');
        ly_div_son2.className = 'ly_son';
        ly_div_son2.innerHTML = b_title;
        ly_div_son1.style.cssText = 'display:inline-block;width:565px;height:100%;';
        ly_div.className = 'aaabbb';
        ly_div.style.cssText = 'position:absolute;top:152px;left:50%;height:46px;color:#222;border-radius:2px;box-sizing:border-box;font-size:16px;line-height:46px;font-weight:400; z-index: 999;';
        var ly_span = document.createElement('span');
        ly_span.style.cssText = 'float:right;background:#f4f4f4;';
        ly_span.innerHTML = '您上次访问第';
        var ly_a = document.createElement('a');
        ly_a.style.cssText = 'float:right;color:#00a1d6;background:#f4f4f4;';
        if (JSON.parse(localStorage.getItem('b_localStorage'))[b_id] == null) {
            ly_a.innerHTML = 1 + '集';
            ly_a.href = b_url + '?p=' + 1;
        } else {
            ly_a.innerHTML = JSON.parse(localStorage.getItem('b_localStorage'))[b_id] + '集';
            ly_a.href = b_url + '?p=' + JSON.parse(localStorage.getItem('b_localStorage'))[b_id];
        }
        ly_div.appendChild(ly_div_son2);
        ly_div.appendChild(ly_div_son1);
        ly_div.appendChild(ly_a);
        ly_div.appendChild(ly_span);
        document.body.append(ly_div)
        ly_div.onmouseover = function () {
            this.children[0].style.display = 'block';
        }
        ly_div.onmouseleave = function () {
            this.children[0].style.display = 'none';
        }
        console.log(document.querySelector(".aaabbb"));
        //鼠标移动到显示该集的内容
        var styles = document.createElement('style')
        styles.id = 'id';
        styles.type = 'text/css';
        if (styles.styleSheet) {
            styles.styleSheet.cssText = '.ly_son{display:none;position:absolute;top:60px;right:0;padding:0 8px;height:40px;border-radius:8px;color:#fff;font-size:18px;line-height:40px;background-color:#00b5e5}.ly_son::after{position:absolute;top:-20px;right:11px;content:" ";width:0;height:0;border-top:10px solid transparent;border-bottom:10px solid #00b5e5;border-left:10px solid transparent;border-right:10px solid transparent}'//IE
        } else {
            styles.appendChild(document.createTextNode('.ly_son{display:none;position:absolute;top:60px;right:0;padding:0 8px;height:40px;border-radius:8px;color:#fff;font-size:18px;line-height:40px;background-color:#00b5e5}.ly_son::after{position:absolute;top:-20px;right:11px;content:" ";width:0;height:0;border-top:10px solid transparent;border-bottom:10px solid #00b5e5;border-left:10px solid transparent;border-right:10px solid transparent}'))//for FF
        }

        document.getElementsByTagName('head')[0].appendChild(styles)
        //保存浏览数据
        var b_localStorage = JSON.parse(localStorage.getItem('b_localStorage'));
        //获取到localStorage.getItem('b_localStorage');值对象中所对应的id和p
        b_localStorage[b_id] = b_p;
        localStorage.setItem('b_localStorage', JSON.stringify(b_localStorage));
        var b_p_2 = b_p;
        setInterval(() => {
            //获取当前页面的集数
            b_p = window.location.href.split('p=')[1];
            if (b_p_2 != b_p) {
                if (JSON.parse(localStorage.getItem('b_localStorage'))[b_id] == null) {
                    ly_a.innerHTML = 1 + '集';
                    ly_a.href = b_url + '?p=' + 1;
                    ly_div_son2.innerHTML = list_box[0].querySelector('a').title;
                } else {
                    ly_a.innerHTML = JSON.parse(localStorage.getItem('b_localStorage'))[b_id] + '集';
                    ly_a.href = b_url + '?p=' + JSON.parse(localStorage.getItem('b_localStorage'))[b_id];
                    if (JSON.parse(localStorage.getItem('b_localStorage'))[b_id] == null) {
                        ly_div_son2.innerHTML = list_box[0].querySelector('a').title;
                    } else {
                        ly_div_son2.innerHTML = list_box[JSON.parse(localStorage.getItem('b_localStorage'))[b_id] - 1].querySelector('a').title;
                    }

                }
                b_localStorage[b_id] = b_p;
                localStorage.setItem('b_localStorage', JSON.stringify(b_localStorage));
                b_p_2 = b_p;
            }
        }, 2500);


    }, 5000);

}
})();