add page pagination for script below:
// ==UserScript==
// @name         F95 – add “Compressed version” link (Updated for current search result structure)
// @namespace    https://example.com/
// @version      1.8.5
// @description  Finds newest compressed build in same thread using updated search result parsing to handle forum HTML changes, with version-aware search and fallback to broad search.
// @author       You
// @match        https://f95zone.to/*threads/*
// @grant        GM_xmlhttpRequest
// @connect      f95zone.to
// ==/UserScript==

/* -------------------------------------------------- */
/* ------------------  helpers  --------------------- */
/* -------------------------------------------------- */

function parseVersionKey(text) {
    if (!text) return null;

    const cleanedText = text.replace(/[\[\]\(\)]/g, ' ');

    const seasonRegex = /s(?:eason)?\s*(\d+).*?(ch|ep|chapter|episode)\.?\s*(\d+)/i;
    let match = cleanedText.match(seasonRegex);
    if (match && match[1] && match[2] && match[3]) {
        const season = parseInt(match[1], 10);
        const typeStr = match[2].toLowerCase();
        const number = parseInt(match[3], 10);
        const displayType = typeStr.startsWith('ch') ? 'Ch.' : 'Ep.';
        return { key: season + number / 100, valueStr: `S${season} ${displayType} ${number}` };
    }

    const standaloneRegex = /\b(ch|ep|chapter|episode)\.?\s*(\d+)/i;
    match = cleanedText.match(standaloneRegex);
    if (match && match[1] && match[2]) {
        const typeStr = match[1].toLowerCase();
        const number = parseInt(match[2], 10);
        const displayType = typeStr.startsWith('ch') ? 'Ch.' : 'Ep.';
        return { key: 1 + number / 100, valueStr: `${displayType} ${number}` };
    }

    const versionRegex = /v(?:ersion)?[\s._-]?(\d[\d.]*)/i;
    match = cleanedText.match(versionRegex);
    if (match && match[1]) {
        const parts = match[1].split('.');
        let key = NaN;
        if (parts.length === 1) {
            key = parseFloat(parts[0]);
        } else {
            key = parseFloat(parts[0]) + parseFloat(parts.slice(1).join('')) / Math.pow(10, parts.slice(1).join('').length);
        }
        if (isNaN(key)) key = parseFloat(match[1]);
        return { key, valueStr: `v${match[1]}` };
    }

    return null;
}

function createCompressedVersionLink(label, href) {
    const link = document.createElement('a');
    link.href = href;
    link.textContent = label;
    link.target = '_blank';
    link.rel = "noopener noreferrer";
    link.style.cssText = `
        display: inline-block; margin: 10px 0 12px 0; padding: 8px 14px;
        background-color: #ba4545; color: white; font-weight: bold;
        font-size: 14px; text-decoration: none; border-radius: 4px; cursor: pointer;
    `;
    link.title = 'Go to compressed version post';
    return link;
}

function insertLinkAboveDownloadDiv(firstPost, element) {
    const candidates = firstPost.querySelectorAll('div[style*="text-align: center"]');
    for (const div of candidates) {
        if (div.textContent.trim().toUpperCase().includes('DOWNLOAD')) {
            div.parentNode.insertBefore(element, div);
            return true;
        }
    }
    const firstSpoiler = firstPost.querySelector('.bbCodeSpoiler');
    if (firstSpoiler) {
        firstSpoiler.parentNode.insertBefore(element, firstSpoiler);
    } else {
        firstPost.insertBefore(element, firstPost.firstChild);
    }
    return false;
}

function isGameReleasePost(post) {
    if (!post) return false;
    const centerDivs = post.querySelectorAll('div[style*="text-align: center"]');
    for (const div of centerDivs) {
        if (div.textContent.trim().toUpperCase().includes('DOWNLOAD')) return true;
    }
    const spoilerButtons = post.querySelectorAll('.bbCodeSpoiler-button');
    for (const button of spoilerButtons) {
        const buttonText = button.textContent.trim().toUpperCase();
        if (buttonText.includes('DOWNLOAD') || buttonText.includes('LINKS')) return true;
    }
    return false;
}

function looksLikeQuote(snippet) {
    if (!snippet) return false;
    const s = snippet.trim().toLowerCase();
    return s.includes('said:') || s.startsWith('quote') || s.startsWith('spoiler');
}

function isIgnorableComment(text) {
    if (!text) return false;
    const s = text.trim().toLowerCase();
    const requestKeywords = [
        'request', 'looking for', 'anyone has', 'does anyone have',
        'can someone', 'anyone have', 'does anyone know', 'need', 'searching for',
        'is this', 'is there', 'or what'
    ];
    return requestKeywords.some(keyword => s.includes(keyword)) || s.endsWith('?');
}

/* -------------------------------------------------- */
/* --------  CORE: search-result processing  -------- */
/* -------------------------------------------------- */

