Skip to content

Instantly share code, notes, and snippets.

@twlz0ne
Last active December 27, 2015 07:19
Show Gist options
  • Save twlz0ne/7288598 to your computer and use it in GitHub Desktop.
Save twlz0ne/7288598 to your computer and use it in GitHub Desktop.
福州豆瓣租房团小组书签
var group = new (function() {
var foo = function() {
var recruit = new Array(); //招租
var recruit_roommate = new Array(); //招合租
var wanted = new Array(); //求租
var wanted_roomate = new Array(); //求合租
var others = new Array(); //其他
for (var i = 0; i < 5; i++) {
$.ajax({type : 'get',
url : 'http://www.douban.com/group/463347/discussion?start=' + (i * 25),
async : false,
success : function(data, status, xhr) {
var trs = $(data).find('table[class="olt"]>tbody>tr');
for (var idx = 0; idx < trs.length; idx++) {
var tr = trs[idx];
var $td = $(tr).find('td[class="title"]');
if ($td.length) {
if ($td.find('a').attr('title').indexOf('【招合租') !== -1) {
var ary = recruit_roommate;
} else if ($td.find('a').attr('title').indexOf('【求合租') !== -1) {
var ary = wanted_roomate;
} else if ($td.find('a').attr('title').indexOf('【招租') !== -1) {
var ary = recruit;
} else if ($td.find('a').attr('title').indexOf('【求租') !== -1) {
var ary = wanted;
} else {
var ary = others;
}
ary.push(new Array(
$td.find('a').attr('title'),
$td.find('a').attr('href'),
$td.next().find('a').text(),
$td.next().find('a').attr('href'),
$td.next().next().text(),
$td.next().next().next().text()
));
}
}
} // success
});
};
inner_div = '<div id="inner_div" style="display:block; top:0px; position:absolute; width:100%; background:rgba(25, 25, 25, .8); z-index:9999;">';
var for_each = function(ary) {
var div = ''
if (ary.length > 0) {
div += '<div style="width:800px; margin-right: auto;margin-left: auto; background:white">';
div += '<table class="olt"><thead style="background-color:#ECF3EF;"><tr><td></td><td></td><td></td><td></td><td></td></tr></thead><tbody>';
for (var j = 0; j < ary.length; j++) {
// 序号
div += '<tr class>';
div += '<td nowrap="nowrap" class="">&nbsp;' + j + '</td>';
// 标题
div += '<td class="title"><a target="_blank" href="' + ary[j][1]
+ '" title="' + ary[j][0]
+ '" class>' + ary[j][0]
+ '</a></td>';
// 作者
div += '<td nowrap="nowrap"><a target="_blank" href="' + ary[j][3]
+ '" class="">' + ary[j][2]
+ '</a></td>';
// 回应
div += '<td nowrap="nowrap" class="">' + (ary[j][4] == '' ? '0' : ary[j][4]) + '</td>';
// 时间
div += '<td nowrap="nowrap" class="">' + ary[j][5] + '</td>';
div += '</tr>';
}
div += '</table></tbody>';
div += '</div>';
}
return div;
};
inner_div += for_each(recruit_roommate);
inner_div += for_each(wanted_roomate);
inner_div += for_each(recruit);
inner_div += for_each(wanted);
inner_div += for_each(others);
inner_div += '<div id="close_div" style="width:800px; margin-right: auto;margin-left: auto; height:20px; background:gray;" align="center"><b>关&nbsp闭</b></div>';
inner_div += '</div>';
var outer_div = document.getElementById('outer_div');
if (outer_div == null) {
outer_div = '<div id="outer_div"></div>';
$(document.getElementsByTagName('body')).append(outer_div);
}
outer_div = document.getElementById('outer_div');
$(outer_div).html(inner_div);
$(outer_div).show();
// reset inner_div height to fill full screen
if ($('#inner_div').height() < document.height) {
$('#inner_div').height(document.height);
}
$('#close_div').live('click', function(event){
$('#outer_div').hide();
});
};
return {
foo : foo,
};
})();
group.foo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment