您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
api视频推荐挂载脚本
当前为
// ==UserScript== // @name MyBilibili // @namespace http://tampermonkey.net/ // @version 0.1 // @description api视频推荐挂载脚本 // @author N-cat // @match https://api.bilibili.com/x/web-interface/dynamic/region?ps=*&rid=* // @match *://www.bilibili.com/ // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant GM_xmlhttpRequest // @connect * // @license MIT // ==/UserScript== (function() { 'use strict'; const style = `<style> .add-main{ margin:auto; width:1100px; } .add-div{ width: 206px; height: 206px; display:inline-block; padding:7px 7px 7px 7px; box-sizing:content-box; } .add-a{ color: #212121; margin: 10px 0 8px; height: 40px; text-decoration: none; width: 206px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 14px; line-height: 20px; overflow: hidden; text-overflow: ellipsis; transition: color .3s; } .add-a:hover{ color: #00a1d6; transition: color .3s; } .add-img{ width: 206px; height: 116px; border-radius: 2px; } .add-author{ color:#999; text-decoration: none; transition: color .3s; font-size: 12px; } .add-author:hover{ color: #00a1d6; transition: color .3s; } .re{ position:fixed; right:80px; bottom:80px; background-color:#00a1d6; color:white; height:50px; width:50px; border-radius: 10px; font-size:15px; border:solid 3px #FA5A57; cursor:pointer; outline: none; } .top{ position:fixed; right:80px; bottom:150px; background-color:#00a1d6; color:white; height:50px; width:50px; border-radius: 10px; font-size:15px; border:solid 3px #FA5A57; cursor:pointer; outline: none; } </style>`; var ps = 50; // 页数 var rid = 1; // 类型(1:综合) // var cookie = document.cookie; // console.log(cookie) var data // api删除原数据 var pre = document.getElementsByTagName('pre') if(pre.length != 0){ pre[0].remove(); } // 主站隐藏原数据(旧) var olddiv = document.getElementsByClassName('b-wrap'); for(let i in olddiv){ if(i > 1){ olddiv[i].style.display = "none"; } } olddiv = document.getElementsByClassName('international-footer'); if(olddiv.length != 0){ olddiv[0].style.display = "none"; } // 主站隐藏原数据(新) var newdiv = document.getElementsByClassName('bili-layout'); if(newdiv.length != 0){ newdiv[0].style.display = "none"; } // 请求推荐api function getvideo(){ GM_xmlhttpRequest({ url:"https://api.bilibili.com/x/web-interface/dynamic/region?ps=" + ps + "&rid=" + rid, method:"get", // cookie:cookie, onload:function(xhr){ data = JSON.parse(xhr.response) console.log(data.data.archives) // 添加元素 let div = document.createElement("div"); div.classList.add('add-main'); for(let i of data.data.archives){ //div.innerHTML += '<div class="add-div">' //div.innerHTML += '<a href="https://www.bilibili.com/video/' + i.bvid + '" target="_blank"><img class="add-img" src="' + i.pic + '" /></a><br>' //div.innerHTML += '<a class="add-a" href="https://www.bilibili.com/video/' + i.bvid + '" target="_blank">' + i.title + '</a></div>'; // 视频总div let id = document.createElement("div"); div.appendChild(id); id.classList.add('add-div'); // 图片链接 let a1 = document.createElement("a"); id.appendChild(a1); a1.innerHTML = '<img class="add-img" src="' + i.pic + '" />' a1.setAttribute('href',"https://www.bilibili.com/video/" + i.bvid ); a1.setAttribute('target',"_blank"); // 文字链接 let a2 = document.createElement("a"); id.appendChild(a2); a2.classList.add('add-a'); a2.setAttribute('href',"https://www.bilibili.com/video/" + i.bvid ); a2.setAttribute('target',"_blank"); // 文字 let txt = document.createTextNode(i.title); a2.appendChild(txt); // 作者 let a3 = document.createElement("a"); id.appendChild(a3); a3.classList.add('add-author'); a3.setAttribute('href',"https://space.bilibili.com/" + i.owner.mid ); a3.setAttribute('target',"_blank"); let author = document.createTextNode(i.owner.name); a3.appendChild(author); } div.innerHTML += style; // 设置添加位置 var header = document.getElementsByClassName('bili-layout'); if(header.length != 0){ header[0].parentNode.insertBefore(div, header[0]); // 新 } else { document.body.append(div); // 旧 } } }) } getvideo(); // 刷新按钮 var btn = document.createElement("input"); btn.setAttribute("type", "button"); btn.setAttribute("value", "刷新"); btn.classList.add('re'); document.body.append(btn); btn.onclick = function(){ document.body.scrollTop = document.documentElement.scrollTop = 0; var dd = document.getElementsByClassName('add-main'); for(let j of dd){ j.style.display = "none"; } getvideo(); // 请求后刷新也会请求一次,这里待优化 } // 顶部按钮 var top = document.createElement("input"); top.setAttribute("type", "button"); top.setAttribute("value", "顶部"); top.classList.add('top'); document.body.append(top); top.onclick = function(){ document.body.scrollTop = document.documentElement.scrollTop = 0; } // 下拉刷新 let timeout = null; window.onscroll = function() { const scrollH = document.documentElement.scrollHeight;// 文档的完整高度 const scrollT = document.documentElement.scrollTop || document.body.scrollTop; // 当前滚动条的垂直偏移 const screenH = window.screen.height; // 屏幕可视高度 if ((scrollH - scrollT - screenH) < 2000) { // 只是一个相对值,可以让页面再接近底面的时候就开始请求 timeout && clearTimeout(timeout); // 判断timeout是否在执行 timeout = setTimeout(() => { console.log('下拉刷新') getvideo(); }, 3000); // api在3s内请求返回重复内容 } }; })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址