diff --git a/script/boxjs.json b/script/boxjs.json index 1f02c947842..75fdf96844d 100644 --- a/script/boxjs.json +++ b/script/boxjs.json @@ -11,10 +11,7 @@ "keys": ["unicom_user_cookie", "unicom_mobile", "unicom_encrypt_mobile", "city_code"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/10010", - "icons": [ - "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/10010.png", - "https://raw.githubusercontent.com/Orz-3/mini/master/Color/10010.png" - ], + "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/10010.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/10010.png"], "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/10010/unicom_signin.js" }, { @@ -35,10 +32,7 @@ ], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/bilibili", - "icons": [ - "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/bilibili.png", - "https://raw.githubusercontent.com/Orz-3/mini/master/Color/bilibili.png" - ] + "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/bilibili.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/bilibili.png"] }, { "id": "blackmatrix7.didachuxing", @@ -46,30 +40,16 @@ "keys": ["dida_cid", "dida_cookie", "dida_useragent", "dida_access_token"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/didachuxing", - "icons": [ - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/didachuxing/didachuxing.png", - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/didachuxing/didachuxing.png" - ], + "icons": ["https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/didachuxing/didachuxing.png", "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/didachuxing/didachuxing.png"], "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/didachuxing/didachuxing_plus.js" }, { "id": "blackmatrix7.didichuxing", "name": "滴滴出行", - "keys": [ - "didi_token", - "didi_city_id", - "didi_lottery_id", - "didi_my_source_id", - "didi_group_id", - "didi_finance_channel_id", - "didi_finance_activity_id" - ], + "keys": ["didi_token", "didi_city_id", "didi_lottery_id", "didi_my_source_id", "didi_group_id", "didi_finance_channel_id", "didi_finance_activity_id"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/didichuxing", - "icons": [ - "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/didi.png", - "https://raw.githubusercontent.com/Orz-3/mini/master/Color/didi.png" - ], + "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/didi.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/didi.png"], "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/didichuxing/didi_checkin.js" }, { @@ -78,10 +58,7 @@ "keys": ["dingdongmaicai_checkin_cookie", "dingdongmaicai_checkin_body"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/dingdong", - "icons": [ - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/dingdong/dingdong.png", - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/dingdong/dingdong.png" - ], + "icons": ["https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/dingdong/dingdong.png", "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/dingdong/dingdong.png"], "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/dingdong/dingdong_checkin.js" }, { @@ -90,10 +67,7 @@ "keys": ["eleme_app_cookie", "eleme_app_longitude", "eleme_app_latitude"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/eleme", - "icons": [ - "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/elem.png", - "https://raw.githubusercontent.com/Orz-3/mini/master/Color/elem.png" - ], + "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/elem.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/elem.png"], "scripts": [ { "name": "领取吃货豆", @@ -111,10 +85,7 @@ "keys": ["famijia_checkin_cookie", "famijia_device_id", "famijia_black_box"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/famijia", - "icons": [ - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/famijia/famijia.png", - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/famijia/famijia.png" - ], + "icons": ["https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/famijia/famijia.png", "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/famijia/famijia.png"], "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/famijia/famijia_checkin.js" }, { @@ -123,10 +94,7 @@ "keys": ["luka_checkin_cookie", "luka_signin_auth"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/luka", - "icons": [ - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/luka/luka.png", - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/luka/luka.png" - ], + "icons": ["https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/luka/luka.png", "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/luka/luka.png"], "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/luka/luka_signin.js" }, { @@ -135,29 +103,16 @@ "keys": ["manmanbuy_checkin_cookie", "manmanbuy_login_body", "manmanbuy_username", "manmanbuy_deviceid"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/manmanbuy", - "icons": [ - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/manmanbuy/manmanmai.png", - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/manmanbuy/manmanmai.png" - ], + "icons": ["https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/manmanbuy/manmanmai.png", "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/manmanbuy/manmanmai.png"], "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/manmanbuy/manmanbuy_checkin.js" }, { "id": "blackmatrix7.meituan", "name": "美团买菜", - "keys": [ - "meituan_mall_cookie", - "meituan_mall_t", - "meituan_mall_querystring", - "meituan_mall_uuid", - "meituan_mall_userid", - "meituan_mall_body" - ], + "keys": ["meituan_mall_cookie", "meituan_mall_t", "meituan_mall_querystring", "meituan_mall_uuid", "meituan_mall_userid", "meituan_mall_body"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/meituan", - "icons": [ - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/meituan/maicai.png", - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/meituan/maicai.png" - ], + "icons": ["https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/meituan/maicai.png", "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/meituan/maicai.png"], "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/meituan/maicai_checkin.js" }, { @@ -166,10 +121,7 @@ "keys": ["smzdm_cookie", "smzdm_session"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/smzdm", - "icons": [ - "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/smzdm.png", - "https://raw.githubusercontent.com/Orz-3/mini/master/Color/smzdm.png" - ], + "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/smzdm.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/smzdm.png"], "scripts": [ { "name": "每日自动任务", @@ -187,10 +139,7 @@ "keys": ["tieba_checkin_cookie"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/tieba", - "icons": [ - "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/tieba.png", - "https://raw.githubusercontent.com/Orz-3/mini/master/Color/tieba.png" - ], + "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/tieba.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/tieba.png"], "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/tieba/tieba_checkin.js" }, { @@ -199,10 +148,7 @@ "keys": ["wanda_checkin_cookie", "wanda_activitycode"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/wanda", - "icons": [ - "https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/wanda.png", - "https://raw.githubusercontent.com/Orz-3/mini/master/Color/wanda.png" - ], + "icons": ["https://raw.githubusercontent.com/Orz-3/mini/master/Alpha/wanda.png", "https://raw.githubusercontent.com/Orz-3/mini/master/Color/wanda.png"], "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/wanda/wanda_checkin.js" }, { @@ -211,15 +157,124 @@ "keys": ["zhihu_blocked_users", "zhihu_current_userinfo", "zhihu_keyword_block"], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/zhihu", - "icons": [ - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu.png", - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu.png" - ], + "icons": ["https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu.png", "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu.png"], + "descs_html": ["

具体功能说明查看README.md

", "

✨为Plus版本专属功能,❓为已过时或即将淘汰功能

", "

切换Lite、Plus版本,或出现异常请执行数据清理

"], "scripts": [ { "name": "知乎助手数据清理", "script": "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js" } + ], + "settings": [ + { + "id": "zhihu_settings_recommend_stream", + "name": "屏蔽推荐页流媒体", + "val": false, + "type": "boolean", + "desc": "屏蔽推荐页中的视频、直播等流媒体信息" + }, + { + "id": "zhihu_settings_moments_stream", + "name": "屏蔽关注页流媒体", + "val": false, + "type": "boolean", + "desc": "屏蔽关注页中的“最新视频”" + }, + { + "id": "zhihu_settings_hot_list", + "name": "热榜去广告", + "val": true, + "type": "boolean", + "desc": "去除知乎热榜页面的广告" + }, + { + "id": "zhihu_settings_fake_vip", + "name": "显示为盐选会员", + "val": false, + "type": "boolean", + "desc": "非会员用户显示为盐选会员,仅自己可见,无实际效果" + }, + { + "id": "zhihu_settings_preset_words", + "name": "屏蔽预置关键词广告", + "val": false, + "type": "boolean", + "desc": "屏蔽搜索页中的预置关键词广告" + }, + { + "id": "zhihu_settings_blocked_users", + "name": "黑名单屏蔽效果增强✨", + "val": true, + "type": "boolean", + "desc": "增强知乎APP黑名单用户屏蔽效果" + }, + { + "id": "zhihu_settings_blocked_keywords", + "name": "推荐页关键词过滤✨", + "val": true, + "type": "boolean", + "desc": "除普通关键词外还支持正则表达式过滤" + }, + { + "id": "zhihu_settings_sys_msg", + "name": "屏蔽官方账号推广消息✨", + "val": false, + "type": "boolean", + "desc": "屏蔽消息页内的官方账号推广消息" + }, + { + "id": "zhihu_settings_answer_tip", + "name": "付费内容/营销推广/购物推广提醒✨", + "val": true, + "type": "boolean", + "desc": "在知乎回答中提示付费或营销内容" + }, + { + "id": "zhihu_settings_remove_yanxuan", + "name": "屏蔽“盐选推荐”❓", + "val": true, + "type": "boolean", + "desc": "屏蔽推荐页中的“盐选推荐”" + }, + { + "id": "zhihu_settings_app_conf", + "name": "去除推荐页多余标签❓", + "val": false, + "type": "boolean", + "desc": "知乎7.x及以上版本无效" + }, + { + "id": "zhihu_settings_hot_search", + "name": "知乎热搜去广告❓", + "val": false, + "type": "boolean", + "desc": "知乎7.x及以上版本无效" + }, + { + "id": "magicjs_loglevel", + "name": "日志等级", + "val": "INFO", + "type": "radios", + "items": [ + { + "key": "INFO", + "label": "INFO" + }, + { + "key": "WARNING", + "label": "WARNING" + }, + { + "key": "ERROR", + "label": "ERROR" + }, + { + "key": "DEBUG", + "label": "DEBUG" + } + ], + "desc": "出现异常时请选择DEBUG提交日志" + } ] }, { @@ -266,10 +321,7 @@ ], "author": "@blackmatrix7", "repo": "https://github.com/blackmatrix7/ios_rule_script/tree/master/script/synology", - "icons": [ - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/synology/icon/synology_dark.jpg", - "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/synology/icon/synology.jpg" - ], + "icons": ["https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/synology/icon/synology_dark.jpg", "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/synology/icon/synology.jpg"], "scripts": [ { "name": "登录Synology", diff --git a/script/zhihu/README.md b/script/zhihu/README.md index ea22bbe10b8..e2a766c733e 100644 --- a/script/zhihu/README.md +++ b/script/zhihu/README.md @@ -6,74 +6,53 @@ 分为Plus和Lite两个版本,Lite只提供最纯粹的去广告功能,Plus带有一些优化阅读体验的功能。 -目前已实现(带✨的为Plus版本的功能): +目前已实现 (✨的为Plus版本的功能,❓为过时或即将删除的功能): 1. 去除知乎的启动广告 -2. 去除关注列表的广告 -3. 去除推荐列表的广告 +2. 去除关注页的广告 +3. 去除推荐页的广告 4. 去除回答列表的广告 5. 去除回答列表的圆桌 6. 去除回答页面的广告 7. 去除知乎直播红点 8. 去除知乎指南提示 9. 去除未读消息的红点 -10. 知乎网页版去广告 [#21](https://github.com/blackmatrix7/ios_rule_script/issues/21) 11. 拦截知乎内测邀请 -12. 去除预置关键字广告(beta) -13. 去除热搜内的广告(beta) -14. 去除热榜内的广告(beta) -15. 去除评论区内的广告(beta) -16. 客户端中显示自己是盐选会员(除了自娱自乐没任何用途) -17. 直接运行脚本可清理客户端内持久化的数据 -18. 付费内容文首提醒(beta)✨ -19. 推广内容文首提醒(beta)✨ +12. 去除预置关键字广告 +14. 去除热榜内的广告 +15. 去除评论区内的广告 +14. 去除关注页顶部的最新视频 +15. 客户端中显示自己是盐选会员 +16. 直接运行脚本可清理客户端内持久化的数据 +17. 部分功能支持BoxJS配置(alpha) +18. 付费内容文首提醒✨ +19. 推广内容文首提醒✨ 20. 拦截部分回答预加载以节约流量✨ -21. 去除推荐列表的付费推荐内容✨ -22. 去除官方账号的推广消息✨ -23. 去除推荐列表中黑名单用户的回答✨ -24. 去除回答列表中黑名单用户的回答✨ -25. 去除关注列表顶部的最常访问✨ -26. 精简首页顶部的标签页✨ -27. 屏蔽消息页面的知乎活动助手✨ -28. 减少推荐列表内的视频(alpha)✨ -29. 拦截知乎下发的配置,如皮肤(alpha)✨ -30. 新旧版评论区黑名单用户过滤✨ -31. 屏蔽转发的黑名单用户的想法✨ -32. 非盐选会员屏蔽关键字解锁✨ - -隐藏功能: - -隐藏功能默认不生效,需要自行根据脚本中的注释简单修改代码实现。 - -如果你不清楚如何修改代码,请不要尝试,目前不处理任何自行修改代码引起的异常。 - -1. 去除推荐列表中的视频 -2. 去除推荐列表中的直播 -3. 脚本内置的黑名单用户 -4. 调整允许设置屏蔽关键词的数量 -5. 屏蔽推荐列表中的盐选推荐内容 +21. 去除官方账号的推广消息✨ +22. 去除推荐页中黑名单用户的回答✨ +23. 去除回答列表中黑名单用户的回答✨ +24. 去除关注页顶部的最常访问✨ +25. 精简首页顶部的标签页✨ +26. 屏蔽消息页面的知乎活动助手✨ +27. 新旧版评论区黑名单用户过滤✨ +28. 屏蔽转发的黑名单用户的想法✨ +29. 推荐页屏蔽关键词解锁✨ +30. 知乎网页版去广告 [#21](https://github.com/blackmatrix7/ios_rule_script/issues/21)❓ +31. 去除热搜内的广告❓ +32. 屏蔽推荐页中的盐选推荐内容❓ +33. 拦截知乎下发的配置,如皮肤(alpha)✨❓ +34. 减少推荐页内的视频(alpha)✨❓ +35. 去除推荐页的付费推荐内容✨❓ ## 最近更新 -1. 修复偶尔获取不到用户信息导致黑名单失效的问题 -2. 修复官方营销消息在某些情况下屏蔽失效的问题 -3. 修复重新获取黑名单时没有清理历史脚本黑名单数据的问题 -4. 去除推荐列表中盐选专栏的文章 -5. 非盐选会员现在也可以使用屏蔽关键字的功能 -6. 查看其他用户信息时,如果已经是黑名单用户,会自动加入脚本黑名单 -7. 新旧版评论区黑名单用户过滤 -8. 直接运行脚本可清理客户端内持久化的数据 -9. 客户端中显示自己是盐选会员(除了自娱自乐没任何用途) -10. 修复知乎视频无法自动播放的问题 -11. 去除热搜内的广告(beta) -12. 去除热榜内的广告(beta) -13. 强化精简首页顶部标签页的功能(清理缓存后生效) -14. 拦截知乎下发的配置,如皮肤 -15. 去除评论区内的广告(beta) +1. 推荐页关键词屏蔽支持正则表达式 +2. 加入BoxJS配置开关 +3. 提高推荐页屏蔽效率 ## 版本切换 -在Lite版本和Plus版本切换时,务必手动运行一次脚本,清理持久化数据,以免影响切换效果。 +**在Lite版本和Plus版本切换时,务必手动运行一次脚本,清理持久化数据,以免影响切换效果。** 清理持久化数据后,如果使用Plus版本,请重新获取黑名单。 @@ -104,25 +83,33 @@ ## 部分功能说明 -### 屏蔽关键词解锁(alpha) +### BoxJS可选配置(alpha) -现在非会员,可以在设置-屏蔽设置-屏蔽关键词中使用此功能;**真正的盐选会员此功能不会生效。** +部分功能支持BoxJS配置,目前还在测试阶段,配置项可能有所增减。 -此功能并非真正解锁会员特权,只是借用知乎APP的操作界面,通过脚本实现的关键词屏蔽。 +如果有问题请将日志等级设置到DEBUG后提交反馈。 -与会员真正的屏蔽关键词功能相比,执行效率和匹配范围都较差,所以限制只能设置20个关键词。关键词是与整个JSON字符串进行比较,所以在设置关键词时,尽量不要使用英文和标点,否则一旦和JSON对象的key相同,会导致推荐列表无任何显示。如果一定要使用英文单词和标点,务必清楚自己在做什么。 +Lite版本请确保所有Plus版本的选项都为关闭状态,以减少不必要的代码执行。 + + + +### 屏蔽关键词解锁 + +现在非会员和会员都可以在“设置-屏蔽设置-屏蔽关键词”中使用此功能。 + +**真正的盐选会员,使用此脚本后,会覆盖掉盐选会员的的配置功能,但已配置好的关键词不会失效。如果不需要此功能,可以在BoxJS中永久关闭。** + +此功能并非真正解锁会员特权,只是借用知乎APP的操作界面,通过脚本实现的关键词屏蔽。如果你已经是尊贵的盐选会员,建议关闭此功能,使用盐选会员自带的关键词屏蔽。 + +知乎助手的关键词解锁额外提供了正则表达式的屏蔽功能,可以实现一些较复杂的判断逻辑,及提高屏蔽效率。比如关键词设置`男士.*(沐浴露|香水)+`,表示只有“男士”和“沐浴露”或“香水”共同出现时才进行屏蔽。而`(羊毛|优惠|红包)+`,表示“羊毛”、“优惠”、“红包”出现任意一个关键词就进行屏蔽,可以替代原先的羊毛”、“优惠”、“红包”三个关键词,减少关键词数量,提高屏蔽效率。 #### 小技巧 -添加关键字 `zvideo`,可屏蔽推荐列表中的视频。 +通过抓包获取推荐页的数据,可以通过正则屏蔽任意内容。 -理论上,通过抓包获取的各种类型数据,只要能在响应的json中找到对应的关键字,都可以通过“关键字屏蔽”功能实现过滤。 - -**当用户为盐选会员时,脚本的关键字屏蔽功能不生效,所以对会员没有效果。** - -### 付费内容提醒(beta) +### 付费内容提醒 遇到需要付费阅读的回答时,会**将付费内容的提醒置顶**。避免阅读中途发现内容需要付费的情况,提高阅读体验。 @@ -130,21 +117,17 @@ -### 推广内容提醒(beta) +### 推广内容提醒 遇到含有营销推广/购物推广内容的回答时,会将含有推广内容的提醒置顶,自行判断是否继续阅读。 -### 精简顶部标签页 - -精简顶部标签页的功能,需要对原先拦截的appcloud2.zhihu.com域名进行放行,通过脚本对Response进行修改以实现此功能。**原先有对此域名进行拦截的规则,务必进行去除,否则功能不会生效。** - ### 黑名单增强 -知乎的黑名单设计,无法屏蔽黑名单用户的公开信息。将某人拉黑后,他的回答依旧会出现在推荐列表和回答列表中。 +知乎的黑名单设计,无法屏蔽黑名单用户的公开信息。将某人拉黑后,他的回答依旧会出现在推荐页和回答列表中。 -黑名单增强就是对黑名单用户的回答进行屏蔽,让他的回答从推荐列表和回答列表中消失。(如果只为在推荐列表屏蔽某人,建议用知乎提供的屏蔽用户的方法,这是在服务器端进行的更加高效的屏蔽。) +黑名单增强就是对黑名单用户的回答进行屏蔽,让他的回答从推荐页和回答列表、评论和想法中消失。(如果只为在推荐页屏蔽某人,建议用知乎提供的屏蔽用户的方法,这是在服务器端进行的更加高效的屏蔽。) 黑名单匹配方式为用户名,同名用户都会被屏蔽,“[已重置]”除外。 @@ -178,6 +161,8 @@ https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhi ### Loon +使用插件 + ```ini [Plugin] https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.lnplugin, tag=知乎助手_去广告及体验增强, enabled=true @@ -194,9 +179,9 @@ IP-CIDR,118.89.204.198/32,REJECT IP6-CIDR,2402:4e00:1200:ed00:0:9089:6dac:96b6/128,REJECT HOST,118.89.204.198,REJECT # 知乎去广告,以下规则的位置越前方越好 +HOST,appcloud2.in.zhihu.com,REJECT HOST,mqtt.zhihu.com,reject HOST,sugar.zhihu.com,reject -HOST,appcloud2.in.zhihu.com,REJECT USER-AGENT,AVOS*,REJECT [rewrite_remote] @@ -233,9 +218,9 @@ IP-CIDR,118.89.204.198/32,REJECT IP6-CIDR,2402:4e00:1200:ed00:0:9089:6dac:96b6/128,REJECT HOST,118.89.204.198,REJECT # 知乎去广告,以下规则的位置越前方越好 +HOST,appcloud2.in.zhihu.com,REJECT HOST,mqtt.zhihu.com,reject HOST,sugar.zhihu.com,reject -HOST,appcloud2.in.zhihu.com,REJECT USER-AGENT,AVOS*,REJECT [rewrite_remote] @@ -248,7 +233,7 @@ https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhi 对于脚本内置的黑名单,**保持谨慎和克制的原则**,只加入无法通过加入黑名单进行屏蔽的账号。如需要屏蔽更多的账户,可以由使用者手动将其加入黑名单来实现。 -推荐列表中脚本内置的黑名单基本上都已去除,只保留”会员推荐“等几个,因为这些都不是账号,不能通过加入黑名单来屏蔽。并且, 会员推荐的屏蔽功能,只有在你获取过一次黑名单后才会生效。如果你用的是Lite版本,完全不用担心屏蔽问题。 +推荐页中脚本内置的黑名单基本上都已去除,只保留”会员推荐“等几个,因为这些都不是账号,不能通过加入黑名单来屏蔽。并且, 会员推荐的屏蔽功能,只有在你获取过一次黑名单后才会生效。如果你用的是Lite版本,完全不用担心屏蔽问题。 官方消息中脚本内置的黑名单也仅保留无法加入黑名单的营销账号,其他的如果需要屏蔽,手动把它们加入黑名单就好。 diff --git a/script/zhihu/images/06.jpg b/script/zhihu/images/06.jpg index 8ec5dbb2384..83ca934be77 100644 Binary files a/script/zhihu/images/06.jpg and b/script/zhihu/images/06.jpg differ diff --git a/script/zhihu/images/07.jpg b/script/zhihu/images/07.jpg new file mode 100644 index 00000000000..98e42527fa7 Binary files /dev/null and b/script/zhihu/images/07.jpg differ diff --git a/script/zhihu/zhihu_lite.lnplugin b/script/zhihu/zhihu_lite.lnplugin index 397270e34e7..c5554f0c0a0 100644 --- a/script/zhihu/zhihu_lite.lnplugin +++ b/script/zhihu/zhihu_lite.lnplugin @@ -28,13 +28,13 @@ URL-REGEX,^https?:\/\/www\.zhihu\.com\/api\/v\d+\/brand\/question/\d+/card\?,REJ ^https?:\/\/www\.zhihu\.com\/api\/v\d+\/brand\/question/\d+/card\? - reject-dict [Script] -http-response ^https?:\/\/api\.zhihu\.com\/people requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_处理用户信息 -http-response ^https?:\/\/api\.zhihu\.com\/(moments|topstory)(\/|\?)?(recommend|action=|feed_type=) requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_信息流去广告 -http-response ^https?:\/\/api\.zhihu\.com\/v4\/questions requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_回答列表去广告 -http-response ^https?:\/\/api\.zhihu\.com\/search\/preset_words\? requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_预置关键词去广告 -http-response ^https?:\/\/api\.zhihu\.com\/search\/top_search\/tabs\/hot\/items requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_热搜去广告 -http-response ^https?:\/\/api\.zhihu\.com\/topstory\/hot-lists?(\?|\/) requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_热榜去广告 -http-response ^https?:\/\/api\.zhihu\.com\/(comment_v5\/)?(answers|comments?|articles|pins)\/\d+\/(root_|child_)?comments? requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_评论去广告 +http-response ^https?:\/\/api\.zhihu\.com\/people requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js,tag=知乎_处理用户信息 +http-response ^https?:\/\/api\.zhihu\.com\/(moments|topstory)(\/|\?)?(recommend|action=|feed_type=) requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js,tag=知乎_信息流去广告 +http-response ^https?:\/\/api\.zhihu\.com\/v4\/questions requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js,tag=知乎_回答列表去广告 +http-response ^https?:\/\/api\.zhihu\.com\/search\/preset_words\? requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js,tag=知乎_预置关键词去广告 +http-response ^https?:\/\/api\.zhihu\.com\/search\/top_search\/tabs\/hot\/items requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js,tag=知乎_热搜去广告 +http-response ^https?:\/\/api\.zhihu\.com\/topstory\/hot-lists?(\?|\/) requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js,tag=知乎_热榜去广告 +http-response ^https?:\/\/api\.zhihu\.com\/(comment_v5\/)?(answers|comments?|articles|pins)\/\d+\/(root_|child_)?comments? requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js,tag=知乎_评论去广告 [MITM] hostname = www.zhihu.com,api.zhihu.com,zhuanlan.zhihu.com \ No newline at end of file diff --git a/script/zhihu/zhihu_lite.qxrewrite b/script/zhihu/zhihu_lite.qxrewrite index 7cd1f1e71d9..bb95d4af858 100644 --- a/script/zhihu/zhihu_lite.qxrewrite +++ b/script/zhihu/zhihu_lite.qxrewrite @@ -1,17 +1,17 @@ # 知乎处理用户信息 -^https?:\/\/api\.zhihu\.com\/people\/ url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js +^https?:\/\/api\.zhihu\.com\/people\/ url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js # 知乎信息流去广告 -^https?:\/\/api\.zhihu\.com\/(moments|topstory)(\/|\?)?(recommend|action=|feed_type=)(?!\/people) url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js +^https?:\/\/api\.zhihu\.com\/(moments|topstory)(\/|\?)?(recommend|action=|feed_type=)(?!\/people) url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js # 知乎回答列表去广告 -^https?:\/\/api\.zhihu\.com\/v4\/questions url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js +^https?:\/\/api\.zhihu\.com\/v4\/questions url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js # 知乎预置关键词去广告 -^https?:\/\/api\.zhihu\.com\/search\/preset_words\? url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js +^https?:\/\/api\.zhihu\.com\/search\/preset_words\? url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js # 知乎热搜去广告 -^https?:\/\/api\.zhihu\.com\/search\/top_search\/tabs\/hot\/items url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js +^https?:\/\/api\.zhihu\.com\/search\/top_search\/tabs\/hot\/items url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js # 知乎热榜去广告 -^https?:\/\/api\.zhihu\.com\/topstory\/hot-lists?(\?|\/) url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js +^https?:\/\/api\.zhihu\.com\/topstory\/hot-lists?(\?|\/) url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js # 知乎评论去广告 -^https?:\/\/api\.zhihu\.com\/(comment_v5\/)?(answers|comments?|articles|pins)\/\d+\/(root_|child_)?comments? url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js +^https?:\/\/api\.zhihu\.com\/(comment_v5\/)?(answers|comments?|articles|pins)\/\d+\/(root_|child_)?comments? url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js # 知乎去除回答下的广告 ^https?:\/\/www\.zhihu\.com\/api\/v4\/answers\/\d+\/recommendations url reject-dict # 知乎其他广告拦截 diff --git a/script/zhihu/zhihu_lite.sgmodule b/script/zhihu/zhihu_lite.sgmodule index 6b5b0ffd418..210a189d234 100644 --- a/script/zhihu/zhihu_lite.sgmodule +++ b/script/zhihu/zhihu_lite.sgmodule @@ -10,13 +10,13 @@ RULE-SET,https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/s ^https?:\/\/api\.zhihu\.com\/(notifications\/v\d\/count|v\d\/package|me\/guides|drama\/living-info|ad|fringe|commercial|market\/popovers|.*featured-comment-ad) data="https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/blank/blank_dict.json" [Script] -知乎_处理用户信息 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/people\/,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js -知乎_信息流去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/(moments|topstory)(\/|\?)?(recommend|action=|feed_type=)(?!\/people),script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js -知乎_回答列表去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/v4\/questions,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js -知乎_预置关键词去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/search\/preset_words\?,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js -知乎_热搜去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/search\/top_search\/tabs\/hot\/items,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js -知乎_热榜去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/topstory\/hot-lists?(\?|\/),script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js -知乎_评论去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/(comment_v5\/)?(answers|comments?|articles|pins)\/\d+\/(root_|child_)?comments?,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js +知乎_处理用户信息 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/people\/,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js +知乎_信息流去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/(moments|topstory)(\/|\?)?(recommend|action=|feed_type=)(?!\/people),script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js +知乎_回答列表去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/v4\/questions,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js +知乎_预置关键词去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/search\/preset_words\?,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js +知乎_热搜去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/search\/top_search\/tabs\/hot\/items,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js +知乎_热榜去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/topstory\/hot-lists?(\?|\/),script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js +知乎_评论去广告 = type=http-response,requires-body=1,max-size=0,pattern=^https?:\/\/api\.zhihu\.com\/(comment_v5\/)?(answers|comments?|articles|pins)\/\d+\/(root_|child_)?comments?,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.min.js [MITM] hostname = %APPEND% www.zhihu.com,api.zhihu.com,zhuanlan.zhihu.com \ No newline at end of file diff --git a/script/zhihu/zhihu_plus.js b/script/zhihu/zhihu_plus.js index e20c788745b..2f8b51fc2d9 100644 --- a/script/zhihu/zhihu_plus.js +++ b/script/zhihu/zhihu_plus.js @@ -12,7 +12,7 @@ let magicJS = MagicJS(scriptName, "INFO"); if (magicJS.isResponse) { switch (true) { // 回答内容优化 - case /^https?:\/\/www\.zhihu\.com\/appview\/v2\/answer\/.*(entry=(?!(preload-topstory|preload-search|preload-subscription)))?/.test(magicJS.request.url): + case magicJS.read("zhihu_settings_answer_tip") != false && /^https?:\/\/www\.zhihu\.com\/appview\/v2\/answer\/.*(entry=(?!(preload-topstory|preload-search|preload-subscription)))?/.test(magicJS.request.url): try { let html = magicJS.response.body; // 付费内容提醒 @@ -57,14 +57,14 @@ let magicJS = MagicJS(scriptName, "INFO"); let obj = JSON.parse(magicJS.response.body); magicJS.logDebug(`用户登录用户信息,接口响应:${magicJS.response.body}`); if (obj && obj["id"] && obj.hasOwnProperty("vip_info") && obj["vip_info"].hasOwnProperty("is_vip")) { - let userInfo = { + const userInfo = { id: obj["id"], is_vip: obj["vip_info"]["is_vip"] ? obj["vip_info"]["is_vip"] !== undefined : false, }; - magicJS.logInfo(`当前用户id:${obj["id"]},是否为VIP:${obj["vip_info"]["is_vip"]}`); + magicJS.logDebug(`当前用户id:${obj["id"]},是否为VIP:${obj["vip_info"]["is_vip"]}`); magicJS.write(currentUserInfoKey, userInfo); // 在知乎APP显示VIP,仅自己可见,无实际用途 - if (obj["vip_info"]["is_vip"] === false) { + if (magicJS.read("zhihu_settings_fake_vip") == true && obj["vip_info"]["is_vip"] === false) { obj["vip_info"]["is_vip"] = true; obj["vip_info"]["vip_icon"] = { url: "https://pic1.zhimg.com/v2-4812630bc27d642f7cafcd6cdeca3d7a_r.png", @@ -80,7 +80,7 @@ let magicJS = MagicJS(scriptName, "INFO"); sub_title: null, button_text: "你好,知乎!", jump_url: "zhihu://vip/purchase", - button_jump_url: "", + button_jump_url: "zhihu://vip/purchase", sub_title_new: null, identity: "svip", }; @@ -91,9 +91,9 @@ let magicJS = MagicJS(scriptName, "INFO"); jump_url: "zhihu://market/home", }, right_button: { - title: "开通盐选会员", - description: "畅享 10w+ 场优质内容等特权", - jump_url: "zhihu://vip/purchase", + title: "我的盐选会员", + description: "畅享 10w+ 优质内容", + jump_url: "zhihu://vip/my", }, }; obj["vip_info"]["entrance_v2"] = { @@ -111,8 +111,8 @@ let magicJS = MagicJS(scriptName, "INFO"); magicJS.logError(`知乎获取当前用户信息出现异常:${err}`); } break; - // 去除MCN信息 - case /^https?:\/\/api\.zhihu\.com\/people\/((?!self).)*$/.test(magicJS.request.url): + // 黑名单增强 - 浏览黑名单用户信息时自动加入脚本黑名单 + case magicJS.read("zhihu_settings_blocked_users") != false && /^https?:\/\/api\.zhihu\.com\/people\/((?!self).)*$/.test(magicJS.request.url): try { let obj = JSON.parse(magicJS.response.body); // 删除MCN信息 @@ -120,14 +120,14 @@ let magicJS = MagicJS(scriptName, "INFO"); response = { body: JSON.stringify(obj) }; // 如已是黑名单用户,但不在脚本黑名单中,则自动加入 if (obj.name && obj.id && obj.is_blocking === true) { - let userInfo = GetUserInfo(); + const userInfo = GetUserInfo(); let customBlockedUsers = magicJS.read(blockedUsersKey, userInfo.id); customBlockedUsers = typeof customBlockedUsers === "object" && !!customBlockedUsers ? customBlockedUsers : {}; if (!customBlockedUsers[obj.name]) { magicJS.logDebug(`当前需要加入黑名单的用户Id:${obj["id"]},用户名:${obj["name"]}`); customBlockedUsers[obj["name"]] = obj["id"]; magicJS.write(blockedUsersKey, customBlockedUsers, userInfo.id); - magicJS.logInfo(`${obj["name"]}写入脚本黑名单成功,当前脚本黑名单数据:${JSON.stringify(customBlockedUsers)}`); + magicJS.logDebug(`${obj["name"]}写入脚本黑名单成功,当前脚本黑名单数据:${JSON.stringify(customBlockedUsers)}`); magicJS.notify(`已自动将用户“${obj["name"]}”写入脚本黑名单。`); } } @@ -138,86 +138,60 @@ let magicJS = MagicJS(scriptName, "INFO"); // 推荐去广告与黑名单增强 case /^https:\/\/api\.zhihu\.com\/topstory\/recommend\?/.test(magicJS.request.url): try { - // 判断是否是“盐选推荐内容” - function IsYanXuan(element) { - let flag = false; - if (element["common_card"]["footline"].hasOwnProperty("elements")) { - for (let i = 0; i < element["common_card"]["footline"]["elements"].length; i++) { - let item = element["common_card"]["footline"]["elements"][i]; - if (item.hasOwnProperty("icon") && item["icon"]["image_url"] == "https://pic2.zhimg.com/80/v2-c46fc8ec4c4e9ffc8f846ae0d8158a80_1440w.png") { - flag = true; + // 默认关闭 + const settings_remove_yanxuan = magicJS.read("zhihu_settings_remove_yanxuan") == true; + const settings_recommend_stream = magicJS.read("zhihu_settings_recommend_stream") == true; + // 默认开启 + const settings_blocked_keywords = magicJS.read("zhihu_settings_blocked_keywords") != false; + const settings_blocked_users = magicJS.read("zhihu_settings_blocked_users") != false; + const user_info = GetUserInfo(); + + let keywords = magicJS.read(keywordBlockKey, user_info.id); + keywords = settings_blocked_keywords && !!keywords ? keywords : []; + let customBlockedUsers = magicJS.read(blockedUsersKey, user_info.id); + customBlockedUsers = settings_blocked_users && !!customBlockedUsers ? customBlockedUsers : {}; + + const dataFilter = (element) => { + let elementStr = JSON.stringify(element); + // 是否为广告 + let isAd = element["card_type"] === "slot_event_card" || element["card_type"] === "slot_video_event_card" || element.hasOwnProperty("ad"); + // 是否为流媒体 element["extra"]["type"] === "drama" || element["extra"]["type"] === "zvideo") || element["extra"]["type"] === "Video" || element["common_card"]["style"] === "BIG_IMAGE") + let isStream = isAd != true && settings_recommend_stream && elementStr.search(/"(type|style)+"\s?:\s?"(drama|zvideo|Video|BIG_IMAGE)+"/i) >= 0; + // 是否为盐选推荐 + let isYanXuan = isStream != true && settings_remove_yanxuan && elementStr.indexOf("https://pic2.zhimg.com/80/v2-c46fc8ec4c4e9ffc8f846ae0d8158a80_1440w.png") >= 0; + // 是否匹配脚本关键词过滤 + let matchKeyword = false; + if (isStream != true && settings_blocked_keywords) { + for (let i = 0; i < keywords.length; i++) { + if (elementStr.search(keywords[i]) >= 0) { + if (magicJS.isDebug){ + let elementTitle = element.common_card.feed_content.title.panel_text; + let elementContent = element.common_card.feed_content.content.panel_text; + let actionUrl = ""; + try { + actionUrl = element.common_card.feed_content.title.action.intent_url; + } catch {} + magicJS.logDebug(`匹配关键字:\n${keywords[i]}\n标题:\n${elementTitle}\n内容:\n${elementContent}`); + magicJS.notifyDebug(scriptName, `关键字:${keywords[i]}`, `${elementTitle}\n${elementContent}`, actionUrl); + } + matchKeyword = true; break; } } } - return flag; - } - - // 判断内容是否匹配屏蔽关键字 - function IsKeywordBlock(element) { - let flag = false; - let elementStr = JSON.stringify(element); - for (let i = 0; i < keywords.length; i++) { - if (elementStr.indexOf(keywords[i]) >= 0) { - let elementTitle = element.common_card.feed_content.title.panel_text; - let elementContent = element.common_card.feed_content.content.panel_text; - let actionUrl = ""; - try { - actionUrl = element.common_card.feed_content.title.action.intent_url; - } catch {} - magicJS.logInfo(`匹配关键字:\n${keywords[i]}\n标题:\n${elementTitle}\n内容:\n${elementContent}`); - magicJS.notifyDebug(scriptName, `关键字:${keywords[i]}`, `${elementTitle}\n${elementContent}`, actionUrl); - flag = true; - break; - } - } - return flag; - } - - let user_info = GetUserInfo(); - let customBlockedUsers = magicJS.read(blockedUsersKey, user_info.id); - let keywords = magicJS.read(keywordBlockKey, user_info.id); - customBlockedUsers = !!customBlockedUsers ? customBlockedUsers : {}; - keywords = !!keywords ? keywords : []; - let obj = JSON.parse(magicJS.response.body); - let data = obj["data"].filter((element) => { - // 修正由于JS number类型精度问题,导致JSON.parse精度丢失,引起视频无法自动播放的问题 + // 是否为黑名单用户 + let isBlockedUser = false; try { - if (element.hasOwnProperty("extra") && element["extra"].hasOwnProperty("type") && element["extra"]["type"] === "zvideo") { - let video_id = element["common_card"]["feed_content"]["video"]["customized_page_url"].match(/https?:\/\/www\.zhihu\.com\/[^=]*=(\d*)/)[1]; - element["common_card"]["feed_content"]["video"]["id"] = video_id; - } - } catch (err) { - magicJS.logError(`修正视频自动播放失败\n异常信息:${err}\n响应数据:${JSON.stringify(element)}`); + isBlockedUser = matchKeyword != true && settings_blocked_users && customBlockedUsers && element["common_card"]["feed_content"]["source_line"]["elements"][1]["text"]["panel_text"] in customBlockedUsers; + } catch { + isBlockedUser = false; } - let flag = !( - element["card_type"] === "slot_event_card" || - element["card_type"] === "slot_video_event_card" || - element.hasOwnProperty("ad") || - // 取消以下几行注释,推荐列表拦截视频与直播 - // element["extra"]["type"] === "drama" || - // element["extra"]["type"] === "zvideo" || - // element["extra"]["type"] === "Video" || - // element["common_card"]["style"] === "BIG_IMAGE" || - // 取消以下注释,推荐列表拦截“盐选推荐” - // IsYanXuan(element) || - // 注释下行,推荐列表关闭关键字屏蔽功能 - IsKeywordBlock(element) - ); - try { - if ( - flag === true && - customBlockedUsers && - element["common_card"]["feed_content"].hasOwnProperty("source_line") && - element["common_card"]["feed_content"]["source_line"].hasOwnProperty("elements") && - customBlockedUsers[element["common_card"]["feed_content"]["source_line"]["elements"][1]["text"]["panel_text"]] - ) { - flag = false; - } - } catch (err) {} - return flag; - }); - obj["data"] = data; + return !(isAd || isStream || isYanXuan || matchKeyword || isBlockedUser); + }; + + // 修复number类型精度丢失 + let obj = JSON.parse(magicJS.response.body.replace(/(\w+"+\s?):\s?(\d{15,})/g, '$1:"$2"')); + obj["data"] = obj["data"].filter(dataFilter); response = { body: JSON.stringify(obj) }; } catch (err) { magicJS.logError(`知乎推荐列表去广告出现异常:${err}`); @@ -226,39 +200,26 @@ let magicJS = MagicJS(scriptName, "INFO"); // 关注列表去广告 case /^https?:\/\/api\.zhihu\.com\/moments(\/|\?)?(recommend|action=|feed_type=)(?!\/people)/.test(magicJS.request.url): try { - let obj = JSON.parse(magicJS.response.body); - let user_info = GetUserInfo(); + // 修复number类型精度丢失 + let obj = JSON.parse(magicJS.response.body.replace(/(\w+"+\s?):\s?(\d{15,})/g, '$1:"$2"')); + const user_info = GetUserInfo(); let customBlockedUsers = magicJS.read(blockedUsersKey, user_info.id); customBlockedUsers = !!customBlockedUsers ? customBlockedUsers : {}; let data = []; - // 修正由于JS number类型精度问题,导致JSON.parse精度丢失,引起想法不存在的问题 - const targetIdFix = (element) => { - if (element["target_type"] == "pin") { - target_id = element["target"]["url"].match(/https?:\/\/www\.zhihu\.com\/pin\/(\d*)/)[1]; - element["target"]["id"] = target_id; - // 转发的想法处理 - if (!!element["target"]["origin_pin"] && element["target"]["origin_pin"].hasOwnProperty("url")) { - origin_target_id = element["target"]["origin_pin"]["url"].match(/https?:\/\/www\.zhihu\.com\/pin\/(\d*)/)[1]; - element["target"]["origin_pin"]["id"] = origin_target_id; - } - } - // 动态折叠处理 - else if (element["type"] == "moments_group") { - let momentsGroupList = []; - for (let j = 0; j < element["list"].length; j++) { - momentsGroupList.push(targetIdFix(element["list"][j])); - } - element["list"] = momentsGroupList; - } - return element; - }; + + const settings_moments_stream = magicJS.read("zhihu_settings_moments_stream") == true; + const settings_blocked_users = magicJS.read("zhihu_settings_blocked_users") != false; + for (let i = 0; i < obj["data"].length; i++) { - let element = targetIdFix(obj["data"][i]); - if (!element["ad"]) { + // let element = targetIdFix(obj["data"][i]); + let element = obj["data"][i]; + if (!element["ad"] && !element["adjson"] && !element["ad_list"]) { // 判断转发的想法是否含有黑名单用户 - if (element.target && element.target.origin_pin && element.target.origin_pin.author && customBlockedUsers[element.target.origin_pin.author.name]) { + if (settings_blocked_users && element.target && element.target.origin_pin && element.target.origin_pin.author && customBlockedUsers[element.target.origin_pin.author.name]) { magicJS.notifyDebug(`屏蔽“${element.target.author.name}”转发黑名单用户“${element.target.origin_pin.author.name}”的想法。`); - } else { + } + // 屏蔽关注页的“最新视频” + else if (!settings_moments_stream || element["type"] != "videos") { data.push(element); } } @@ -272,7 +233,7 @@ let magicJS = MagicJS(scriptName, "INFO"); // 回答列表去广告与黑名单增强 case /^https?:\/\/api\.zhihu\.com\/v4\/questions/.test(magicJS.request.url): try { - let userInfo = GetUserInfo(); + const userInfo = GetUserInfo(); let customBlockedUsers = magicJS.read(blockedUsersKey, userInfo.id); customBlockedUsers = !!customBlockedUsers ? customBlockedUsers : {}; let obj = JSON.parse(magicJS.response.body); @@ -288,49 +249,163 @@ let magicJS = MagicJS(scriptName, "INFO"); magicJS.logError(`知乎回答列表去广告出现异常:${err}`); } break; - // 拦截官方账号推广消息 - case /^https?:\/\/api\.zhihu\.com\/notifications\/v3\/timeline\/entry\/system_message/.test(magicJS.request.url): + // 知乎V5版本评论去广告及黑名单增强 + case /^https?:\/\/api\.zhihu\.com\/comment_v5\/(answers|pins|comments?|articles)\/\d+\/(root|child)_comment/.test(magicJS.request.url): try { - const sysmsg_blacklist = ["知乎小伙伴", "知乎视频", "知乎团队", "知乎礼券", "知乎读书会团队"]; - let obj = JSON.parse(magicJS.response.body); - let data = obj["data"].filter((element) => { - return sysmsg_blacklist.indexOf(element["content"]["title"]) < 0; - }); - obj["data"] = data; - response = { body: JSON.stringify(obj) }; + if (!!magicJS.response.body) { + let obj = JSON.parse(magicJS.response.body); + obj["ad_info"] = {}; + // 屏蔽黑名单用户 + if (magicJS.read("zhihu_settings_blocked_users") != false) { + let user_info = GetUserInfo(); + let customBlockedUsers = magicJS.read(blockedUsersKey, user_info.id); + customBlockedUsers = !!customBlockedUsers ? customBlockedUsers : {}; + let newComments = []; + let blockCommentIdObj = {}; + obj.data.forEach((comment) => { + // 评论人昵称 + let commentUserName = comment.author.name; + // 回复哪个人的评论(仅适用于独立子评论页面请求) + let replyUserName = ""; + if (comment.reply_to_author && comment.reply_to_author && comment.reply_to_author.name) { + replyUserName = comment.reply_to_author.name; + } + if (customBlockedUsers[commentUserName] || customBlockedUsers[replyUserName]) { + if (customBlockedUsers[commentUserName] && !replyUserName && magicJS.request.url.indexOf("root_comment") > 0) { + magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”的主评论。`); + } else if (customBlockedUsers[commentUserName] && !replyUserName && magicJS.request.url.indexOf("child_comment") > 0) { + magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”的子评论。`); + } else if (customBlockedUsers[commentUserName] && replyUserName && magicJS.request.url.indexOf("child_comment") > 0) { + magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”回复“${replyUserName}”的子评论。`); + } else { + magicJS.notifyDebug(`屏蔽“${commentUserName}”回复黑名单用户“${replyUserName}”的子评论。`); + } + blockCommentIdObj[comment.id] = commentUserName; + // 主评论数量-1,仅适用于root_comment主评论页面请求 + if (obj.counts && obj.counts.total_counts) { + obj.counts.total_counts -= 1; + } + // 子评论数量-1,仅适用于child_comment子评论页面请求 + if (obj.paging && obj.paging.totals) { + obj.paging.totals -= 1; + } + if (obj.root && obj.root.child_comment_count) { + obj.root.child_comment_count -= 1; + } + } else { + if (comment.child_comments) { + let newChildComments = []; + comment.child_comments.forEach((childComment) => { + let childCommentUserName = childComment.author.name; + if (customBlockedUsers[childCommentUserName] || blockCommentIdObj[childComment.reply_comment_id]) { + if (customBlockedUsers[childCommentUserName]) { + magicJS.notifyDebug(`屏蔽黑名单用户“${childCommentUserName}”的子评论。`); + blockCommentIdObj[childComment.id] = childCommentUserName; + } else { + magicJS.notifyDebug(`屏蔽“${childCommentUserName}”回复黑名单用户“${blockCommentIdObj[childComment.reply_comment_id]}”的子评论。`); + } + comment.child_comment_count -= 1; + } else { + newChildComments.push(childComment); + } + }); + comment.child_comments = newChildComments; + } + newComments.push(comment); + } + }); + obj.data = newComments; + } + response = { body: JSON.stringify(obj) }; + } } catch (err) { - magicJS.logError(`知乎拦截官方账号推广消息出现异常:${err}`); + magicJS.logError(`去除知乎评论广告出现异常:${err}`); } break; - // 屏蔽官方营销消息 - case /^https?:\/\/api\.zhihu\.com\/notifications\/v3\/message/.test(magicJS.request.url): + // 知乎旧版回答中的评论黑名单增强 + case /^https?:\/\/api\.zhihu\.com\/(answers|pins|comments?|articles)\/\d+\/(root|child)_comments/.test(magicJS.request.url): try { - let obj = JSON.parse(magicJS.response.body); - let newItems = []; - for (let item of obj["data"]) { - if (item["detail_title"] === "官方帐号消息") { - let unread_count = item["unread_count"]; - if (unread_count > 0) { - item["content"]["text"] = "未读消息" + unread_count + "条"; - } else { - item["content"]["text"] = "全部消息已读"; - } - item["is_read"] = true; - item["unread_count"] = 0; - newItems.push(item); - } else if (item["detail_title"] !== "知乎活动助手") { - newItems.push(item); + if (!!magicJS.response.body) { + // 评论区去广告 + let obj = JSON.parse(magicJS.response.body); + if (magicJS.read("zhihu_settings_blocked_users") != false) { + // 屏蔽黑名单用户 + let user_info = GetUserInfo(); + let customBlockedUsers = magicJS.read(blockedUsersKey, user_info.id); + let newData = []; + obj.data.forEach((comment) => { + // 评论人昵称 + let commentUserName = comment.author.member.name; + // 回复哪个人的评论(仅适用于独立子评论页面请求) + let replyUserName = ""; + if (comment.reply_to_author && comment.reply_to_author.member && comment.reply_to_author.member.name) { + replyUserName = comment.reply_to_author.member.name; + } + if (customBlockedUsers[commentUserName] || customBlockedUsers[replyUserName]) { + if (customBlockedUsers[commentUserName] && !replyUserName && magicJS.request.url.indexOf("root_comment") > 0) { + magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”的主评论。`); + } else if (customBlockedUsers[commentUserName] && !replyUserName && magicJS.request.url.indexOf("child_comment") > 0) { + magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”的子评论。`); + } else if (customBlockedUsers[commentUserName] && replyUserName && magicJS.request.url.indexOf("child_comment") > 0) { + magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”回复“${replyUserName}”的子评论。`); + } else { + magicJS.notifyDebug(`屏蔽“${commentUserName}”回复黑名单用户“${replyUserName}”的子评论。`); + } + // 减少主评论页面中的评论总数(仅适用于独立的主评论页面请求) + if (obj.common_counts) { + obj.common_counts -= 1; + } + // 减少子评论页面中的评论总数(仅适用于独立子评论页面请求) + if (obj.paging && obj.paging.totals) { + obj.paging.totals -= 1; + } + } else { + // 屏蔽子评论中的黑名单用户(仅适用于独立的主评论页面请求) + if (comment.child_comments) { + let newChildComments = []; + comment.child_comments.forEach((childComment) => { + if (customBlockedUsers[childComment.author.member.name] || customBlockedUsers[childComment.reply_to_author.member.name]) { + if (customBlockedUsers[childComment.author.member.name]) { + magicJS.notifyDebug(`屏蔽黑名单用户“${childComment.author.member.name}”的主评论。`); + } else { + magicJS.notifyDebug(`屏蔽“${childComment.author.member.name}”回复黑名单用户“${childComment.reply_to_author.member.name}”的子评论。`); + } + comment.child_comment_count -= 1; + } else { + newChildComments.push(childComment); + } + }); + comment.child_comments = newChildComments; + } + newData.push(comment); + } + }); + obj.data = newData; } + response = { body: JSON.stringify(obj) }; } - obj["data"] = newItems; - response = { body: JSON.stringify(obj) }; } catch (err) { - magicJS.logError(`知乎屏蔽官方营销消息出现异常:${err}`); + magicJS.logError(`去除知乎评论广告出现异常:${err}`); + } + break; + // 知乎热榜去广告 + case magicJS.read("zhihu_settings_hot_list") != false && /^https?:\/\/api\.zhihu\.com\/topstory\/hot-lists?(\?|\/)/.test(magicJS.request.url): + try { + if (!!magicJS.response.body) { + let obj = JSON.parse(magicJS.response.body); + let data = obj["data"].filter((e) => { + return e["type"] === "hot_list_feed" || e["type"] === "hot_list_feed_video"; + }); + obj["data"] = data; + response = { body: JSON.stringify(obj) }; + } + } catch (err) { + magicJS.logError(`去除知乎热搜广告出现异常:${err}`); } break; // 黑名单管理 - case /^https?:\/\/api\.zhihu\.com\/settings\/blocked_users/.test(magicJS.request.url): - let userInfo = GetUserInfo(); + case magicJS.read("zhihu_settings_blocked_users") != false && /^https?:\/\/api\.zhihu\.com\/settings\/blocked_users/.test(magicJS.request.url): + const userInfo = GetUserInfo(); let defaultBlockedUsers = {}; let customBlockedUsers = magicJS.read(blockedUsersKey, userInfo.id); customBlockedUsers = typeof customBlockedUsers === "object" && !!customBlockedUsers ? customBlockedUsers : {}; @@ -338,14 +413,14 @@ let magicJS = MagicJS(scriptName, "INFO"); customBlockedUsers[element] = "00000000000000000000000000000000"; defaultBlockedUsers[element] = "00000000000000000000000000000000"; }); - magicJS.logInfo(`当前用户id:${userInfo.id},脚本黑名单:${JSON.stringify(customBlockedUsers)}`); + magicJS.logDebug(`当前用户id:${userInfo.id},脚本黑名单:${JSON.stringify(customBlockedUsers)}`); // 获取黑名单 if (magicJS.request.method == "GET") { try { // 加载黑名单首页时,清空历史黑名单,仅保留脚本默认黑名单 if (magicJS.request.url.indexOf("offset") < 0) { customBlockedUsers = defaultBlockedUsers; - magicJS.logInfo("脚本黑名单已清空,请滑动至黑名单末尾保证重新获取完成。"); + magicJS.logDebug("脚本黑名单已清空,请滑动至黑名单末尾保证重新获取完成。"); magicJS.notify("脚本黑名单已清空,请滑动至黑名单末尾保证重新获取完成。"); } let obj = JSON.parse(magicJS.response.body); @@ -358,10 +433,8 @@ let magicJS = MagicJS(scriptName, "INFO"); }); magicJS.write(blockedUsersKey, customBlockedUsers, userInfo.id); if (obj["paging"]["is_end"] == true) { - magicJS.notify( - `获取脚本黑名单结束,当前黑名单共${Object.keys(customBlockedUsers).length - defaultAnswerBlockedUsers.length}人。\n脚本内置黑名单${defaultAnswerBlockedUsers.length}人。` - ); - magicJS.logInfo(`脚本黑名单内容:${JSON.stringify(customBlockedUsers)}。`); + magicJS.notify(`获取脚本黑名单结束,当前黑名单共${Object.keys(customBlockedUsers).length - defaultAnswerBlockedUsers.length}人。\n脚本内置黑名单${defaultAnswerBlockedUsers.length}人。`); + magicJS.logDebug(`脚本黑名单内容:${JSON.stringify(customBlockedUsers)}。`); } } else { magicJS.logWarning(`获取黑名单失败,接口响应不合法:${magicJS.response.body}`); @@ -381,7 +454,7 @@ let magicJS = MagicJS(scriptName, "INFO"); if (obj["id"]) { customBlockedUsers[obj["name"]] = obj["id"]; magicJS.write(blockedUsersKey, customBlockedUsers, userInfo.id); - magicJS.logInfo(`${obj["name"]}写入脚本黑名单成功,当前脚本黑名单数据:${JSON.stringify(customBlockedUsers)}`); + magicJS.logDebug(`${obj["name"]}写入脚本黑名单成功,当前脚本黑名单数据:${JSON.stringify(customBlockedUsers)}`); magicJS.notify(`已将用户“${obj["name"]}”写入脚本黑名单。`); } else { magicJS.logError(`${obj["name"]}写入脚本黑名单失败,没有获取到用户Id。`); @@ -408,7 +481,7 @@ let magicJS = MagicJS(scriptName, "INFO"); if (customBlockedUsers[username] == user_id) { delete customBlockedUsers[username]; magicJS.write(blockedUsersKey, customBlockedUsers, userInfo.id); - magicJS.logInfo(`${username}移出脚本黑名单成功,当前脚本黑名单数据:${JSON.stringify(customBlockedUsers)}`); + magicJS.logDebug(`${username}移出脚本黑名单成功,当前脚本黑名单数据:${JSON.stringify(customBlockedUsers)}`); magicJS.notify(`已将用户“${username}”移出脚本黑名单!`); break; } @@ -427,8 +500,48 @@ let magicJS = MagicJS(scriptName, "INFO"); } } break; + // 拦截官方账号推广消息 + case magicJS.read("zhihu_settings_sys_msg") != false && /^https?:\/\/api\.zhihu\.com\/notifications\/v3\/timeline\/entry\/system_message/.test(magicJS.request.url): + try { + const sysmsg_blacklist = ["知乎小伙伴", "知乎视频", "知乎团队", "知乎礼券", "知乎读书会团队"]; + let obj = JSON.parse(magicJS.response.body); + let data = obj["data"].filter((element) => { + return sysmsg_blacklist.indexOf(element["content"]["title"]) < 0; + }); + obj["data"] = data; + response = { body: JSON.stringify(obj) }; + } catch (err) { + magicJS.logError(`知乎拦截官方账号推广消息出现异常:${err}`); + } + break; + // 屏蔽官方营销消息 + case magicJS.read("zhihu_settings_sys_msg") != false && /^https?:\/\/api\.zhihu\.com\/notifications\/v3\/message/.test(magicJS.request.url): + try { + let obj = JSON.parse(magicJS.response.body); + let newItems = []; + for (let item of obj["data"]) { + if (item["detail_title"] === "官方帐号消息") { + let unread_count = item["unread_count"]; + if (unread_count > 0) { + item["content"]["text"] = "未读消息" + unread_count + "条"; + } else { + item["content"]["text"] = "全部消息已读"; + } + item["is_read"] = true; + item["unread_count"] = 0; + newItems.push(item); + } else if (item["detail_title"] !== "知乎活动助手") { + newItems.push(item); + } + } + obj["data"] = newItems; + response = { body: JSON.stringify(obj) }; + } catch (err) { + magicJS.logError(`知乎屏蔽官方营销消息出现异常:${err}`); + } + break; // 去除预置关键字广告 - case /^https?:\/\/api\.zhihu\.com\/search\/preset_words\?/.test(magicJS.request.url): + case magicJS.read("zhihu_settings_preset_words") == true && /^https?:\/\/api\.zhihu\.com\/search\/preset_words\?/.test(magicJS.request.url): try { if (!!magicJS.response.body) { magicJS.logDebug(`预置关键字返回:${magicJS.response.body}`); @@ -446,7 +559,7 @@ let magicJS = MagicJS(scriptName, "INFO"); } break; // 优化知乎软件配置 - case /^https?:\/\/appcloud2\.zhihu\.com\/v\d+\/config/.test(magicJS.request.url): + case magicJS.read("zhihu_settings_app_conf") == true && /^https?:\/\/appcloud2\.zhihu\.com\/v\d+\/config/.test(magicJS.request.url): try { if (!!magicJS.response.body) { let obj = JSON.parse(magicJS.response.body); @@ -467,7 +580,7 @@ let magicJS = MagicJS(scriptName, "INFO"); } break; // 知乎热搜去广告 - case /^https?:\/\/api\.zhihu\.com\/search\/top_search\/tabs\/hot\/items/.test(magicJS.request.url): + case magicJS.read("zhihu_settings_hot_search") == true && /^https?:\/\/api\.zhihu\.com\/search\/top_search\/tabs\/hot\/items/.test(magicJS.request.url): try { if (!!magicJS.response.body) { let obj = JSON.parse(magicJS.response.body); @@ -478,165 +591,14 @@ let magicJS = MagicJS(scriptName, "INFO"); magicJS.logError(`去除知乎热搜广告出现异常:${err}`); } break; - // 知乎热榜去广告 - case /^https?:\/\/api\.zhihu\.com\/topstory\/hot-lists?(\?|\/)/.test(magicJS.request.url): - try { - if (!!magicJS.response.body) { - let obj = JSON.parse(magicJS.response.body); - let data = obj["data"].filter((e) => { - return e["type"] === "hot_list_feed" || e["type"] === "hot_list_feed_video"; - }); - obj["data"] = data; - response = { body: JSON.stringify(obj) }; - } - } catch (err) { - magicJS.logError(`去除知乎热搜广告出现异常:${err}`); - } - break; - // 知乎V5版本评论去广告及黑名单增强 - case /^https?:\/\/api\.zhihu\.com\/comment_v5\/(answers|pins|comments?|articles)\/\d+\/(root|child)_comment/.test(magicJS.request.url): - try { - if (!!magicJS.response.body) { - let obj = JSON.parse(magicJS.response.body); - obj["ad_info"] = {}; - // 屏蔽黑名单用户 - let user_info = GetUserInfo(); - let customBlockedUsers = magicJS.read(blockedUsersKey, user_info.id); - customBlockedUsers = !!customBlockedUsers ? customBlockedUsers : {}; - let newComments = []; - let blockCommentIdObj = {}; - obj.data.forEach((comment) => { - // 评论人昵称 - let commentUserName = comment.author.name; - // 回复哪个人的评论(仅适用于独立子评论页面请求) - let replyUserName = ""; - if (comment.reply_to_author && comment.reply_to_author && comment.reply_to_author.name) { - replyUserName = comment.reply_to_author.name; - } - if (customBlockedUsers[commentUserName] || customBlockedUsers[replyUserName]) { - if (customBlockedUsers[commentUserName] && !replyUserName && magicJS.request.url.indexOf("root_comment") > 0) { - magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”的主评论。`); - } else if (customBlockedUsers[commentUserName] && !replyUserName && magicJS.request.url.indexOf("child_comment") > 0) { - magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”的子评论。`); - } else if (customBlockedUsers[commentUserName] && replyUserName && magicJS.request.url.indexOf("child_comment") > 0) { - magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”回复“${replyUserName}”的子评论。`); - } else { - magicJS.notifyDebug(`屏蔽“${commentUserName}”回复黑名单用户“${replyUserName}”的子评论。`); - } - blockCommentIdObj[comment.id] = commentUserName; - // 主评论数量-1,仅适用于root_comment主评论页面请求 - if (obj.counts && obj.counts.total_counts) { - obj.counts.total_counts -= 1; - } - // 子评论数量-1,仅适用于child_comment子评论页面请求 - if (obj.paging && obj.paging.totals) { - obj.paging.totals -= 1; - } - if (obj.root && obj.root.child_comment_count) { - obj.root.child_comment_count -= 1; - } - } else { - if (comment.child_comments) { - let newChildComments = []; - comment.child_comments.forEach((childComment) => { - let childCommentUserName = childComment.author.name; - if (customBlockedUsers[childCommentUserName] || blockCommentIdObj[childComment.reply_comment_id]) { - if (customBlockedUsers[childCommentUserName]) { - magicJS.notifyDebug(`屏蔽黑名单用户“${childCommentUserName}”的子评论。`); - blockCommentIdObj[childComment.id] = childCommentUserName; - } else { - magicJS.notifyDebug(`屏蔽“${childCommentUserName}”回复黑名单用户“${blockCommentIdObj[childComment.reply_comment_id]}”的子评论。`); - } - comment.child_comment_count -= 1; - } else { - newChildComments.push(childComment); - } - }); - comment.child_comments = newChildComments; - } - newComments.push(comment); - } - }); - obj.data = newComments; - response = { body: JSON.stringify(obj) }; - } - } catch (err) { - magicJS.logError(`去除知乎评论广告出现异常:${err}`); - } - break; - // 知乎旧版回答中的评论黑名单增强 - case /^https?:\/\/api\.zhihu\.com\/(answers|pins|comments?|articles)\/\d+\/(root|child)_comments/.test(magicJS.request.url): - try { - if (!!magicJS.response.body) { - // 评论区去广告 - let obj = JSON.parse(magicJS.response.body); - // 屏蔽黑名单用户 - let user_info = GetUserInfo(); - let customBlockedUsers = magicJS.read(blockedUsersKey, user_info.id); - let newData = []; - obj.data.forEach((comment) => { - // 评论人昵称 - let commentUserName = comment.author.member.name; - // 回复哪个人的评论(仅适用于独立子评论页面请求) - let replyUserName = ""; - if (comment.reply_to_author && comment.reply_to_author.member && comment.reply_to_author.member.name) { - replyUserName = comment.reply_to_author.member.name; - } - if (customBlockedUsers[commentUserName] || customBlockedUsers[replyUserName]) { - if (customBlockedUsers[commentUserName] && !replyUserName && magicJS.request.url.indexOf("root_comment") > 0) { - magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”的主评论。`); - } else if (customBlockedUsers[commentUserName] && !replyUserName && magicJS.request.url.indexOf("child_comment") > 0) { - magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”的子评论。`); - } else if (customBlockedUsers[commentUserName] && replyUserName && magicJS.request.url.indexOf("child_comment") > 0) { - magicJS.notifyDebug(`屏蔽黑名单用户“${commentUserName}”回复“${replyUserName}”的子评论。`); - } else { - magicJS.notifyDebug(`屏蔽“${commentUserName}”回复黑名单用户“${replyUserName}”的子评论。`); - } - // 减少主评论页面中的评论总数(仅适用于独立的主评论页面请求) - if (obj.common_counts) { - obj.common_counts -= 1; - } - // 减少子评论页面中的评论总数(仅适用于独立子评论页面请求) - if (obj.paging && obj.paging.totals) { - obj.paging.totals -= 1; - } - } else { - // 屏蔽子评论中的黑名单用户(仅适用于独立的主评论页面请求) - if (comment.child_comments) { - let newChildComments = []; - comment.child_comments.forEach((childComment) => { - if (customBlockedUsers[childComment.author.member.name] || customBlockedUsers[childComment.reply_to_author.member.name]) { - if (customBlockedUsers[childComment.author.member.name]) { - magicJS.notifyDebug(`屏蔽黑名单用户“${childComment.author.member.name}”的主评论。`); - } else { - magicJS.notifyDebug(`屏蔽“${childComment.author.member.name}”回复黑名单用户“${childComment.reply_to_author.member.name}”的子评论。`); - } - comment.child_comment_count -= 1; - } else { - newChildComments.push(childComment); - } - }); - comment.child_comments = newChildComments; - } - newData.push(comment); - } - }); - obj.data = newData; - response = { body: JSON.stringify(obj) }; - } - } catch (err) { - magicJS.logError(`去除知乎评论广告出现异常:${err}`); - } - break; default: - magicJS.logWarning("触发意外的请求处理,请确认脚本或复写配置正常。"); break; } } else if (magicJS.isRequest) { // 知乎屏蔽关键词解锁 - if (/^https?:\/\/api\.zhihu\.com\/feed-root\/block/.test(magicJS.request.url) === true) { + if (magicJS.read("zhihu_settings_blocked_keywords") != false && /^https?:\/\/api\.zhihu\.com\/feed-root\/block/.test(magicJS.request.url) === true) { try { - let userInfo = GetUserInfo(); + const userInfo = GetUserInfo(); // 获取屏蔽关键词列表 if (magicJS.request.method === "GET" && userInfo.is_vip !== true) { let keywords = magicJS.read(keywordBlockKey, userInfo.id); @@ -658,7 +620,7 @@ let magicJS = MagicJS(scriptName, "INFO"); success: true, is_vip: true, kw_min_length: 2, - kw_max_length: 15, + kw_max_length: 100, kw_max_count: keywordMaxCount, data: keywords, }); @@ -707,7 +669,7 @@ let magicJS = MagicJS(scriptName, "INFO"); } else { response = { response: { body: body, headers: headers, status: 200 } }; } - magicJS.logInfo(`添加本地脚本屏蔽关键词“${keyword}”`); + magicJS.logDebug(`添加本地脚本屏蔽关键词“${keyword}”`); } else { let body = JSON.stringify({ error: { @@ -755,7 +717,7 @@ let magicJS = MagicJS(scriptName, "INFO"); } else { response = { response: { body: body, headers: headers, status: 200 } }; } - magicJS.logInfo(`删除本地脚本屏蔽关键词:“${keyword}”`); + magicJS.logDebug(`删除本地脚本屏蔽关键词:“${keyword}”`); } } catch (err) { magicJS.logError(`知乎关键词屏蔽操作出现异常:${err}`); @@ -777,7 +739,7 @@ let magicJS = MagicJS(scriptName, "INFO"); function GetUserInfo() { let defaultUserInfo = { id: "default", is_vip: false }; try { - let userInfo = magicJS.read(currentUserInfoKey); + const userInfo = magicJS.read(currentUserInfoKey); if (typeof userInfo === "string") userInfo = JSON.parse(userInfo); if (!!userInfo && userInfo.hasOwnProperty("id")) { return userInfo; @@ -791,4 +753,4 @@ function GetUserInfo() { } // prettier-ignore -function MagicJS(scriptName="MagicJS",logLevel="INFO"){return new class{constructor(){if(this.version="2.2.3.3",this.scriptName=scriptName,this.logLevels={DEBUG:5,INFO:4,NOTIFY:3,WARNING:2,ERROR:1,CRITICAL:0,NONE:-1},this.isLoon="undefined"!=typeof $loon,this.isQuanX="undefined"!=typeof $task,this.isJSBox="undefined"!=typeof $drive,this.isNode="undefined"!=typeof module&&!this.isJSBox,this.isSurge="undefined"!=typeof $httpClient&&!this.isLoon,this.node={request:void 0,fs:void 0,data:{}},this.iOSUserAgent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1",this.pcUserAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.59",this.logLevel=logLevel,this._barkUrl="",this.isNode){this.node.fs=require("fs"),this.node.request=require("request");try{this.node.fs.accessSync("./magic.json",this.node.fs.constants.R_OK|this.node.fs.constants.W_OK)}catch(err){this.node.fs.writeFileSync("./magic.json","{}",{encoding:"utf8"})}this.node.data=require("./magic.json")}else this.isJSBox&&($file.exists("drive://MagicJS")||$file.mkdir("drive://MagicJS"),$file.exists("drive://MagicJS/magic.json")||$file.write({data:$data({string:"{}"}),path:"drive://MagicJS/magic.json"}))}set barkUrl(url){this._barkUrl=url.replace(/\/+$/g,"")}set logLevel(level){this._logLevel="string"==typeof level?level.toUpperCase():"DEBUG"}get logLevel(){return this._logLevel}get isRequest(){return"undefined"!=typeof $request&&"undefined"==typeof $response}get isResponse(){return"undefined"!=typeof $response}get request(){return"undefined"!=typeof $request?$request:void 0}get response(){return"undefined"!=typeof $response?($response.hasOwnProperty("status")&&($response.statusCode=$response.status),$response.hasOwnProperty("statusCode")&&($response.status=$response.statusCode),$response):void 0}get platform(){return this.isSurge?"Surge":this.isQuanX?"Quantumult X":this.isLoon?"Loon":this.isJSBox?"JSBox":this.isNode?"Node.js":"Unknown"}read(key,session=""){let val="";this.isSurge||this.isLoon?val=$persistentStore.read(key):this.isQuanX?val=$prefs.valueForKey(key):this.isNode?val=this.node.data:this.isJSBox&&(val=$file.read("drive://MagicJS/magic.json").string);try{this.isNode&&(val=val[key]),this.isJSBox&&(val=JSON.parse(val)[key]),session&&("string"==typeof val&&(val=JSON.parse(val)),val=val&&"object"==typeof val?val[session]:null)}catch(err){this.logError(err),val=session?{}:null,this.del(key)}void 0===val&&(val=null);try{val&&"string"==typeof val&&(val=JSON.parse(val))}catch(err){}return this.logDebug(`READ DATA [${key}]${session?`[${session}]`:""}(${typeof val})\n${JSON.stringify(val)}`),val}write(key,val,session=""){let data=session?{}:"";if(session&&(this.isSurge||this.isLoon)?data=$persistentStore.read(key):session&&this.isQuanX?data=$prefs.valueForKey(key):this.isNode?data=this.node.data:this.isJSBox&&(data=JSON.parse($file.read("drive://MagicJS/magic.json").string)),session){try{"string"==typeof data&&(data=JSON.parse(data)),data="object"==typeof data&&data?data:{}}catch(err){this.logError(err),this.del(key),data={}}this.isJSBox||this.isNode?(data[key]&&"object"==typeof data[key]||(data[key]={}),data[key].hasOwnProperty(session)||(data[key][session]=null),void 0===val?delete data[key][session]:data[key][session]=val):void 0===val?delete data[session]:data[session]=val}else this.isNode||this.isJSBox?void 0===val?delete data[key]:data[key]=val:data=void 0===val?null:val;"object"==typeof data&&(data=JSON.stringify(data)),this.isSurge||this.isLoon?$persistentStore.write(data,key):this.isQuanX?$prefs.setValueForKey(data,key):this.isNode?this.node.fs.writeFileSync("./magic.json",data):this.isJSBox&&$file.write({data:$data({string:data}),path:"drive://MagicJS/magic.json"}),this.logDebug(`WRITE DATA [${key}]${session?`[${session}]`:""}(${typeof val})\n${JSON.stringify(val)}`)}del(key,session=""){this.logDebug(`DELETE KEY [${key}]${session?`[${session}]`:""}`),this.write(key,null,session)}notify(title=this.scriptName,subTitle="",body="",opts=""){let convertOptions;if(opts=(_opts=>{let newOpts={};if("string"==typeof _opts)this.isLoon?newOpts={openUrl:_opts}:this.isQuanX?newOpts={"open-url":_opts}:this.isSurge&&(newOpts={url:_opts});else if("object"==typeof _opts)if(this.isLoon)newOpts.openUrl=_opts["open-url"]?_opts["open-url"]:"",newOpts.mediaUrl=_opts["media-url"]?_opts["media-url"]:"";else if(this.isQuanX)newOpts=_opts["open-url"]||_opts["media-url"]?_opts:{};else if(this.isSurge){let openUrl=_opts["open-url"]||_opts.openUrl;newOpts=openUrl?{url:openUrl}:{}}return newOpts})(opts),1==arguments.length&&(title=this.scriptName,subTitle="",body=arguments[0]),this.logNotify(`title:${title}\nsubTitle:${subTitle}\nbody:${body}\noptions:${"object"==typeof opts?JSON.stringify(opts):opts}`),this.isSurge)$notification.post(title,subTitle,body,opts);else if(this.isLoon)opts?$notification.post(title,subTitle,body,opts):$notification.post(title,subTitle,body);else if(this.isQuanX)$notify(title,subTitle,body,opts);else if(this.isNode){if(this._barkUrl){let content=encodeURI(`${title}/${subTitle}\n${body}`);this.get(`${this._barkUrl}/${content}`,()=>{})}}else if(this.isJSBox){let push={title:title,body:subTitle?`${subTitle}\n${body}`:body};$push.schedule(push)}}notifyDebug(title=this.scriptName,subTitle="",body="",opts=""){"DEBUG"===this.logLevel&&(1==arguments.length&&(title=this.scriptName,subTitle="",body=arguments[0]),this.notify(title,subTitle,body,opts))}log(msg,level="INFO"){this.logLevels[this._logLevel]void 0===_options.body?"":`${encodeURIComponent(key)}=${encodeURIComponent(_options.body[key])}`).join("&");_options.url.indexOf("?")<0&&(_options.url+="?"),_options.url.lastIndexOf("&")+1!=_options.url.length&&_options.url.lastIndexOf("?")+1!=_options.url.length&&(_options.url+="&"),_options.url+=qs,delete _options.body}return this.isQuanX?(_options.hasOwnProperty("body")&&"string"!=typeof _options.body&&(_options.body=JSON.stringify(_options.body)),_options.method=method):this.isNode?(delete _options.headers["Accept-Encoding"],"object"==typeof _options.body&&("GET"===method?(_options.qs=_options.body,delete _options.body):"POST"===method&&(_options.json=!0,_options.body=_options.body))):this.isJSBox&&(_options.header=_options.headers,delete _options.headers),_options}adapterHttpResponse(resp){let _resp={body:resp.body,headers:resp.headers,json:()=>JSON.parse(_resp.body)};return resp.hasOwnProperty("statusCode")&&resp.statusCode&&(_resp.status=resp.statusCode),_resp}get(options,callback){let _options=this.adapterHttpOptions(options,"GET");this.logDebug(`HTTP GET: ${JSON.stringify(_options)}`),this.isSurge||this.isLoon?$httpClient.get(_options,callback):this.isQuanX?$task.fetch(_options).then(resp=>{resp.status=resp.statusCode,callback(null,resp,resp.body)},reason=>callback(reason.error,null,null)):this.isNode?this.node.request.get(_options,(err,resp,data)=>{resp=this.adapterHttpResponse(resp),callback(err,resp,data)}):this.isJSBox&&(_options.handler=resp=>{let err=resp.error?JSON.stringify(resp.error):void 0,data="object"==typeof resp.data?JSON.stringify(resp.data):resp.data;callback(err,resp.response,data)},$http.get(_options))}getPromise(options){return new Promise((resolve,reject)=>{magicJS.get(options,(err,resp)=>{err?reject(err):resolve(resp)})})}post(options,callback){let _options=this.adapterHttpOptions(options,"POST");if(this.logDebug(`HTTP POST: ${JSON.stringify(_options)}`),this.isSurge||this.isLoon)$httpClient.post(_options,callback);else if(this.isQuanX)$task.fetch(_options).then(resp=>{resp.status=resp.statusCode,callback(null,resp,resp.body)},reason=>{callback(reason.error,null,null)});else if(this.isNode){let resp=this.node.request.post(_options,callback);resp.status=resp.statusCode,delete resp.statusCode}else this.isJSBox&&(_options.handler=resp=>{let err=resp.error?JSON.stringify(resp.error):void 0,data="object"==typeof resp.data?JSON.stringify(resp.data):resp.data;callback(err,resp.response,data)},$http.post(_options))}get http(){return{get:this.getPromise,post:this.post}}done(value={}){"undefined"!=typeof $done&&$done(value)}isToday(day){if(null==day)return!1;{let today=new Date;return"string"==typeof day&&(day=new Date(day)),today.getFullYear()==day.getFullYear()&&today.getMonth()==day.getMonth()&&today.getDay()==day.getDay()}}isNumber(val){return"NaN"!==parseFloat(val).toString()}attempt(promise,defaultValue=null){return promise.then(args=>[null,args]).catch(ex=>(this.logError(ex),[ex,defaultValue]))}retry(fn,retries=5,interval=0,callback=null){return(...args)=>new Promise((resolve,reject)=>{function _retry(...args){Promise.resolve().then(()=>fn.apply(this,args)).then(result=>{"function"==typeof callback?Promise.resolve().then(()=>callback(result)).then(()=>{resolve(result)}).catch(ex=>{retries>=1?interval>0?setTimeout(()=>_retry.apply(this,args),interval):_retry.apply(this,args):reject(ex),retries--}):resolve(result)}).catch(ex=>{this.logRetry(ex),retries>=1&&interval>0?setTimeout(()=>_retry.apply(this,args),interval):retries>=1?_retry.apply(this,args):reject(ex),retries--})}_retry.apply(this,args)})}formatTime(time,fmt="yyyy-MM-dd hh:mm:ss"){var o={"M+":time.getMonth()+1,"d+":time.getDate(),"h+":time.getHours(),"m+":time.getMinutes(),"s+":time.getSeconds(),"q+":Math.floor((time.getMonth()+3)/3),S:time.getMilliseconds()};/(y+)/.test(fmt)&&(fmt=fmt.replace(RegExp.$1,(time.getFullYear()+"").substr(4-RegExp.$1.length)));for(let k in o)new RegExp("("+k+")").test(fmt)&&(fmt=fmt.replace(RegExp.$1,1==RegExp.$1.length?o[k]:("00"+o[k]).substr((""+o[k]).length)));return fmt}now(){return this.formatTime(new Date,"yyyy-MM-dd hh:mm:ss")}today(){return this.formatTime(new Date,"yyyy-MM-dd")}sleep(time){return new Promise(resolve=>setTimeout(resolve,time))}}(scriptName)} +function MagicJS(scriptName="MagicJS",logLevel="INFO"){return new class{constructor(){if(this._startTime=Date.now(),this.version="2.2.3.6",this.scriptName=scriptName,this.logLevels={DEBUG:5,INFO:4,NOTIFY:3,WARNING:2,ERROR:1,CRITICAL:0,NONE:-1},this.isLoon="undefined"!=typeof $loon,this.isQuanX="undefined"!=typeof $task,this.isJSBox="undefined"!=typeof $drive,this.isNode="undefined"!=typeof module&&!this.isJSBox,this.isSurge="undefined"!=typeof $httpClient&&!this.isLoon,this.node={request:void 0,fs:void 0,data:{}},this.iOSUserAgent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1",this.pcUserAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36 Edg/84.0.522.59",this._logLevel="INFO",this.logLevel=logLevel,this._barkUrl="",this._barkKey="",this.isNode){this.node.fs=require("fs"),this.node.request=require("request");try{this.node.fs.accessSync("./magic.json",this.node.fs.constants.R_OK|this.node.fs.constants.W_OK)}catch(err){this.node.fs.writeFileSync("./magic.json","{}",{encoding:"utf8"})}this.node.data=require("./magic.json")}else this.isJSBox&&($file.exists("drive://MagicJS")||$file.mkdir("drive://MagicJS"),$file.exists("drive://MagicJS/magic.json")||$file.write({data:$data({string:"{}"}),path:"drive://MagicJS/magic.json"}))}set barkUrl(url){try{let _url=url.replace(/\/+$/g,"");this._barkUrl=`${/^https?:\/\/([^/]*)/.exec(_url)[0]}/push`,this._barkKey=/\/([^\/]+)\/?$/.exec(_url)[1]}catch(err){this.logDebug("Bark config error.")}}set logLevel(level){let magic_loglevel=this.read("magicjs_loglevel");this._logLevel=magic_loglevel||level.toUpperCase()}get logLevel(){return this._logLevel}get isRequest(){return"undefined"!=typeof $request&&"undefined"==typeof $response}get isResponse(){return"undefined"!=typeof $response}get isDebug(){return"DEBUG"===this.logLevel}get request(){return"undefined"!=typeof $request?$request:void 0}get response(){return"undefined"!=typeof $response?($response.hasOwnProperty("status")&&($response.statusCode=$response.status),$response.hasOwnProperty("statusCode")&&($response.status=$response.statusCode),$response):void 0}get platform(){return this.isSurge?"Surge":this.isQuanX?"Quantumult X":this.isLoon?"Loon":this.isJSBox?"JSBox":this.isNode?"Node.js":"Unknown"}read(key,session=""){let val="";this.isSurge||this.isLoon?val=$persistentStore.read(key):this.isQuanX?val=$prefs.valueForKey(key):this.isNode?val=this.node.data:this.isJSBox&&(val=$file.read("drive://MagicJS/magic.json").string);try{this.isNode&&(val=val[key]),this.isJSBox&&(val=JSON.parse(val)[key]),session&&("string"==typeof val&&(val=JSON.parse(val)),val=val&&"object"==typeof val?val[session]:null)}catch(err){this.logError(err),val=session?{}:null,this.del(key)}void 0===val&&(val=null);try{val&&"string"==typeof val&&(val=JSON.parse(val))}catch(err){}return this.logDebug(`READ DATA [${key}]${session?`[${session}]`:""}(${typeof val})\n${JSON.stringify(val)}`),val}write(key,val,session=""){let data=session?{}:"";if(session&&(this.isSurge||this.isLoon)?data=$persistentStore.read(key):session&&this.isQuanX?data=$prefs.valueForKey(key):this.isNode?data=this.node.data:this.isJSBox&&(data=JSON.parse($file.read("drive://MagicJS/magic.json").string)),session){try{"string"==typeof data&&(data=JSON.parse(data)),data="object"==typeof data&&data?data:{}}catch(err){this.logError(err),this.del(key),data={}}this.isJSBox||this.isNode?(data[key]&&"object"==typeof data[key]||(data[key]={}),data[key].hasOwnProperty(session)||(data[key][session]=null),void 0===val?delete data[key][session]:data[key][session]=val):void 0===val?delete data[session]:data[session]=val}else this.isNode||this.isJSBox?void 0===val?delete data[key]:data[key]=val:data=void 0===val?null:val;"object"==typeof data&&(data=JSON.stringify(data)),this.isSurge||this.isLoon?$persistentStore.write(data,key):this.isQuanX?$prefs.setValueForKey(data,key):this.isNode?this.node.fs.writeFileSync("./magic.json",data):this.isJSBox&&$file.write({data:$data({string:data}),path:"drive://MagicJS/magic.json"}),this.logDebug(`WRITE DATA [${key}]${session?`[${session}]`:""}(${typeof val})\n${JSON.stringify(val)}`)}del(key,session=""){this.logDebug(`DELETE KEY [${key}]${session?`[${session}]`:""}`),this.write(key,null,session)}notify(title=this.scriptName,subTitle="",body="",opts=""){let convertOptions;if(opts=(_opts=>{let newOpts={};if("string"==typeof _opts)this.isLoon?newOpts={openUrl:_opts}:this.isQuanX?newOpts={"open-url":_opts}:this.isSurge&&(newOpts={url:_opts});else if("object"==typeof _opts)if(this.isLoon)newOpts.openUrl=_opts["open-url"]?_opts["open-url"]:"",newOpts.mediaUrl=_opts["media-url"]?_opts["media-url"]:"";else if(this.isQuanX)newOpts=_opts["open-url"]||_opts["media-url"]?_opts:{};else if(this.isSurge){let openUrl=_opts["open-url"]||_opts.openUrl;newOpts=openUrl?{url:openUrl}:{}}return newOpts})(opts),1==arguments.length&&(title=this.scriptName,subTitle="",body=arguments[0]),this.logNotify(`title:${title}\nsubTitle:${subTitle}\nbody:${body}\noptions:${"object"==typeof opts?JSON.stringify(opts):opts}`),this.isSurge)$notification.post(title,subTitle,body,opts);else if(this.isLoon)opts?$notification.post(title,subTitle,body,opts):$notification.post(title,subTitle,body);else if(this.isQuanX)$notify(title,subTitle,body,opts);else if(this.isJSBox){let push={title:title,body:subTitle?`${subTitle}\n${body}`:body};$push.schedule(push)}this._barkUrl&&this._barkKey&&this.notifyBark(title,subTitle,body)}notifyDebug(title=this.scriptName,subTitle="",body="",opts=""){"DEBUG"===this.logLevel&&(1==arguments.length&&(title=this.scriptName,subTitle="",body=arguments[0]),this.notify(title,subTitle,body,opts))}notifyBark(title=this.scriptName,subTitle="",body="",opts=""){let options={url:this._barkUrl,headers:{"Content-Type":"application/json; charset=utf-8"},body:{title:title,body:subTitle?`${subTitle}\n${body}`:body,device_key:this._barkKey}};this.post(options,err=>{})}log(msg,level="INFO"){this.logLevels[this._logLevel]void 0===_options.body?"":`${encodeURIComponent(key)}=${encodeURIComponent(_options.body[key])}`).join("&");_options.url.indexOf("?")<0&&(_options.url+="?"),_options.url.lastIndexOf("&")+1!=_options.url.length&&_options.url.lastIndexOf("?")+1!=_options.url.length&&(_options.url+="&"),_options.url+=qs,delete _options.body}return this.isQuanX?(_options.hasOwnProperty("body")&&"string"!=typeof _options.body&&(_options.body=JSON.stringify(_options.body)),_options.method=method):this.isNode?(delete _options.headers["Accept-Encoding"],"object"==typeof _options.body&&("GET"===method?(_options.qs=_options.body,delete _options.body):"POST"===method&&(_options.json=!0,_options.body=_options.body))):this.isJSBox&&(_options.header=_options.headers,delete _options.headers),_options}adapterHttpResponse(resp){let _resp={body:resp.body,headers:resp.headers,json:()=>JSON.parse(_resp.body)};return resp.hasOwnProperty("statusCode")&&resp.statusCode&&(_resp.status=resp.statusCode),_resp}get(options,callback){let _options=this.adapterHttpOptions(options,"GET");this.logDebug(`HTTP GET: ${JSON.stringify(_options)}`),this.isSurge||this.isLoon?$httpClient.get(_options,callback):this.isQuanX?$task.fetch(_options).then(resp=>{resp.status=resp.statusCode,callback(null,resp,resp.body)},reason=>callback(reason.error,null,null)):this.isNode?this.node.request.get(_options,(err,resp,data)=>{resp=this.adapterHttpResponse(resp),callback(err,resp,data)}):this.isJSBox&&(_options.handler=resp=>{let err=resp.error?JSON.stringify(resp.error):void 0,data="object"==typeof resp.data?JSON.stringify(resp.data):resp.data;callback(err,resp.response,data)},$http.get(_options))}getPromise(options){return new Promise((resolve,reject)=>{magicJS.get(options,(err,resp)=>{err?reject(err):resolve(resp)})})}post(options,callback){let _options=this.adapterHttpOptions(options,"POST");if(this.logDebug(`HTTP POST: ${JSON.stringify(_options)}`),this.isSurge||this.isLoon)$httpClient.post(_options,callback);else if(this.isQuanX)$task.fetch(_options).then(resp=>{resp.status=resp.statusCode,callback(null,resp,resp.body)},reason=>{callback(reason.error,null,null)});else if(this.isNode){let resp=this.node.request.post(_options,callback);resp.status=resp.statusCode,delete resp.statusCode}else this.isJSBox&&(_options.handler=resp=>{let err=resp.error?JSON.stringify(resp.error):void 0,data="object"==typeof resp.data?JSON.stringify(resp.data):resp.data;callback(err,resp.response,data)},$http.post(_options,{}))}done(value={}){this._endTime=Date.now();let span=(this._endTime-this._startTime)/1e3;magicJS.logDebug(`SCRIPT COMPLETED: ${span}S.`),"undefined"!=typeof $done&&$done(value)}isToday(day){if(null==day)return!1;{let today=new Date;return"string"==typeof day&&(day=new Date(day)),today.getFullYear()==day.getFullYear()&&today.getMonth()==day.getMonth()&&today.getDay()==day.getDay()}}isNumber(val){return"NaN"!==parseFloat(val).toString()}attempt(promise,defaultValue=null){return promise.then(args=>[null,args]).catch(ex=>(this.logError(ex),[ex,defaultValue]))}retry(fn,retries=5,interval=0,callback=null){return(...args)=>new Promise((resolve,reject)=>{function _retry(...args){Promise.resolve().then(()=>fn.apply(this,args)).then(result=>{"function"==typeof callback?Promise.resolve().then(()=>callback(result)).then(()=>{resolve(result)}).catch(ex=>{retries>=1?interval>0?setTimeout(()=>_retry.apply(this,args),interval):_retry.apply(this,args):reject(ex),retries--}):resolve(result)}).catch(ex=>{this.logRetry(ex),retries>=1&&interval>0?setTimeout(()=>_retry.apply(this,args),interval):retries>=1?_retry.apply(this,args):reject(ex),retries--})}_retry.apply(this,args)})}formatTime(time,fmt="yyyy-MM-dd hh:mm:ss"){var o={"M+":time.getMonth()+1,"d+":time.getDate(),"h+":time.getHours(),"m+":time.getMinutes(),"s+":time.getSeconds(),"q+":Math.floor((time.getMonth()+3)/3),S:time.getMilliseconds()};/(y+)/.test(fmt)&&(fmt=fmt.replace(RegExp.$1,(time.getFullYear()+"").substr(4-RegExp.$1.length)));for(let k in o)new RegExp("("+k+")").test(fmt)&&(fmt=fmt.replace(RegExp.$1,1==RegExp.$1.length?o[k]:("00"+o[k]).substr((""+o[k]).length)));return fmt}now(){return this.formatTime(new Date,"yyyy-MM-dd hh:mm:ss")}today(){return this.formatTime(new Date,"yyyy-MM-dd")}sleep(time){return new Promise(resolve=>setTimeout(resolve,time))}}(scriptName)} diff --git a/script/zhihu/zhihu_plus.lnplugin b/script/zhihu/zhihu_plus.lnplugin index 130ae64a746..071aae36eab 100644 --- a/script/zhihu/zhihu_plus.lnplugin +++ b/script/zhihu/zhihu_plus.lnplugin @@ -36,8 +36,10 @@ URL-REGEX,^https?:\/\/www\.zhihu\.com\/api\/v\d+\/brand\/question/\d+/card\?,REJ ^https?:\/\/www\.zhihu\.com\/api\/v\d+\/brand\/question/\d+/card\? - reject-dict # 屏蔽消息页面上拉的用户精选 ^https?:\/\/api\.zhihu\.com/moments/hybrid\? - reject-dict -# 知乎下发的配置,如皮肤等,目前已知会导致Tab页管理功能失效 +# 知乎下发的配置 ^https?:\/\/api\.zhihu\.com\/ab\/api\/v1\/products\/zhihu\/platforms\/ios\/config - reject-200 +# 屏蔽知乎“我的”页面推荐开通会员的卡片 +^https?:\/\/api\.zhihu\.com\/people\/self\/new_user_card - reject-200 [Script] http-request ^https?:\/\/api\.zhihu\.com\/feed-root\/block requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_屏蔽关键字解锁 @@ -45,7 +47,7 @@ http-response ^https?:\/\/api\.zhihu\.com\/people requires-body=1,script-path=ht http-response ^https?:\/\/api\.zhihu\.com\/(moments|topstory)(\/|\?)?(recommend|action=|feed_type=)(?!\/people) requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_信息流去广告及黑名单增强 http-response ^https?:\/\/api\.zhihu\.com\/settings\/blocked_users requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_获取黑名单 http-response ^https?:\/\/api\.zhihu\.com\/v4\/questions requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_回答列表去广告及黑名单增强 -http-response ^https?:\/\/api\.zhihu\.com\/notifications\/v3\/(message\?|timeline\/entry\/system_message) requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_官方消息去广告 +http-response ^https?:\/\/api\.zhihu\.com\/notifications\/v3\/(message|timeline\/entry\/system_message) requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_官方消息去广告 http-response ^https?:\/\/api\.zhihu\.com\/search\/preset_words\? requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_预置关键词去广告 http-response ^https?:\/\/www\.zhihu\.com\/appview\/v2\/answer\/.*(entry=(?!(preload-topstory|preload-search|preload-subscription)))? requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_回答内容优化 http-response ^https?:\/\/appcloud2\.zhihu\.com\/v\d+\/config requires-body=1,script-path=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js,tag=知乎_优化软件配置 diff --git a/script/zhihu/zhihu_plus.qxrewrite b/script/zhihu/zhihu_plus.qxrewrite index 8d89a782161..0a4fbd2e74a 100644 --- a/script/zhihu/zhihu_plus.qxrewrite +++ b/script/zhihu/zhihu_plus.qxrewrite @@ -7,7 +7,7 @@ # 知乎获取黑名单 ^https?:\/\/api\.zhihu\.com\/settings\/blocked_users url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js # 知乎官方消息去广告 -^https?:\/\/api\.zhihu\.com\/notifications\/v3\/(message\?|timeline\/entry\/system_message) url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js +^https?:\/\/api\.zhihu\.com\/notifications\/v3\/(message|timeline\/entry\/system_message) url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js # 知乎预置关键词去广告 ^https?:\/\/api\.zhihu\.com\/search\/preset_words\? url script-response-body https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_plus.js # 优化软件配置 @@ -40,8 +40,10 @@ ^https?:\/\/www\.zhihu\.com\/api\/v\d+\/brand\/question/\d+/card\? url reject-dict # 屏蔽消息页面上拉的用户精选 ^https?:\/\/api\.zhihu\.com/moments/hybrid\? url reject-dict -# 知乎下发的配置,如皮肤等,目前已知会导致Tab页管理功能失效 +# 知乎下发的配置,如皮肤等 ^https?:\/\/api\.zhihu\.com\/ab\/api\/v1\/products\/zhihu\/platforms\/ios\/config url reject-200 +# 屏蔽知乎“我的”页面推荐开通会员的卡片 +^https?:\/\/api\.zhihu\.com\/people\/self\/new_user_card url reject-200 # hostname = www.zhihu.com,api.zhihu.com,appcloud2.zhihu.com,zhuanlan.zhihu.com hostname = *.zhihu.com diff --git a/script/zhihu/zhihu_plus.sgmodule b/script/zhihu/zhihu_plus.sgmodule index eab42c9e4a6..dfa80067dcc 100644 --- a/script/zhihu/zhihu_plus.sgmodule +++ b/script/zhihu/zhihu_plus.sgmodule @@ -6,8 +6,10 @@ RULE-SET,https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/script/zhihu/zhihu_remove_ads.list,REJECT-DROP [URL Rewrite] -# 知乎下发的配置,如皮肤等,目前已知会导致Tab页管理功能失效 +# 屏蔽知乎下发的配置,如皮肤等 ^https?:\/\/api\.zhihu\.com\/ab\/api\/v1\/products\/zhihu\/platforms\/ios\/config - reject +# 屏蔽知乎“我的”页面推荐开通会员的卡片 +^https?:\/\/api\.zhihu\.com\/people\/self\/new_user_card - reject [Map Local] # 知乎去除最常访问