我试图对微博热搜的响应进行修改
请求地址为: /ajax/side/hotSearch
response:
`const { method, payload, originalResponse } = arguments[0];
const blocked_category = ['艺人','综艺']
const blocked_star_name = ['王一博']
const startMatched = function(star_name){
if(Object.keys(star_name).length>0){
for (let i = star_name.length - 1; i >= 0; i--) {
if (blocked_star_name.includes(star_name[i])){
return true
}
}
}
return false;
}
const categoryMatched = function(category){
const array = category.split(',')
for (let i = 0; i < array.length; i++) {
if (blocked_category.includes(array[i])){
return true;
}
}
return false;
}
const json = JSON.parse(originalResponse)
json.data.realtime = json.data.realtime.filter(item=>!categoryMatched(item.category)).filter(item=>!startMatched(item.star_name))
return JSON.stringify(json)
`
修改完之后第一次能正常运行,但是刷新之后控制台的蓝色框里展开会看到报错:
Uncaught SyntaxError: Unexpected token 'c', "const { me"... is not valid JSON at JSON.parse (<anonymous>) at modifyResponse (index.js:98:91) at xhr.onreadystatechange (index.js:111:13)