知乎去首页加载广告【油猴教程专用,可能出现bug,不更新】
// ==UserScript==
// @name 知乎去首页加载广告【油猴教程专用,可能出现bug,不更新】
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.zhihu.com/
// @icon https://www.google.com/s2/favicons?domain=zhihu.com
// @grant none
// @run-at document-start
// ==/UserScript==
let oldfetch=fetch
function newobj(){}
function fuckfetch(...bianliang){
return new Promise(function(resolve, reject){
oldfetch(...bianliang).then(function(response) {
let handler = {
get: function(target, prop, receiver) {
if(typeof Reflect.get(target,prop)==='function')
{
if(Reflect.get(target,prop+'proxy')===undefined)
{
target[prop+'proxy']=(...funcargs)=> {
let result=target[prop].call(target,...funcargs)
if(bianliang.length!==0&&bianliang[0].indexOf('/api/v3/feed/topstory/recommend')!==-1&&prop==='json'){
return new Promise(function(resolve, reject){
result.then(
function(data){
console.log('bianliang',bianliang)
let retobj={
data:[],
fresh_text:data.fresh_text,
paging:data.paging,
}
for(let index=0;index<data.data.length;index++){
if(data.data[index].ad===undefined){
retobj.data.push(data.data[index])
}
}
resolve(retobj)
}
)
})
}
console.log('fetchfunction',prop,funcargs,result)
return result
}
}
return Reflect.get(target,prop+'proxy')
}
return Reflect.get(target, prop);
},
set(target, prop, value) {
return Reflect.set(target, prop, value);
},
};
let proxy=new Proxy(response, handler)
resolve(proxy)
})
});
}
window.fetch=fuckfetch
window.onload=function(){
document.querySelector('.Pc-feedAd-container').parentElement.style.display='none'
}