Created
July 1, 2013 08:57
-
-
Save james/5899389 to your computer and use it in GitHub Desktop.
Userscript to add price per bedroom in rightmove.co.uk search results.
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 Right Move Price per Bedroom | |
// @version 0.1.4 | |
// @namespace abscond | |
// @include http://*rightmove.co.uk/*/find* | |
// ==/UserScript== | |
function addJQuery(callback) { | |
var script = document.createElement("script"); | |
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); | |
script.addEventListener('load', function() { | |
var script = document.createElement("script"); | |
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();"; | |
document.body.appendChild(script); | |
}, false); | |
document.body.appendChild(script); | |
} | |
// the guts of this userscript | |
function main() { | |
$('ol#summaries > li').each(function(i, el) { | |
var price_el = $(el).find('.price'); | |
var price = parseInt(price_el.html().replace(/\D/g, "")); | |
var bedrooms = parseInt($(el).find('.bedrooms span:first').html().charAt(0)); | |
var price_per_bed = Math.round(price/bedrooms); | |
price_el.html(price_el.html() + " (£" + price_per_bed + " per bed)"); | |
}); | |
} | |
// load jQuery and execute the main function | |
addJQuery(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment