Lebonscrap

Usage privé pour Thomas

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Lebonscrap
// @namespace    http://tampermonkey.net/
// @version      3.04
// @description  Usage privé pour Thomas
// @author       Thomas
// @match        https://www.leboncoin.fr/*
// @icon         https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://leboncoin.fr&size=64
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @require https://code.jquery.com/ui/1.14.0/jquery-ui.min.js
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var lastLbcAnnoncesArray = [];
    var audioElement = "";
    var sound = false;
    var theme_main_color = "#ec5a13";
    var theme_grey_color = "#bbbbbb";
    var refreshDelay = 5;
    var effetDuBoutonDuTemps = 2;
    var autorefresh = false;
    // var notify_sound_url = 'https://directory.audio/media/fc_local_media/audio_preview/pending-notification.mp3';
    var notify_sound_url = 'https://directory.audio/media/fc_local_media/audio_preview/quick-bubble-pop2.mp3';

    function switchSound(){
        sound = !sound;
        if(sound){
            $('#switchSound').removeClass('scriptButtonDisabled');
        }
        else {
            $('#switchSound').addClass('scriptButtonDisabled');
        }
    }
    function switchAutorefresh(){
        autorefresh = !autorefresh;
        if(autorefresh){
            $('#switchAutorefresh').removeClass('scriptButtonDisabled');
        }
        else {
            $('#switchAutorefresh').addClass('scriptButtonDisabled');
        }
    }

    function refreshLbc(){
        updateDelayCounter();
        $('.h-2xl').trigger('click');


        cleanLeboncoin();
        deletePremiumPosts();



        var firstAnnonce = $('article[data-qa-id]').first().attr("aria-label"); // Selectionne le titre de la première annonce affichée
        if(lastLbcAnnoncesArray.indexOf(firstAnnonce) === -1){
            if(lastLbcAnnoncesArray.length !== 0){
                // Nouvelle annonce détectée
                if(sound){
                    audioElement.play();
                    annoncerObjet(firstAnnonce);
                }
            }

            lastLbcAnnoncesArray.push(firstAnnonce);
            console.log("Enregistré: "+firstAnnonce);
        }

    }

    function annoncerObjet(titre){
        if ('speechSynthesis' in window) {
            var msg = new SpeechSynthesisUtterance(titre);
            window.speechSynthesis.speak(msg);
        }
    }

    function debug(){
        cleanLeboncoin();
    }

    function cleanLeboncoin(){
        $('h1:first-child').hide();
        $('.py-md:first-child').hide(); // Barre de recherche
        $('div[data-test-id="add-category-banner"]').hide();
    }

    function EditDomLbc(){

        $('<span id="scriptOverlay"></span>').insertAfter('nav:eq(0)');


        $( "#scriptOverlay" ).append( $('<span id="removeToTimer" style="position: absolute;top: 0;left: 0;" class="scriptButton scriptButtonSmall">-'+effetDuBoutonDuTemps+'s</span>') );
        $( "#scriptOverlay" ).append( $('<span id="addToTimer" style="position: absolute;top: 0;right: 0;" class="scriptButton scriptButtonSmall">+'+effetDuBoutonDuTemps+'s</span>') );
        $( "#scriptOverlay" ).append( $('<span class="scriptButton scriptButtonDisabled"><span id="refreshCountdown">'+refreshDelay+'</span></span>') );
        $( "#scriptOverlay" ).append( $('<span id="switchSound" class="scriptButton '+((sound)?'':'scriptButtonDisabled')+'">Son</span>') );
        $( "#scriptOverlay" ).append( $('<span id="switchAutorefresh" class="scriptButton '+((autorefresh)?'':'scriptButtonDisabled')+'"><span class="turnOn">Stop</span><span class="turnOff">Lancer</span></span>') );
        $( "#scriptOverlay" ).append( $('<span id="manualRefresh" class="scriptButton">Refresh</span>') );
        $( "#scriptOverlay" ).append( $('<span id="debugButton" class="scriptButton">Debug</span>') );
        $('.styles_Listing__isoog').css('margin-top', '-150px');

        var style = $('<style>article:has(.bg-accent){display: none;} #switchAutorefresh .turnOff, #switchAutorefresh .turnOn {display: none;} #switchAutorefresh.scriptButtonDisabled .turnOff, #switchAutorefresh .turnOn {display: block !important;} #switchAutorefresh.scriptButtonDisabled .turnOn {display: none !important;}         #scriptOverlay { position: fixed;left: 50px;top:80px; z-index: 999999;background: #000000c7; border-radius: 5px; padding: 30px 10px; cursor: move;} .scriptButtonDisabled {background: '+theme_grey_color+' !important;}  .scriptButton { background: '+theme_main_color+';font-size: 30px;padding: 5px;cursor: pointer;text-align:center; min-width: 120px;border-radius: 5px; margin: 5px; display: block; } .scriptButtonSmall {padding: 0px 8px; min-width: 1px; font-size: 15px; display: inline;}</style>');
        $('html > head').append(style);

        $('#scriptOverlay').draggable();

    }

    function deletePremiumPosts(){
        $('article').each(function(index){
            if($(this).has('.bg-accent').length > 0 ){
                $(this).remove();
            }
        });
        return;

    }


    function updateDelayCounter(){
        $('#refreshCountdown').text(refreshDelay);
    }

    function init(){

        audioElement = document.createElement('audio');
        // audioElement.setAttribute('src', 'https://directory.audio/media/fc_local_media/audio_preview/pending-notification.mp3');
        audioElement.setAttribute('src', notify_sound_url);

        cleanLeboncoin();
        EditDomLbc();
        deletePremiumPosts();
    }

    window.addEventListener('load', function() {

        init();

        setInterval(function(){
            var timer = parseInt($('#refreshCountdown').text());
            if(autorefresh){
                timer = timer -1;
                if(timer == 0){
                    timer = refreshDelay;
                    refreshLbc();
                }
                else {
                    $('#refreshCountdown').text(timer);
                }

            }

        }, 1000);

        $(document).on('click', '#switchSound', function(){
            switchSound();
        });
        $(document).on('click', '#switchAutorefresh', function(){
            switchAutorefresh();
        });
        $(document).on('click', '#manualRefresh', function(){
            refreshLbc();
        });

        $(document).on('click', '#debugButton', function(){
            debug();
        });
        $(document).on('click', '#addToTimer', function(){
            refreshDelay += effetDuBoutonDuTemps;
            updateDelayCounter();
        });
        $(document).on('click', '#removeToTimer', function(){
            refreshDelay -= effetDuBoutonDuTemps;
            if(refreshDelay <= 0 ){
                refreshDelay = 1;
            }
            updateDelayCounter();
        });




    }, false);

})();