open_original_links_in_pocket

just open direct!

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        open_original_links_in_pocket
// @namespace   undegro
// @include     https://getpocket.com/*
// @version     4.6
// @license     MIT
// @description just open direct!
// ==/UserScript==

{
  const parent = document.getElementById("__next")
  const observeParent = new MutationObserver(records => records.filter(record => record.addedNodes[0]).some(record => record.target.tagName == "MAIN" || (record.target == parent && record.addedNodes[0].querySelector("main"))) && init())
  const observeArticle = new MutationObserver(records => records.flatMap(record => [...record.addedNodes]).forEach(rewrite))

  observeParent.observe(parent, { childList: true, subtree: true })

  async function init() {
    observeArticle.disconnect()
    const articleList = await waitElement("main > div > div > div")
    if(articleList) observeArticle.observe(articleList, { childList: true, subtree: true })
  }

  function rewrite(target) {
    if(target.tagName == "ARTICLE") {
      const links = [...target.getElementsByTagName("a")]
      const publisherLink = links.find(link => link.classList.contains("publisher"))
      links.forEach(link => {
        link.addEventListener("click", e => e.stopPropagation())
        link.href = decodeURIComponent(publisherLink.href.replace(/^https:\/\/getpocket\.com\/redirect\?url=/, ""))
        link.setAttribute("target", "_blank")
      })
    }
  }

  function waitElement(selector) {
    return new Promise((resolve) => {
      const searchElement = () => {
        const elem = document.querySelector(selector)
        if(!elem) {
          requestAnimationFrame(searchElement)
        }else{
          resolve(elem)
        }
      }

      searchElement()
      setTimeout(() => resolve(false), 5000)
    })
  }
}