function findBestMatchingCompressedPost(html) {
    const doc = new DOMParser().parseFromString(html, 'text/html');

    // Use updated selector for search result posts:
    const items = [...doc.querySelectorAll('div.message--post')];

    if (!items.length) {
        console.warn('findBestMatchingCompressedPost(): no matching post items found in search results.');
        return null;
    }

    const compressedRegex = /(compressed|compress|archive|\.zip|\.rar|\.7z)/i;
    const releaseIndicatorRegex = /(mega|pixeldrain|workupload|buzzheavier|datanodes|akirabox|win|linux|mac|gb|mb)/i;
    const hasLinkRegex = /\[(URL|CODE|SPOILER)/i;

    // Get current thread URL without fragment, to build post links
    const threadUrl = window.location.href.split('#')[0];

    const candidates = items.map(postDiv => {
        const bbWrapper = postDiv.querySelector('.bbWrapper');
        if (!bbWrapper) return null;
        const snippetText = bbWrapper.innerText.trim();

        const postIdMatch = postDiv.id ? postDiv.id.match(/message-(\d+)/) : null;
        if (!postIdMatch) return null;
        const postId = postIdMatch[1];
        const postUrl = `${threadUrl}#post-${postId}`;

        if (looksLikeQuote(snippetText) || isIgnorableComment(snippetText) ||
            !compressedRegex.test(snippetText)) {
            return null;
        }

        const candidateVersionInfo = parseVersionKey(snippetText);
        const hasLinkTag = hasLinkRegex.test(snippetText);
        if (!candidateVersionInfo && !hasLinkTag) {
            return null;
        }

        const timeElem = postDiv.querySelector('time');
        if (!timeElem || !timeElem.getAttribute('datetime')) return null;
        const dateObj = new Date(timeElem.getAttribute('datetime'));
        if (isNaN(dateObj.getTime())) return null;

        const hasReleaseIndicator = releaseIndicatorRegex.test(snippetText);

        return { url: postUrl, date: dateObj, versionInfo: candidateVersionInfo, hasReleaseIndicator };
    }).filter(Boolean);

    if (!candidates.length) return null;

    candidates.sort((a, b) => {
        if (a.hasReleaseIndicator && !b.hasReleaseIndicator) return -1;
        if (!a.hasReleaseIndicator && b.hasReleaseIndicator) return 1;
        return b.date - a.date;
    });

    return candidates[0];
}

/* -------------------------------------------------- */
/* -----------  helper: POST form search  ----------- */
/* -------------------------------------------------- */

function postSearchUsingPageForm(searchQuery, threadId) {
    return new Promise((resolve, reject) => {
        const forms = document.querySelectorAll('form[action="/search/search"]');
        let searchForm = null;
        for (const form of forms) {
            if (form.querySelector('select[name="constraints"]')) {
                searchForm = form;
                break;
            }
        }
        if (!searchForm) {
            return reject(new Error("Could not find a search form with a 'constraints' dropdown. The page structure may have changed."));
        }
        const formData = new FormData(searchForm);
        formData.set('keywords', searchQuery);

        if (threadId) {
            formData.set('thread_ids', threadId);
        }

        formData.set('search_in', 'posts');

        const searchUrl = searchForm.action;
        GM_xmlhttpRequest({
            method: "POST", url: searchUrl, data: formData,
            headers: { "User-Agent": navigator.userAgent, "Referer": window.location.href },
            withCredentials: true,
            onload: r => {
                if (r.status >= 200 && r.status < 300) {
                    resolve(r.responseText);
                } else reject(new Error(`HTTP ${r.status}: ${r.statusText}`));
            },
            onerror: () => reject(new Error('Network error during GM_xmlhttpRequest')),
        });
    });
}

/* -------------------------------------------------- */
/* -------------------  main  ----------------------- */
/* -------------------------------------------------- */

async function trySearch(searchQuery, threadId) {
    const html = await postSearchUsingPageForm(searchQuery, threadId);
    const candidate = findBestMatchingCompressedPost(html);
    return { html, candidate };
}

window.addEventListener('load', () => {
    (async function main() {
        try {
            const firstPost = document.querySelector('.message-threadStarterPost.message--post.js-post');
            if (!firstPost) return;
            if (!isGameReleasePost(firstPost)) return;

            const urlMatch = window.location.pathname.match(/\.([0-9]+)(\/|$)/);
            const threadId = urlMatch ? urlMatch[1] : null;
            if (!threadId) return;

            const threadTitleElem = document.querySelector('.p-title-value');
            const threadTitle = threadTitleElem ? threadTitleElem.textContent.trim() : "";

            const versionMatch = threadTitle.match(/(S[0-9]+|P[0-9a-z\-]+)/gi);
            const versionToken = versionMatch ? versionMatch.join(' ') : "";

            let searchQuery = 'compressed';
            if (versionToken) {
                searchQuery = `compressed ${versionToken}`;
            }

            let { candidate } = await trySearch(searchQuery, threadId);

            if (!candidate && searchQuery !== 'compressed') {
                ({ candidate } = await trySearch('compressed', threadId));
            }

            if (!candidate) {
                const warn = document.createElement('span');
                warn.textContent = 'No matching compressed version found.';
                warn.style.cssText = 'color:#ba4545; display:block; margin:10px 0 12px;';
                insertLinkAboveDownloadDiv(firstPost, warn);
                return;
            }

            const versionStr = candidate.versionInfo ? candidate.versionInfo.valueStr : 'Link';
            const linkLabel = `Compressed Version (${versionStr})`;

            const link = createCompressedVersionLink(linkLabel, candidate.url);
            insertLinkAboveDownloadDiv(firstPost, link);

        } catch (e) {
            console.error("F95 Compressed Link Script Error:", e);
        }
    })();
});