Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sacah/49cb7073605513af76a1 to your computer and use it in GitHub Desktop.
Save sacah/49cb7073605513af76a1 to your computer and use it in GitHub Desktop.
Greasemonkey script for RealEstate.com.au - Hide previously viewed properties
// ==UserScript==
// @name Realestate.com.au hide previously viewed properties
// @namespace http://www.sacah.net
// @include http://www.realestate.com.au/*
// @version 1
// @grant none
// @license None
// ==/UserScript==
/* Clear saved results with
localStorage.setItem('viewedProps', '');
*/
function override(object, method, callback) {
object[method]=callback(object[method])
}
override(LMI.CORS, 'CORSRequest', function(creq) {
return function () {
override(arguments[2], 'success', function(success) {
return function (xhr) {
var data=JSON.parse(xhr.response);
if(data.tieredResults) {
var viewedProps=localStorage.getItem('viewedProps') || '';
viewedProps=viewedProps.split(',');
function removeSeen(propList) {
var tmp=[];
for(var a=0, len=propList.results.length; a<len; a++) {
if(viewedProps.indexOf(propList.results[a].listingId)==-1) {
tmp.push(propList.results[a]);
viewedProps.push(propList.results[a].listingId);
}
}
propList.results=tmp;
propList.count=tmp.length;
return propList;
}
var total=0;
for(var a=0, len=data.tieredResults.length; a<len; a++) {
data.tieredResults[a]=removeSeen(data.tieredResults[a]);
total+=data.tieredResults[a].count;
}
localStorage.setItem('viewedProps', viewedProps.join(','));
data.totalResultsCount=total;
var newXhr={};
for(var a in xhr) newXhr[a]=xhr[a];
newXhr.response=newXhr.responseText=JSON.stringify(data);
} else newXhr=xhr;
success.apply(this, [newXhr]);
}
});
creq.apply(this, arguments);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment