open_original_links_in_pocket

just open direct!

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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