nT-Exporter

Export content URLs from newTumbl blog

נכון ליום 02-06-2023. ראה הגרסה האחרונה.

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 or Violentmonkey 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         nT-Exporter
// @namespace    https://www.newtumbl.com/
// @version      1.1
// @description  Export content URLs from newTumbl blog
// @author       ceodoe
// @license      GPLv3
// @match        https://*.newtumbl.com/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=newtumbl.com
// @grant        none
// @run-at       document-end
// ==/UserScript==

window.setTimeout(function() {
    let nav = document.querySelector("div.nav > ul");
    let dumpBtn = document.createElement("li");
    dumpBtn.innerText = "Export";

    dumpBtn.onclick = function() {
        let urlArray = [];
        let outputString = "";

        let imgs = document.querySelectorAll("img");
        let mediaRegex = new RegExp(/^https:\/\/dn[0-9]\.newtumbl\.com\/img\/[0-9]+\/[0-9]+\/[0-9]\/[0-9]+\/nT_[A-Za-z0-9_]+\.jpg|gif|mp4$/);
        let thumbnailRegex = new RegExp(/(_150|_300|_600)\.(jpg|gif|mp4)$/);
        let avatarRegex = new RegExp(/^https:\/\/dn[0-9]\.newtumbl\.com\/img\/[0-9]+\/0\/0\//);

        for(let i = 0; i < imgs.length; i++) {
            // Ignore avatars
            if(!avatarRegex.test(imgs[i].src)) {
                if(mediaRegex.test(imgs[i].src)) {
                    // Replace thumbnails with full version of the image
                    if(thumbnailRegex.test(imgs[i].src)) {
                        urlArray.push(imgs[i].src.replace(thumbnailRegex, ".$2"));
                    } else {
                        urlArray.push(imgs[i].src);
                    }
                }
            }
        }

        let vids = document.querySelectorAll("video > source");
        for(let i = 0; i < vids.length; i++) {
            if(mediaRegex.test(vids[i].src)) {
                urlArray.push(vids[i].src);                
            }
        }

        let urlSet = [...new Set(urlArray)];

        for(let i = 0; i < urlSet.length; i++) {
            outputString += urlSet[i] + "\n";
        }

        let element = document.createElement('a');
        element.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(outputString));
        element.setAttribute("download", `${window.location.host.split(".")[0]}_${GM_info.script.name}-${Date.now()}.txt`);
        element.style.display = "none";
        document.body.appendChild(element);
        element.click();
        document.body.removeChild(element);

        alert("Success! " + GM_info.script.name + " found " + urlSet.length + " unique media elements on this page, and saved their URLs to a text file. In order to download the actual media files, feed the downloaded text file into your favourite downloader, such as wget or JDownloader 2.");
    };

    nav.append(dumpBtn);
}, 1000);