Auto-Remove inactive offers

Deletes inactive offers from your notepad by clicking a button

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Auto-Remove inactive offers
// @namespace    https://greasyfork.org/users/1434745-r4tr4ce
// @version      1.4
// @description  Deletes inactive offers from your notepad by clicking a button
// @author       r4tr4ce
// @match        https://www.chrono24.*/user/notepad.htm*
// @grant        none
// @icon         https://static.chrono24.com/images/default/favicon/android-chrome-192x192.png
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function removeSoldItems() {
        let soldItems = document.querySelectorAll('div[data-watch-state="sold"], div[data-watch-state="deactivated"]');
        let index = 0;

        function processNext() {
            if (index < soldItems.length) {
                let div = soldItems[index];
                let button = Array.from(div.getElementsByTagName('button')).find(btn =>
                    btn.getAttribute('aria-label')?.includes('Remove')
                );
                if (button) {
                    button.click();

                    setTimeout(() => {
                        let deleteButton = document.querySelector('.js-confirmation-modal-confirm');
                        if (deleteButton) {
                            console.log('Clicking confirmation delete button:', deleteButton);
                            deleteButton.click();
                        }
                    }, 50);
                }
                index++;
                setTimeout(processNext, 500);
            }
        }

        processNext();
    }

    function createTriggerButton() {
        let button = document.createElement('button');
        button.textContent = 'Remove Sold Items';
        button.style.padding = '10px';
        button.style.backgroundColor = '#FF2400';
        button.style.color = 'white';
        button.style.border = 'none';
        button.style.cursor = 'pointer';
        button.addEventListener('click', removeSoldItems);

        let interval = setInterval(() => {
            let parentContainer = document.querySelector('.d-flex.align-items-center.justify-content-between .d-flex.flex-wrap.notepadfilters-selected');
            if (parentContainer) {
                parentContainer.appendChild(button);
                clearInterval(interval);
            }
        }, 100);
    }

    createTriggerButton();
})();