自动拉黑华为用户

一入泥潭深似海,满城尽是菊家军。余承东是天上父,任正非是地上神。老师教你爱祖国,外野孝子爱华为。你给华为智商税,华为给你增智慧。华为好呀华为美,华为用户全拉黑。

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name 自动拉黑华为用户
// @description 一入泥潭深似海,满城尽是菊家军。余承东是天上父,任正非是地上神。老师教你爱祖国,外野孝子爱华为。你给华为智商税,华为给你增智慧。华为好呀华为美,华为用户全拉黑。
// @namespace huawei-ptsd
// @match *://bbs.saraba1st.com/2b/thread-*
// @grant none
// @run-at document-end
// @version 1.2
// ==/UserScript==
async function getFormHash() {
  let res = await fetch('https://bbs.saraba1st.com/2b/home.php?mod=space&do=friend&view=blacklist'),
      html = await res.text(),
      parser = new DOMParser(),
      doc = parser.parseFromString(html, 'text/html'),
      formHashInput = doc.querySelector('form[name=blackform] input[name=formhash]'),
      formHash = formHashInput.value;
  return formHash;
}

async function addBlacklist(username) {
  let formHash = await getFormHash(),
      res = await fetch('https://bbs.saraba1st.com/2b/home.php?mod=spacecp&ac=friend&op=blacklist&start=', {
          method: 'POST',
          credentials: 'include',
          headers: {
              'content-type': 'application/x-www-form-urlencoded'
          },
          body: `username=${encodeURIComponent(username)}&blacklistsubmit_btn=true&blacklistsubmit=true&formhash=${formHash}`,
      }),
      html = await res.text();
  return html.includes('操作成功');
}

function isHuaweiUser(text) {
  return [
      /—— 来自 HUAWEI .+, Android .+$/, // S1Next-鹅版
      /----发送自 HUAWEI .+,Android .+$/ // Stage1 App For Android
  ].some(re => re.test(text));
}

~async function() {
  let huaweiPosts = Array.from(document.querySelectorAll('#postlist > [id^=post_]:not([style])')).filter(
      postElement => {
          return isHuaweiUser(postElement.querySelector('[id^=postmessage_]').textContent);
      })

  for (let postElement of huaweiPosts) {
      postElement.style.display = 'none';
  }

  let unblockedHuaweiUsers = Array.from(
      new Set(
          huaweiPosts.map(
              postElement => {
                  return postElement.querySelector('.authi .xw1').textContent;
              })
          )
      );

  for (let username of unblockedHuaweiUsers) {
      await addBlacklist(username);
  }
}();