I want to add a condition for adding the buttons. Only add the buttons when the address link consist of the word "thread". For example https://141love.net/thread-3217887 .  Please see the script below.

// ==UserScript==
// @name         Auto-Rate Posts with Close Handling
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  Automatically rate posts in a forum thread and handle already rated posts
// @author       Your Name
// @match        https://141love.net/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to update input values in the rate form and click the correct submit button
    function updateInputsAndSubmit() {
        const score1 = document.querySelector('input#score1.px.z');
        const score2 = document.querySelector('input#score2.px.z');
        const score4 = document.querySelector('input#score4.px.z');

        if (score1 && score2 && score4) {
            // Set the desired values
            score1.value = 2;
            score2.value = 20;
            score4.value = 2;

            console.log('Values set. Attempting to click the correct submit button.');

            // Find and click the correct submit button
            const submitButton = document.querySelector('button.pn.pnc:not(.z)');
            if (submitButton) {
                setTimeout(() => {
                    submitButton.click();
                }, 200);
            } else {
                console.log('Submit button not found. Retrying...');
                setTimeout(updateInputsAndSubmit, 200); // Retry if the button isn't found
            }
        } else {
            console.log('One or more inputs not found. Retrying...');
            setTimeout(updateInputsAndSubmit, 200);
        }
    }

    // Function to close the window if already rated
    function closeFwinWindow() {
        const closeButton = document.querySelector('button#closebtn.pn.pnc');
        if (closeButton) {
            console.log('Already rated window detected. Closing it.');
            closeButton.click();
        }
    }

    // Observe changes to detect when a rate form or already rated window is opened
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.addedNodes) {
                mutation.addedNodes.forEach((node) => {
                    if (node.id === 'fwin_rate') {
                        console.log('Rate window detected. Updating inputs...');
                        setTimeout(updateInputsAndSubmit, 500);
                    }
                    if (node.tagName === 'TABLE' && node.classList.contains('fwin')) {
                        console.log('Already rated window detected. Attempting to close.');
                        setTimeout(closeFwinWindow, 500);
                    }
                });
            }
        });
    });

    function automateRating() {
        // Find all rate buttons and click them one by one
        const rateButtons = document.querySelectorAll('a.rateb');
        rateButtons.forEach((button, index) => {
            setTimeout(() => {
                console.log(`Clicking rate button for post index ${index}`);
                button.click();
            }, index * 1000); // Delay each click by 1 second
        });
    }

    // Create and append a button for starting the automation
    function addAutomationButton(container, buttonText, styles) {
        if (container) {
            const autoButton = document.createElement('button');
            autoButton.innerText = buttonText;
            autoButton.onclick = automateRating;
            Object.assign(autoButton.style, styles);

            container.appendChild(autoButton);
        }
    }

    // Add the automation buttons on page load
    window.addEventListener('load', () => {
        const mainButtonStyles = {
            backgroundColor: '#FE9500',
            color: 'white',
            border: 'none',
            borderRadius: '4px',
            padding: '7px 10px',
            fontSize: '14.5px',
            cursor: 'pointer',
            margin: '0px'
        };

        const scrollTopButtonStyles = {
            backgroundColor: '#F4F4F4', // Change color for the button in #scrolltop
            color: '#BBBBBB', // Text color
            borderTop: '1px solid #BBBBBB',
            borderLeft: '0px solid #BBBBBB',
            borderBottom: '0px solid #BBBBBB',
            borderRight: '0px solid #BBBBBB',
            borderRadius: '0px',
            padding: '7px 7px',
            fontSize: '11px',
            fontWeight: 'bold', // Set font weight to bold
            cursor: 'pointer',
            margin: '0px',
            writingMode: 'horizontal-lr' // Ensures horizontal text
        };
        addAutomationButton(document.querySelector('div#pgt.pgs.cl'), '自動評分', mainButtonStyles);
        addAutomationButton(document.querySelector('div#scrolltop'), '自動評分', scrollTopButtonStyles); // Use different styles here

        // Start observing the document for rate windows
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
})();