-
Notifications
You must be signed in to change notification settings - Fork 327
/
Copy pathbilibili_block_ugc.user.js
12 lines (12 loc) · 5.65 KB
/
bilibili_block_ugc.user.js
1
2
3
4
5
6
7
8
9
10
11
12
// ==UserScript==
// @name Bilibili UGC
// @namespace https://github.com/ipcjs
// @version 0.0.2
// @description Bilibili UGC
// @author ipcjs
// @match https://www.bilibili.com/*
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @run-at document-start
// @grant none
// ==/UserScript==
var e;!function(e){e.isDev=GM_info.script.name.includes(".dev")}(e||(e={}));let n=[];let t=null;function r(e){t??(t=window.document.getElementById("referrerMark")),t&&(t.content=e)}var o,i;!function(e){e.multiply=function(e,n){let t="";for(let r=0;r<n;r++)t+=e;return t},e.toSnakeCase=function(e){return e.replace(/[A-Z]/g,(e=>`_${e.toLowerCase()}`)).replace(/^_/,"")},e.getSearchParam=function(e,n){return(e.match(new RegExp("[?|&]"+n+"=(\\w+)"))||["",""])[1]},e.replaceTemplate=function(e,n){return e.replace(/___(\w+)___/g,((e,t)=>n[t]))},e.escapeSpecialChars=function(e){return e.replace(/\n/g,"\\\n").replace(/"/g,'\\"').replace(/\r/g,"\\\r").replace(/\t/g,"\\\t").replace(/\b/g,"\\\b").replace(/\f/g,"\\\f")}}(o||(o={})),function(e){function n(e){if("object"!=typeof e)return e;try{return JSON.stringify(e)}catch(n){return console.debug(n),`${e}`}}e.convertKeyToSnakeCase=function e(n){if(Array.isArray(n))for(const t of n)e(t);else if("object"==typeof n){const t=n;for(const n of Object.keys(t)){const r=t[n];e(r),t[o.toSnakeCase(n)]=r}}return n},e.stringify=n,e.stringifyArray=function(e){return e.map(n).join(" ")}}(i||(i={}));const a=GM_info.script.name+".msg";let s=function e(n=window,t=0){return n===window.top?t:e(n.parent,t+1)}(),c=[];0===s&&window.addEventListener("message",(e=>{if(e.data instanceof Array&&e.data[0]===a){let[,n,t]=e.data;c.push(o.multiply(" ",n)+t)}}));const l=function(e){window.top?.postMessage([a,s,e],"*")};function u(n){return e.isDev?window.console[n].bind(window.console,n+":"):function(...e){e.unshift(n+":"),window.console[n].apply(window.console,e),l(i.stringifyArray(e))}}u("log");const f=u("info");u("debug"),u("warn");const d=u("error");var p,_,w;!function(e){const n=e=>e.replace(/(\.|\?)/g,"\\$1");e.url=e=>new RegExp(`^(https?:)?//${n(e)}`),e.urlPath=e=>new RegExp(`^(https?:)?//[\\w\\-\\.]+${n(e)}`)}(p||(p={})),function(e){e.runCatching=function(e,n){let t=function(){try{return e.apply(this,arguments)}catch(t){return n?n(t):void d("Exception while run %o: %o\n%o",e,t,t.stack)}},r=Object.getOwnPropertyDescriptor(e,"name")||{value:"",writable:!1,configurable:!0};return Object.defineProperty(t,"name",r),t}}(_||(_={})),function(e){e.proxyGlobalField=function(e,n){const t=window,r=`${e}_origin`;let o;t[r]=t[e],Object.defineProperty(t,e,{configurable:!0,enumerable:!0,get:()=>(n?.onRead?.(o),o),set:e=>{o=n.onWrite(e)}}),t[r]&&(t[e]=t[r])}}(w||(w={}));const y=e.isDev?f:function(){},m=(e=window.__INITIAL_STATE__)=>!!e?.videoData?.stat&&(e.videoData.stat.like<1e3||2===e.videoData.argue_info?.argue_type),g=(e,n=1)=>{const t=e.filter((e=>e.duration>=600*n&&e.stat?.like>1e4*n||e.stat?.like>5e5*n));return y("filterRelatedVideos",e,t),t},b=(e=window.__playinfo__)=>(e.code=404,e.data={},e.message="Not Found",e);w.proxyGlobalField("__INITIAL_STATE__",{onWrite:e=>{y("STATE",e);let n=!1;return m(e)&&(n=!0,b()),((e=window.__INITIAL_STATE__)=>!!e?.videoData&&e.videoData.duration<600)(e)&&(n=!0),n&&(e.availableVideoList=[]),e}}),w.proxyGlobalField("__NEXT_DATA__",{onWrite:e=>(y("NEXT_DATA",e),e)}),w.proxyGlobalField("__playinfo__",{onWrite:e=>(y("INFO",e),e)}),w.proxyGlobalField("__pinia",{onWrite:e=>(y("PINIA",e),e?.feed?.data?.recommend?.item&&(e.feed.data.recommend.item=g(e.feed.data.recommend.item)),e?.feed?.data?.head?.recommend&&(e.feed.data.head.recommend=g(e.feed.data.head.recommend)),e)}),function({transformRequest:t,transformResponse:o}){let i=!0;window.XMLHttpRequest=new Proxy(window.XMLHttpRequest,{construct:function(a,s){i&&e.isDev&&(i=!1);let c={};const l=e=>{let n={};return e.then((e=>{c.readyState=4,c.response=e,c.responseText="string"==typeof e?e:JSON.stringify(e),c.__onreadystatechange(n)})).catch((e=>{c.__block_response=!1,null!=c.__response&&(c.readyState=4,c.response=c.__response,c.__onreadystatechange(n))}))},u=()=>(c.__block_response=!0,l);return new Proxy(new a(...s),{has:function(e,n){return"onloadend"!==n&&n in e},set:function(e,n,t,r){if("onreadystatechange"===n){c.__onreadystatechange=t;let n=t;t=function(t){if(4===e.readyState){const n=o({url:e.responseURL,response:e.response,xhr:e,container:c});if(null!=n&&("object"==typeof n&&n instanceof Promise?n.compose(u()):(c.response=n,c.responseText="string"==typeof n?n:JSON.stringify(n))),c.__block_response)return void(c.__response=e.response)}n.apply(c.responseText?r:this,arguments)}}return e[n]=t,!0},get:function(e,o,i){if(o in c)return c[o];let a=e[o];if("function"==typeof a){let i=a;a=function(){if(1===e.readyState){const e=c.__url,t=new URL(e,document.location.href).hostname;n.includes(t)?r("no-referrer"):r("no-referrer-when-downgrade")}if("open"===o)c.__method=arguments[0],c.__url=arguments[1];else if("send"===o){const e=t({url:c.__url,container:c});null!=e&&e.compose(u())}return i.apply(e,arguments)}}return a}})}})}({transformResponse:({url:e,response:n,xhr:t,container:r})=>{if(e.match(p.url("api.bilibili.com/x/player/wbi/playurl"))){if(m())return b({})}else if(e.match(p.url("api.bilibili.com/x/web-interface/wbi/view/detail"))){const e=JSON.parse(t.responseText);return e.data.Related=g(e.data.Related),e}return null},transformRequest:({url:e,container:n})=>null}),function(){const e=window.fetch;window.fetch=async function(n,t){const r=await e(n,t);if("string"==typeof n&&n.match(p.url("api.bilibili.com/x/web-interface/wbi/index/top/feed/rcmd"))){const e=await r.json();return e.data.item=g(e.data.item,.5),new Response(JSON.stringify(e))}return r}}();