XenForo Watched Threads Backup (All Pages, Plain URLs)

Export ALL watched thread URLs across all watched-threads pages as a plain text file.

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

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 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         XenForo Watched Threads Backup (All Pages, Plain URLs)
// @namespace    https://simpcity.cr/
// @version      0.4
// @description  Export ALL watched thread URLs across all watched-threads pages as a plain text file.
// @author       You
// @license      MIT
// @match        https://simpcity.cr/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
'use strict';

const BUTTON_ID = "xf-export-urls";

function createButton() {
if (document.getElementById(BUTTON_ID)) return;
const btn = document.createElement('button');
btn.id = BUTTON_ID;
btn.textContent = 'Export Watched URLs (All Pages)';
Object.assign(btn.style, {
position: 'fixed',
right: '20px',
bottom: '20px',
zIndex: 9999,
padding: '10px 14px',
background: '#0b74de',
color: '#fff',
border: 'none',
borderRadius: '6px',
cursor: 'pointer'
});
btn.addEventListener('click', exportAllPages);
document.body.appendChild(btn);
}

function getThreadUrls(doc) {
const anchors = doc.querySelectorAll('a[href*="/threads/"]');
const urls = [];
anchors.forEach(a => {
const href = a.href;
// Only include real thread pages (skip ?unread, anchors, etc.)
if (/\/threads\/[^/]+\.\d+\/?$/.test(href)) {
if (!urls.includes(href)) {
urls.push(href);
}
}
});
return urls;
}

function getMaxPage() {
let max = 1;
document.querySelectorAll('a[href*="page="]').forEach(a => {
const m = a.href.match(/page=(\d+)/);
if (m) {
const num = parseInt(m[1], 10);
if (num > max) max = num;
}
});
return max;
}

async function fetchPage(url) {
const res = await fetch(url, { credentials: 'same-origin' });
const text = await res.text();
return new DOMParser().parseFromString(text, "text/html");
}

async function exportAllPages() {
const btn = document.getElementById(BUTTON_ID);
btn.disabled = true;
btn.textContent = "Collecting...";

const base = location.href.split("?")[0];
const maxPage = getMaxPage();
const allUrls = new Set();

// page 1 (current page)
getThreadUrls(document).forEach(u => allUrls.add(u));

// remaining pages
for (let p = 2; p <= maxPage; p++) {
btn.textContent = `Collecting... (page ${p}/${maxPage})`;
const pageUrl = `${base}?page=${p}`;
try {
const doc = await fetchPage(pageUrl);
getThreadUrls(doc).forEach(u => allUrls.add(u));
} catch (e) {
console.error("Failed to fetch page", p, e);
break;
}
}

// Export
const text = Array.from(allUrls).join("\n");
const blob = new Blob([text], { type: "text/plain" });
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "watched-threads.txt";
a.click();

btn.disabled = false;
btn.textContent = "Export Watched URLs (All Pages)";
}

createButton();
})();