Rllmuk De-embed Twitter

Replaces embedded Twitter posts with a link

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Rllmuk De-embed Twitter
// @description Replaces embedded Twitter posts with a link
// @namespace   https://github.com/insin/greasemonkey/
// @version     3
// @grant       none
// @match       https://www.rllmukforum.com/index.php?/topic/*
// @match       https://rllmukforum.com/index.php?/topic/*
// ==/UserScript==

let $style = document.createElement('style')
$style.appendChild(document.createTextNode(`
iframe[data-embed-src*="url=https://twitter.com"], iframe[src*="url=https://twitter.com"] {
  display: none !important;
}
`))
document.querySelector('head').appendChild($style)

function processIframes() {
  document.querySelectorAll(`iframe[data-embed-src*="url=https://twitter.com"], iframe[src*="url=https://twitter.com"]`).forEach($iframe => {
    let link = ($iframe.dataset.embedSrc || $iframe.src).match(/https:\/\/twitter\.com\/[^/]+(\/status(?:es)?\/\d+)?/)?.[0]
    if (link) {
      $iframe.insertAdjacentHTML('afterend', `<a href="${link}" target="_blank">${link}</a>`)
      $iframe.remove()
    } else {
      $iframe.style.setProperty('display', 'revert', 'important')
    }
  })
}

processIframes()

// Watch for posts being replaced when paging
new MutationObserver(mutations =>
  mutations.forEach(mutation => {
    if (mutation.oldValue == 'true') {
      processIframes()
    }
  })
).observe(document.querySelector('div.cTopic'), {
  attributes: true,
  attributeFilter: ['animating'],
  attributeOldValue: true,
})

// Watch for new posts being loaded into the current page
new MutationObserver(mutations => {
  mutations.forEach(mutation =>
    mutation.addedNodes.forEach(processIframes)
  )
}).observe(document.querySelector('#elPostFeed > form'), {
  childList: true,
})