// ==UserScript== // @name 低端影视 // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.1.4 // @description 低端影视添加观看历史记录功能,最多保存10条,可一键清空,过滤片头10秒广告(因广告屏蔽造成的10秒广告)! // @author 张仨 // @match https://ddrk.me/* // @run-at document-end // @grant unsafeWindow // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // ==/UserScript== let newNode = document.createElement("li"), // 创建元素节点 referenceNode = document.querySelector("#menu-item-1431"), // 匹配子节点 parentNode = referenceNode.parentNode; // 匹配父节点 parentNode.insertBefore(newNode, referenceNode); // 插入到指定父节点的子节点前面 newNode.id = "my_menu-item"; // 赋予ID // 写入节点内容 newNode.innerHTML = ` 观看记录 清空记录 ` let video_records = GM_getValue("video_records") || [], // 观看记录数组 video = document.querySelector("video"), // 匹配视频 dropdown_menu = document.querySelector('#my_dropdown-menu'), // 匹配下拉菜单 clear_record = document.querySelector(".clear_record"); // 匹配清空按钮 if (video) { // 判断是否是视频播放页 video.addEventListener("play", () => { // 监听视频播放状态 if (video.duration >= 10 && video.duration <= 12) { // 过滤片头10秒广告(因广告屏蔽造成的10秒广告) video.currentTime = video.duration } let url = window.location.href, // 获取视频播放页链接 video_title = document.querySelector(".post-title").innerText, // 获取视频名 title = (video_title.indexOf("(") != -1) ? video_title.substring(0, video_title.indexOf("(")) : video_title; // 去除视频名括号内信息 if (JSON.stringify(video_records).indexOf(url) == -1) { // 匹配记录数组中的视频播放页链接 video_records.length >= 10 && video_records.shift(); // 超过10条记录则删除第一条 video_records.push({ title: `${title}`, url: `${url}` }); // 添加对象到数组中 GM_setValue("video_records", video_records); // 存储观看记录 }; }); }; // 切换集数后自动刷新网页(不刷新无法记录集数与跳过片头广告,不想要此功能可以把54-62行删除) if (history.replaceState != null) { let _replaceState = history.replaceState; history.replaceState = function () { setTimeout(() => { location.reload(); }, 300) return _replaceState.apply(history, arguments); }; }; // 遍历对象数组创建观看记录菜单 video_records.forEach(e => { let list = document.createElement("li"); list.innerHTML = `${e.title}`; // title属性为鼠标悬停工具提示文本 dropdown_menu.appendChild(list); }); // 清空记录 clear_record.onclick = () => { GM_deleteValue("video_records"); }; // CSS样式 GM_addStyle(` #my_menu-item { cursor:pointer; } #my_dropdown-menu { cursor:pointer; min-height: 360px; margin-top: -2px; } #my_menu-item:hover #my_dropdown-menu { display: block; } #my_dropdown-menu>li>a { font-size: .8125rem; padding: .5em 1.42857142857143em; font-weight: 700; font-family: Lato,Helvetica,Arial,sans-serif; } .clear_record { position: absolute; bottom: 0; height: 30px; width: 100%; text-align: center; line-height: 30px; } .clear_record:hover { background-color: rgba(199, 212, 214, 0.712); } `)