Created
April 8, 2013 07:36
-
-
Save bxshi/5334933 to your computer and use it in GitHub Desktop.
58_house_renting_filter
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 58.com Filter | |
// @namespace http://use.i.E.your.homepage/ | |
// @version 0.1 | |
// @description For my girlfriend | |
// @include http://bj.58.com/hezu/* | |
// @copyright 2012+, You | |
// ==/UserScript== | |
//Constants | |
// a function that loads jQuery and calls a callback function when jQuery has finished loading | |
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); | |
} | |
var main = function () { | |
var getPhoneUsage = function(i, url2Phone){ | |
GM_xmlhttpRequest({ | |
method: "GET", | |
url: url2Phone, | |
onload: function (response) { | |
console.log ( response.status, | |
response.responseText.substring (0, 80) | |
); | |
} | |
}); | |
}; | |
var getInfomation = function(i, detailPage){ | |
$.get(detailPage, function(data) { | |
try{ | |
var location = data.match(/出 租 间[^所在区域]*/gi).toString().match(/[朝|向|东|南|西|北]+/gi).toString(); | |
}catch(e){} | |
try{ | |
var phone = data.match(/http:\/\/image.58.com\/showphone.aspx[^\']*/gi)[0].toString(); | |
}catch(e){} | |
try{ | |
var agent = data.match(/dianpuurl/gi)!=null; | |
}catch(e){} | |
try{ | |
var phoneUsage = data.match(/http:\/\/my.58.com\/mobileposthistory\/[^"]*/gi).toString().replace(/amp;/gi,''); | |
getPhoneUsage(i, phoneUsage); | |
}catch(e){} | |
if(location){ | |
$(contentColumns[i]).append('<td>'+location+'</td>'); | |
} | |
if(phone){ | |
$(contentColumns[i]).append('<td>'+'<img src=\''+phone+'\' />' +'</td>'); | |
} | |
if(agent){ | |
$(contentColumns[i]).parent().hide(); | |
} | |
//TODO 厨房设备 | |
}); | |
}; | |
var DISTANCE_THRESHOLD = 1500; | |
//Get td of valid columns | |
var contentColumns = $('tbody tr td.t:not([style])'); | |
var detailPages = []; | |
for (var i = 0; i < contentColumns.length; i++) { | |
// Check if it fits the needs of distance | |
var LenStr = $(contentColumns[i]).html().match(/约[0-9]+米/gi).toString(); | |
LenStr = parseInt(LenStr.substring(1, LenStr.length - 1)); | |
if (LenStr < DISTANCE_THRESHOLD) { | |
//Highlight text | |
$(contentColumns[i]).html( | |
'<span style="background: #FFFF99;">' + | |
$(contentColumns[i]).html().replace(/约[0-9]+米/gi, | |
'约'+'<span style="font-size: 20pt; color: red">'+LenStr+'</span>'+'米') | |
+ '</span>'); | |
} | |
//Get infomations about house | |
detailPages[i] = $(contentColumns[i]).find('a.t').attr('href'); | |
getInfomation(i, detailPages[i]); | |
} | |
}; | |
addJQuery(main); | |
//Run script after page loaded | |
// addEventListener('DOMContentLoaded', addJQuery(main), false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment