open_original_links_in_pocket

just open direct!

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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)
    })
  }
}