Created
August 8, 2017 04:31
-
-
Save sylwit/e283531f8c5a918850976675aa5bcfa6 to your computer and use it in GitHub Desktop.
Improve UX by adding a ban feature on duproprio! POC in 30 min
This file contains hidden or 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 duproprio | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Improve UX by adding a ban feature on duproprio! POC in 30 min | |
// @author @sylwit | |
// @match https://duproprio.com/* | |
// @grant none | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let bans = JSON.parse(localStorage.getItem('bans')) || {}; | |
console.log(`${Object.keys(bans).length} properties are banned`); | |
$('.search-results-listings-list__item').each(function( index ) { | |
const item = $(this); | |
const id = item.attr('id'); | |
if (bans.hasOwnProperty(id)){ | |
item.hide(); | |
return; | |
} | |
const favorite = item.find('.search-results-listings-list__item-favourite'); | |
const ban = $("<a />", { | |
'data-ban' : id, | |
href : '#', | |
text : 'ban' | |
}); | |
favorite.prepend(ban); | |
}); | |
$("a[data-ban]").click(function (e){ | |
e.preventDefault(); | |
const id = $(this).data('ban'); | |
bans[id] = true; | |
localStorage.setItem('bans', JSON.stringify(bans)); | |
console.log(`ban ${id}`); | |
$(`#${id}`).hide(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment