TweetDeck 延命

for old tweetdeck

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        TweetDeck 延命
// @namespace   https://rinsuki.net
// @match       https://tweetdeck.twitter.com/*
// @version     1.0.1
// @author      -
// @description for old tweetdeck
// @run-at      document-start
// ==/UserScript==

function hook() {
  const xp = XMLHttpRequest.prototype
  const config = Object.getOwnPropertyDescriptor(xp, "responseText")
  let selfDestructTimer
  const myConfig = {
    ...config,
    get() {
      const orig = config.get.bind(this)()
      if (this.responseURL.startsWith("https://api.twitter.com/1.1/help/settings.json")) {
        const obj = JSON.parse(orig)
        console.info("original settings", obj)
        obj.config.tweetdeck_graphql_login = {value: true}
        const newResponseText = JSON.stringify(obj)
       console.info("feature flag hooked", newResponseText)
        if (selfDestructTimer != null) clearTimeout(selfDestructTimer)
        selfDestructTimer = setTimeout(() => {
          if (Object.getOwnPropertyDescriptor(xp, "responseText").get === myConfig.get) {
            console.info("it seems getter is not overrided, so hook will self-destruct...")
            Object.defineProperty(xp, "responseText", config)
          }
        }, 1000)
        return newResponseText
      }
      console.info("unrelated request...")
      return orig
    }
  }
  Object.defineProperty(xp, "responseText", myConfig)
}

if ("wrappedJSObject" in window) {
  console.info("hook for firefox")
  window.wrappedJSObject.eval(`(${hook.toString().replace(" hook", "")})()`)
} else {
  console.info("hook for chromium")
  hook()
}