Skip to content

Instantly share code, notes, and snippets.

@jeduan
Last active December 20, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeduan/6162252 to your computer and use it in GitHub Desktop.
Save jeduan/6162252 to your computer and use it in GitHub Desktop.
Busqueda de departamentos con vanilla js
(function(){
//Configuration
var colonias = 'Roma Norte,Roma Sur,Cuauhtémoc,Juárez,Del Valle Norte,Narvarte Oriente,Narvarte Poniente,Letrán Valle,Del Valle Sur,Piedad Narvarte,Del Valle Centro,San Pedro de los Pinos,Vertiz Narvarte'.split(',');
var sinBusco = true;
var util = {
$$: function(selector) {
return [].slice.call(document.querySelectorAll(selector))
},
closest: function(node, selector) {
var currentNode = node;
while (currentNode) {
if (currentNode.webkitMatchesSelector(selector)) {
return currentNode;
} else if (!currentNode || !currentNode.ownerDocument || currentNode === document.body) {
break;
}
currentNode = currentNode.parentElement;
}
return null
}
}
var Tester = function() {
this.version = 1
}
Tester.prototype.init = function() {
if (/segundamano\.(com\.)?mx/.test(document.location.host)) {
util.$$('.listing_thumbs_row').forEach(function (row) {
var extract = row.querySelector('.listing_row_extract'),
location = row.querySelector('.listing_row_location'),
extractText = extract.textContent.trim();
if (/Busco/.test(extractText) || /Comparto/.test(extractText)) {
row.style.display = 'none';
}
if (!~colonias.indexOf(location.textContent.trim())) {
row.style.display = 'none';
}
});
}
}
window['yd!'] = new Tester
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment