');
var data = {
cursor: {
estimatedResultCount: 0,
resultCount: 0
},
results: []
},
rbJquery = $(html.slice(begin, end)).find('.rb');
$.each(rbJquery, function(index, val) {
if (index === 0) {
data.cursor.resultCount = parseInt($(val).find('em').text().replace(',', ''), 10);
data.cursor.estimatedResultCount = data.cursor.resultCount;
} else {
var tempResult = {
unescapedUrl: "",
titleNoFormatting: "",
contentNoFormatting: ""
};
tempResult.unescapedUrl = $(val).find("h3 a").attr('href');
tempResult.titleNoFormatting = $(val).find("h3 a").text();
tempResult.contentNoFormatting = $(val).find('div.ft').text();
data.results.push(tempResult);
}
/* iterate through array or object */
});
return data;
}
function repiguToData(html) {
// var begin = html.search('
'),
// end = html.search('
');
var data = {
cursor: {
estimatedResultCount: 0,
resultCount: 0
},
results: []
},
rbJquery = $(html).find('.g');
data.cursor.resultCount = parseInt($(html).find('#resultStats').text().slice(4).replace(',', ''), 10);
data.cursor.estimatedResultCount = data.cursor.resultCount;
$.each(rbJquery, function(index, val) {
var tempResult = {
unescapedUrl: "",
titleNoFormatting: "",
contentNoFormatting: ""
};
tempResult.unescapedUrl = "https://repigu.com"+$(val).find("h3 a").attr('href');
tempResult.titleNoFormatting = $(val).find("h3 a").text();
tempResult.contentNoFormatting = $(val).find('.st').text();
data.results.push(tempResult);
/* iterate through array or object */
});
return data;
}
function pageBar(page, totalPage) {
var
html = '\
\
',
pageNodeHtml = '',
i, c,
startPage = 10 * parseInt((page - 1) / 10, 10) + 1;
$('#wxz-pagese').replaceWith(html);
c = $('#wxz-pagese').find('.page-content').eq(0);
for (i = 0; i < 10; i++) {
if (i + startPage > totalPage) {
break;
}
if (i + startPage === page) {
$(pageNodeHtml).html(i + startPage).addClass('global-disabled').appendTo(c);
} else {
$(pageNodeHtml).html(i + startPage)
.bind('click', {
msg: i + startPage
}, function(e) {
search(keyword, (e.data.msg - 1) * 10);
})
.appendTo(c);
}
}
if (page <= 1) {
$('#wxz-pagese').find('.page-prev').eq(0).addClass('global-disabled');
} else {
$('#wxz-pagese').find('.page-prev').eq(0).bind('click', {
msg: page - 1
}, function(event) {
search(keyword, (event.data.msg - 1) * 10);
});
}
if (page >= totalPage) {
$('#wxz-pagese').find('.page-next').eq(0).addClass('global-disabled');
} else {
$('#wxz-pagese').find('.page-next').eq(0).bind('click', {
msg: page + 1
}, function(event) {
search(keyword, (event.data.msg - 1) * 10);
});
}
html = null;
pageNodeHtml = null;
i = null;
c = null;
startPage = null;
}
function setUI() {
//根据屏幕设置div的大小位置
var
html_1 = '\
',
//显示页面的html
html_2 = '\
\
',
html_4='\
\
'+flag+'\
\
\
',
cssText = '\
\
';
switch (replaceEle) {
case '#top_menu_other':
$('div.info.clearfix ul').prepend(html_1);//切换按钮
$(replaceEle).remove(); //删除搜索栏了广告
// $('div.info.clearfix ul').prepend(html_1);//搜索按钮
break;
case 'div.remaining':
$(replaceEle).before(html_1);
$('#wxz_searchForm').addClass('side-options');
$('#wxz_searchButton').css({
width: 40
});
break;
}
$('div.info.clearfix ul').prepend(html_4);//切换按钮
$('body').append(html_2);
$('head:first').append(cssText); //插入css
//应用大小和页面
$('.wxz-content').css({
height: window.innerHeight / 3 * 2
});
$('#wxz_myDiv').css({
top: window.innerHeight / 8,
left: window.innerWidth / 4
});
//应用拖拽
$("#wxz_myDiv").draggable({
handle: "#wxz_myDiv_title"
});
}
function bind() {
//绑定各种函数
$('#wxz_searchButton').click(function() {
keyword = $('#wxz_input').val();
search(keyword, 0);
});
$('#wxz_closeButton').click(function() {
searchClear();
});
$('.li.wxz-menu-option').click(function(){
flag=$(this).attr('data-key');
$('#wxzMenuDisplay').text(flag);
$('.wxz-menu-content').hide();
});
$('#wxz_input').keyup(function(event) {
if (event.which == 13) {
$('#wxz_searchButton').trigger('click');
}
});
} return {
init: function(option) {
var
t = window.setInterval(function() { //百度云把一些内容放到后面加载,因此我设置了一个延时循环,每隔100ms选择一下所需的元素,当所需的元素存在时,开始脚本,同时停止延时循环
if ($(replaceEle).length > 0) {
window.clearInterval(t);
flag = option;
setUI();
bind();
}
console.log('waiting');
}, 100);
},
};
};
//根据屏幕分辨率选择替换的元素
var ele = (window.innerWidth > 1024 ? '#top_menu_other' : 'div.remaining');
//启动
SearchObject(jQuery, ele).init('Repigu'); //to use original google, please replace parameter with 'Google';
\