Pocket - open all saves in new tab

Adds a button to open all saves in new tab, also removes all `?utm_source=*` from url

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Pocket - open all saves in new tab
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  Adds a button to open all saves in new tab, also removes all `?utm_source=*` from url
// @author       FallenMax
// @match        https://getpocket.com/saves
// @match        https://getpocket.com/*/saves
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license MIT
// ==/UserScript==

(async function() {
    'use strict';

    await new Promise(resolve => setTimeout(resolve, 3000))

    const openAllLinks = () =>{
        const items = document.querySelectorAll('article[data-testid=article-card]')
        for (let i = 0; i < items.length; i++) {
            const item = items[i]
            const link = item.querySelector('a.publisher')
            const url = new URL(link.href)
            url.searchParams.delete('utm_source')
            link.href = url.href
            link.target = '_blank'
            link.click()
        }
    }

    let $sort = document.querySelector('button[data-testid="sort-options"]')
    let count=0
    while (!$sort) {
      if(count++>20) throw new Error('button not found')
      await new Promise(resolve => setTimeout(resolve, 1000))
      $sort = document.querySelector('button[data-testid="sort-options"]')
    }
    let $openAll = document.createElement('button')

    $openAll.textContent = 'Open All'
    $openAll.className = 'tiny'

    $sort.insertAdjacentElement('afterend', $openAll)

    $openAll.onclick = openAllLinks


})();