Last active
August 2, 2023 11:00
-
-
Save allquest/fb7b790fb6548bdec3ec5259bebd20c0 to your computer and use it in GitHub Desktop.
Greasemonkey script for LeBonCoin - A kind of RSS for the website Le bon coin with your query -- each time you reload a page, a GET request is sent to lbc and match your query. If a new offer is available, the link is shown on the top of the page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Leboncoin RSS | |
// @namespace http://gist.github.com/fb7b790fb6548bdec3ec5259bebd20c0 | |
// @author Tegomass | |
// @description A kind of RSS for LeBonCoin with your personnal search | |
// @include * | |
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js | |
// @version 1.1 | |
// @grant GM_addStyle | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
/* | |
Have fun with the config variable ! | |
*/ | |
$(function(){ | |
if (window.top !== window.self) { //prevent running in iframes | |
return; | |
} | |
var config = { | |
query : 'rx100', //the query | |
nbProduct : 3, //number of product to check | |
displayDay : 2, //number of day you want the news to be displayed | |
region : 'ile_de_france', //region of the offer | |
showLogInConsole : true //show log of products matched in the console | |
}; | |
GM_addStyle('#tegodiv { background-color: white; opacity: 0.8; position: fixed; top:0; left:0; font-size:12px; z-index: 999999;}\ | |
#tegodiv span {display: block; color: black;}'); | |
var lbcUrl = 'https://www.leboncoin.fr/annonces/offres/'+config.region+'/?th=1&q='+config.query; | |
var daySaved = Math.floor(Date.now() / 86400000); //get timestamp in DAY | |
$('body').append('<div id="tegodiv"><a href="'+lbcUrl+'" id="tegoclick">rx100</a></div>'); | |
GM_xmlhttpRequest({ //allow CORS | |
method: "GET", | |
url: lbcUrl, | |
onload: function(data) { | |
$('#listingAds', data.response).find('li:lt('+config.nbProduct+')').each(function(){ | |
var title = $.trim($(this).find('h2.item_title').text()); | |
var link = $(this).find('a.list_item').attr('href'); | |
if (GM_getValue(title) == undefined){ //if entry doesn't exist | |
console.log('NEW detected!'); | |
GM_setValue(title, daySaved); | |
} | |
var entry = GM_getValue(title); | |
if (entry+config.displayDay > daySaved ) {//delay the display for +2days | |
$('#tegodiv').append('<span><a href="'+link+'">'+title+'</a> <a href="#" class="tegodelete">[x]</a></span>'); | |
} | |
$('.tegodelete').one('click', function(e){ | |
e.preventDefault(); | |
$target = $(this).prev('a'); | |
GM_setValue(title, 0); //set the timestamp to 0 | |
$(this).remove(); | |
$target.remove(); | |
}) | |
if (config.showLogInConsole){ | |
console.log(title); | |
} | |
}); | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment