// ==UserScript== // @name 百度云插件+APIKey // @namespace // @version 4.2.4 beta // @description 在百度云网盘的页面添加一个搜索框,调用谷歌的搜索API搜索所有公开分享文件// To add a search frame that calls the google cse api for searching some public shared files in BaiduYun cloud netdisk. // @require http://code.jquery.com/jquery-2.1.1.min.js // @description For more imformation,please email me at wang0xinzhe@gmail.com. // @include http://pan.baidu.com/disk/* // @include https://pan.baidu.com/disk/* // @include https://yun.baidu.com/#from=share_yun_logo/ // @include http://yun.baidu.com/#from=share_yun_logo/ // @grant GM_xmlhttpRequest // @run-at document-end // @copyright 2014,04,20 __By Wang Hsin-che // @downloadURL none // ==/UserScript== var url='https://www.googleapis.com/customsearch/v1element?key=AIzaSyCVAXiUzRYsML1Pv6RwSG1gunmMikTzQqY&rsz=filtered_cse&num=10&hl=en&prettyPrint=true&source=gcsc&gss=.com&sig=ee93f9aae9c9e9dba5eea831d506e69a&cx=018177143380893153305:yk0qpgydx_e&q=';//&q=windows&start=0'; var showList=''; var totalResults=0; var frontIndex=0; var pageIndex=0; var tempNode; //根据屏幕设置div的大小位置 var myDivHeight=window.innerHeight/3*2; var myDivWidth=window.innerWidth/2; var myDivLeft=-window.innerWidth/6; var myDivTop=window.innerHeight/8; //搜索框的html var html_1='
\
'; //显示页面的html var html_2='\
\
\
\

搜索

\
\
\
\ [-->]\ [<--]\
\ '; //插入的css var cssText='\ \ '; //“搜索重置”函数 function searchClear(){ $('#wxz_myDiv').slideUp(); $(wxz_input).val(''); showList=''; tempNode=''; frontIndex=0; pageIndex=0; $('.wxz-content').empty();//清空原来的内容 console.log('clear'); } //“搜索”函数 function search(keyword){ console.log('search'); if (keyword==''){ console.log('fail'); return 1; } $('.wxz-content').html('');//显示loading条 $('#wxz_myDiv').slideDown(); GM_xmlhttpRequest({ method: "GET", url: url+keyword+'&start='+pageIndex, headers: { "User-Agent": "Mozilla/5.0", // If not specified, navigator.userAgent will be used. "Accept": "text/xml" // If not specified, browser defaults will be used. }, onload: function(response) { Data=JSON.parse(response.responseText); frontIndex=pageIndex-10; totalResults=parseInt(Data.cursor.estimatedResultCount,10);//把json数据转为html,存入缓存showlist showList="

---- by Google Custome Search

keyword is '"+keyword+"' found '"+Data.cursor.resultCount+"' Results

--------------------------------------------------

"; $.each(Data.results,function(index,element){ pageIndex++; tempNode=''+element.titleNoFormatting+''; showList+='

'+tempNode+'

'; showList+='

'+element.contentNoFormatting+'

'; }); showList+='

-------------------------------------------------------------

"'+pageIndex+'" items have been load

About me

'; $('.wxz-content').html(showList);//替换原来内容,之所以用了showlist作为缓存是为了提升速度 if(Data.cursor.resultCount==0){$('.wxz-content').html('
');}//无结果时提示 $('.wxz-content').scrollTop(0);//滚到顶端 }, onerror:function(){ $('.wxz-content').html('');//出错的图片 console.log( "error" ); } }); } function run() { $('#top_menu_other').replaceWith(html_1);//搜索栏替换了广告 $('body').append(html_2); $('head:first').append(cssText);//插入css //应用大小和页面 $('.wxz-content').height(myDivHeight); $('.wxz-myDiv').offset({ top: myDivTop, left: myDivLeft }); //绑定各种函数 $('#wxz_searchButton').click(function(){frontIndex=0;pageIndex=0;search($('#wxz_input').val());}); $('#wxz_closeButton').click(function(){searchClear();}); $('#wxz_nextPageButton').click(function(){if(pageIndex=0){pageIndex=frontIndex;search($('#wxz_input').val());}else{alert("It is the top page!");}}); $('#wxz_input').keyup(function(event){if(event.which==13){$('#wxz_searchButton').trigger('click');}}); } //百度云把一些内容放到后面加载,导致到$.(document ).ready ();$.(window ).load();window.addeventhandle ()等函数在firefox或者chrome下不起作用,只能用window.onload(); //window.onload = function() { // run(); // }; var t=window.setInterval(function(){//百度云把一些内容放到后面加载,因此我设置了一个延时循环,每隔100ms选择一下所需的元素,当所需的元素存在时,开始脚本,同时停止延时循环 if($('#top_menu_other').length>0){ run(); window.clearInterval(t); } console.log('waiting'); },100);