Blinkist "Today's Free Blink" text scraper ("new-reader")

This script combines the chapter texts into one text and collects the audio links.

As of 2022-06-09. See the latest version.

// ==UserScript==
// @name         Blinkist "Today's Free Blink" text scraper ("new-reader")
// @description  This script combines the chapter texts into one text and collects the audio links.
// @namespace    http://tampermonkey.net/
// @version      0.3
// @author       scr1ptst3r
// @match        https://www.blinkist.com/de/nc/new-reader/*
// @match        https://www.blinkist.com/en/nc/new-reader/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=blinkist.com
// @grant        none
// @license      MIT
// ==/UserScript==
/* jshint esversion: 6 */
(function () {
    'use strict';
    window.addEventListener('load', () => {
        setTimeout(() => {
            const sbtn = document.createElement("button")
            sbtn.innerText = "START AUTO-SCRAPER"
            sbtn.setAttribute("data-scraper-btn","")
            sbtn.style.cssText = `position:fixed;top:0;left:50%;transform:translateX(-50%);font-size:16px;border:1px solid #bbb;cursor:pointer;border-radius:0 0 8px 8px;z-index:9999;padding:4px 9px;background-color:rgb(255, 193, 7);color:#000;font-weight:900`
            document.body.appendChild(sbtn)
            sbtn.addEventListener("click", function () {
                function nextChapter() {
                    if (document.querySelector(".reader-content__next").style.display != "none") {
                        setTimeout(() => {
                            document.querySelector(".reader-content__next").click()
                            nextChapter()
                        }, 1500)
                    }
                }
                nextChapter()
                sbtn.remove()
            })
                if (document.querySelector("[data-test-id=keyIdeas]")) {
                document.querySelector("[data-test-id=keyIdeas]").addEventListener("click", function () {
                if(document.querySelector("[data-scraper-btn]")){
                  document.querySelector("[data-scraper-btn]").remove()
                }}
               )
               }
            if (document.querySelector(".reader-content__next")) {
                document.querySelector(".reader-content__next").addEventListener("click", function () {
                if(document.querySelector("[data-scraper-btn]")){
                  document.querySelector("[data-scraper-btn]").remove()
                }
                    copyText()
                    setTimeout(() => {
                        if (document.querySelector(".reader-content__next").style.display === "none") {
                            const el1 = document.createElement("button")
                            el1.innerText = "COPY"
                            el1.style.cssText = `position:fixed;top:0;left:50%;transform:translateX(-50%);font-size:16px;border:1px solid #bbb;cursor:pointer;border-radius:0 0 8px 8px;z-index:9999;padding:4px 9px;background-color:rgb(25, 135, 84);color:white;font-weight:900`
                            document.body.appendChild(el1)
                            el1.addEventListener("click", function () {
                                el1.remove()
                                const el = document.createElement("textarea")
                                el.innerText = decodeURIComponent(document.body.getAttribute("data-content"))
                                el.style.cssText = `position:fixed;top:0;left:0;width:0;height:0;`
                                el.setAttribute("data-title", document.title)
                                document.body.appendChild(el)
                                el.select()
                                el.setSelectionRange(0, 99999)
                                navigator.clipboard.writeText(el.value)
                                el.remove()
                                const blinkistWindow = window.open("", "Blinkist Text", "top=10,left=10,width=500,height=800")
                                blinkistWindow.document.write(decodeURIComponent(document.body.getAttribute("data-content")).replace(/\n/g, "<br>"))
                                console.log(decodeURIComponent(document.body.getAttribute("data-content")))
                                let audioOutput = ""
                                decodeURIComponent(document.body.getAttribute("data-audio")).split("\n").forEach(e => { audioOutput += `<a href="${e}" target="_blank">${e}</a><br><br>` })
                                const blinkistAudioWindow = window.open("", "Blinkist Audio Links", "top=10,left=520,width=1100,height=800")
                                blinkistAudioWindow.document.write(audioOutput)
                                console.log(decodeURIComponent(document.body.getAttribute("data-audio")))
                            })
                        }
                    }, 1100)
                })
            }
        }, 1400)
        let x = encodeURIComponent(location.pathname.split("/").pop() + ":\n "), y = ""
        function copyText() {
            if (document.querySelector(".reader-content")) {
                x += encodeURIComponent(document.querySelector(".reader-content").innerText.replace("Mark as finished", "") + "\n\n")
                document.body.setAttribute("data-content", x)
            }
            if (document.querySelector("[audio-url]")) {
                y += encodeURIComponent(document.querySelector("[audio-url]").getAttribute("audio-url") + "\n")
                document.body.setAttribute("data-audio", y)
            }
        }
    })
})();