Skip to content

Instantly share code, notes, and snippets.

@parisni
Last active September 25, 2023 20:43
Show Gist options
  • Save parisni/4735282c86822b54a9c7a29980dfadd1 to your computer and use it in GitHub Desktop.
Save parisni/4735282c86822b54a9c7a29980dfadd1 to your computer and use it in GitHub Desktop.
vinted
// ==UserScript==
// @name Vinted RSS
// @namespace https://gist.github.com/parisni/4735282c86822b54a9c7a29980dfadd1
// @author parisni
// @description A kind of RSS for Vinted with your personnal search
// @include https://www.vinted.fr/*
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @require https://raw.githubusercontent.com/eligrey/FileSaver.js/master/dist/FileSaver.min.js
// @version 1.1
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_xmlhttpRequest
// @grant window.close
// @grant window.focus
// ==/UserScript==
/*
Have fun with the config variable !
*/
function buildRss(title, date, posts){
return `<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<id>${title}</id>
<title>${title}</title>
<updated>${date}</updated>
<logo>https://static.vinted.com/assets/web-logo/default/logo.svg</logo>
<subtitle>Vinted search feed</subtitle>
${buildRssItems(date, posts)}
</feed>`;
}
function buildRssItems(date, items) {
return items
.map((item) => {
return `
<entry>
<id>${item.link}</id>
<title>${item.title}</title>
<link href="${item.link}" rel="alternate"/>
<content type="xhtml"><div>${item.descr}</div></content>
<updated>${date}</updated>
</entry>`;
})
.join("");
}
$(function(){
if (window.top !== window.self) { //prevent running in iframes
return;
}
var lbcUrl = document.location.href
GM_xmlhttpRequest({ //allow CORS
method: "GET",
url: lbcUrl,
onload: function(data) {
// remove ads before scrapping
var rm = document.getElementsByClassName("feed-grid__item--full-row")
for (let i = 0; i < rm.length; i++) {
rm[i].remove()
}
// no scrap
var a = document.getElementsByClassName("new-item-box__container")
console.log(a)
var b = document.getElementsByClassName("new-item-box__overlay")
console.log(b)
var content = []
for (let i = 0; i < b.length; i++) {
console.log(b[i].getAttribute("title"));
console.log();
var title = b[i].getAttribute("title");
var link = b[i].getAttribute("href");
var descr = a[i].innerText;
content.push({'link': link, 'title': title, 'descr': descr})
}
if(content.length!==0){
var blob = new Blob([buildRss(lbcUrl, new Date(Date.now()).toISOString(), content)], {type: "text/plain;charset=utf-8"});
saveAs(blob, "atom.xml")
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment