Rllmuk De-embed Twitter

Replaces embedded Twitter posts with a link

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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,
})