blackmatrix7 / ios_rule_script

分流规则、重写写规则及脚本。
GNU General Public License v2.0
16.45k stars 2.64k forks source link

Script/zheye 回答信息流广告 #1321

Open Jiohon opened 1 week ago

Jiohon commented 1 week ago

规则名称:zheye

规则链接:https://github.com/blackmatrix7/ios_rule_script/tree/master/script/zheye

异常规则:知乎回答信息流页面广告

问题描述:广告字段更新,现有规则无法处理

抓包截图:(相关抓包工具的截图。)

调整方案:(你希望规则做哪些调整,及其原因。)

image

在removeNextBlackUserAnswer此函数内增加对adjson的处理

function removeNextBlackUserAnswer() {
  let response = null
  try {
    if (!!$.response.body) {
      let obj = JSON.parse($.response.body)
      const blackUserAnswersId = $.data.read(blackAnswersIdKey, [])
      if (blackUserAnswersId.length > 0) {
        let newData = []
        obj.data.forEach((element) => {
          const tag = blackUserAnswersId.includes(element.id.toString())
          if (tag === false) {
+            if (Object.hasOwnProperty(element, "adjson")) element.adjson = ""
            element.ad_info = { data: "" }
            newData.push(element)
          } else {
            $.notification.debug(`屏蔽翻页过程中出现的黑名单用户回答Id:${element.id}`)
          }
        })
        for (let i = 0; i < newData.length; i++) {
          if (newData[i]["extra"] && newData[i]["extra"]["question_index"]) {
            newData[i]["extra"]["question_index"] = i + 1
          }
          if (newData[i]["strategy_info"]) {
            newData[i]["strategy_info"]["global_index"] = i + 1
            newData[i]["strategy_info"]["strategy_index"] = i + 1
          }
        }
        obj.data = newData
      }
      response = { body: JSON.stringify(obj) }
    }
  } catch (err) {
    $.logger.error(`屏蔽下翻黑名单用户的回答出现异常:${err}`)
  }
  return response
}