Greasy Fork

Greasy Fork is available in English.

RL - TradeMe Real Estate Filter Updated - new

Hide listings without a specified price on TradeMe Real Estate listings.

当前为 2024-02-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         RL - TradeMe Real Estate Filter Updated - new
// @namespace    http://drsr/
// @version      1.4
// @author       chaoscreater
// @description  Hide listings without a specified price on TradeMe Real Estate listings.
// @include      /https://www\.trademe\.co\.nz/[Bb]rowse/[Cc]ategory[Aa]ttribute[Ss]earch[Rr]esults.aspx.*/
// @include      https://www.trademe.co.nz/a/property/*
// @include      https://www.trademe.co.nz/browse/property/regionlistings.aspx*
// @include      https://www.trademe.co.nz/members/listings.aspx*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const KILL_PATTERN = /(Price by negotiation)|(Enquiries Over)|(To be auctioned)|(Tender)|(Deadline private treaty)|(Deadline sale)/i;
    const KILLED_LISTING_STYLES = `
        .killedlisting { background-color: #eeeeee !important; color: #999999 !important; }
        .hiddenlisting { display: none !important; }
    `;

    function addStyle(style) {
        const styleElement = document.createElement('style');
        styleElement.type = 'text/css';
        styleElement.innerHTML = style;
        document.head.appendChild(styleElement);
    }

    function hideListingBasedOnPrice() {
        const priceElements = document.querySelectorAll('.tm-property-search-card-price-attribute__price');
        console.log(`Found ${priceElements.length} price elements.`);
        priceElements.forEach((element) => {
            const priceText = element.textContent;
            const listingLinkElement = element.closest('a.tm-property-premium-listing-card__link');
            if (KILL_PATTERN.test(priceText) && listingLinkElement) {
                listingLinkElement.classList.add('killedlisting', 'hiddenlisting');
            }
        });
    }

    function waitForListingsAndExecute(callback, interval = 100, timeout = 10000) {
        const startTime = Date.now();
        const checkCondition = setInterval(function() {
            if (document.querySelector('.tm-property-search-card-price-attribute__price') || Date.now() - startTime > timeout) {
                clearInterval(checkCondition);
                console.log("Executing callback after listings detected or timeout.");
                callback();
            }
        }, interval);
    }

    addStyle(KILLED_LISTING_STYLES);

    // Use MutationObserver to dynamically observe changes in the list of properties
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.addedNodes.length) {
                console.log("Mutation observed, checking listings.");
                hideListingBasedOnPrice();
            }
        });
    });

    const config = { childList: true, subtree: true };

    // Start observing the body for changes in the DOM
    observer.observe(document.body, config);

    // Replace the setTimeout with waitForListingsAndExecute for initial check
    waitForListingsAndExecute(hideListingBasedOnPrice);
})();