百度云插件+APIKey

在百度云网盘的页面添加一个搜索框,调用谷歌的搜索API搜索所有公开分享文件// To add a search frame that calls the google cse api for searching some public shared files in BaiduYun cloud netdisk.

As of 17.08.2014. See ბოლო ვერსია.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name       百度云插件+APIKey
// @namespace  
// @version    4.2.5 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 [email protected]. 
// @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   
// ==/UserScript==

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// my custom jquery draggable plugin//////////////////////////////////////////////////////////////////////////////
// by Wang Hsin-che @ 2014.07 
// version : 0.1
// usage: $("#element").draggable({handle:"#childElement"});  or $("#element").draggable(); 

(function ( $ ) {
var x0,y0,ele,setting;
$.fn.draggable = function(option) {
setting=$.extend({handle:this.selector},option);//deal with the "handle" parameter,default is the selector
this.css({position:"absolute"});//make sure that the "postion" is "absolute"
ele=this;//save the selector 
$(setting.handle).bind('mousedown',function(e0){
	$(setting.handle).css({cursor:"move"});//set the appearance of cursor 
	x0=ele.offset().left-e0.pageX;//*1
	y0=ele.offset().top-e0.pageY;//*1
	$(document).bind('mousemove',function(e1){//bind the mousemove event, caution:this event must be bind to "document"
		$(document).bind('mouseup',function(){//when the mouse up,unbind the mousemove event
			$(document).unbind('mousemove');
			$(setting.handle).css({cursor:"auto"});
		});
		ele.css({left:x0+e1.pageX,top:y0+e1.pageY});//this expression and the expression of *1 equal to "ele.origin_offset+mouse.current_offset-mouse.origin_offset"
	});
});

return this;
};
}( jQuery ));
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



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='<div class="search-form"><input class="search-query" placeholder=" 搜索公开分享文件" id="wxz_input">\
			<input type="button" value="GO" class="search-button" id="wxz_searchButton"></div>';
//显示页面的html

var html_2='\
<div class="b-panel b-dialog share-dialog" id="wxz_myDiv">\
<div class="dlg-hd b-rlv" id="wxz_myDiv_title">\
<div title="关闭" id="wxz_closeButton" class="dlg-cnr dlg-cnr-r"></div>\
<h3 >搜索</h3>\
</div>\
<div class="wxz-content">\
</div>\
<div class="offline-bottom">\
<div class="offline-pageing">\
<div class="pagese " id="wxz-pagese">\
<a href="javascript:void(0)" class="page-prev  "id="wxz_frontPageButton">上一页</a>\
<a href="javascript:void(0)" class="page-next " id="wxz_nextPageButton">下一页</a>\
</div>\
</div>\
</div>\
</div>\
';

//插入的css
var cssText='\
<style type="text/css">\
	#wxz_searchButton{background-image:none;cursor:pointer;background-color: rgb(155, 154, 154);color: #ffffff;}\
		.wxz-myDiv{display:none;z-index:99;box-shadow:0 0 9px rgba(0,0,0,.9);background:#FFFFFF;position:absolute;outline:0 none;}\
		.wxz-content{line-height: 200%;text-align: left;white-space: normal;margin-left:20px;overflow:auto;}\
		.wxz-close{margin-right:20px;important;height:20px;cursor:pointer}\
		.wxz-next{margin-right:20px;float:right;height:20px;cursor:pointer}\
		.wxz-front{margin-right:40px;float:right;height:20px;cursor:pointer}\
		.wxz-content a{color:#0066FF!important;font: 14px/1.5 arial,sans-serif!important;}\
</style>\
				';



//“搜索重置”函数
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('<img src=http://www.scienceq.org/images/loading_pdf.gif>');//显示loading条
	$('.wxz-content').html('<img src="data:image/gif;base64,R0lGODlhJgJuAcQQAP+KACFMdlx8m5erv8TP2jBYf9Pb5E1wkaa3yLXD0T9kiImgtmuIpHqUrfDz9v///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFMgAQACwAAAAAJgJuAQAF/+AjjmRpnmiqrmzrvnAsz3Rt33iu73zv/8CgcEgsGo/IpHLJbDqf0Kh0Sq1ar9isdsvter/gsHhMLpvP6LR6zW673/C4fE6v2+/4vH7P7/v/gIGCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+goaKjpKWmp6ipqqusra6vsLGys7S1tre4ubq7vL2+v8DBwsPExcbHyMnKy8zNzs/Q0dLT1NXW19jZ2tvc3d7f4OH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z4AC4PbjkgEc+eeWUnyA45px3bsLmmlseev/fhF8+uumfi3766qyXAHrqqMPuueytTwZ55rTXPsLrrqveO+6/x04C78P7Xjzwxz9e+uzJM7+78c3nLn300z+PvPXCY2/Z7dmLQLz21YMfvPPeQy8+9eOHX373kHFP/gPfr/8+/ObTf73878dv//zx6++Y+7rDXwD3l7/6EVB9B0yf+vTXPwP+b3mhY9zi8DZBvVWQbxc0XAYRt0HFbQ+CqZNg5UQYQQqO0IQltOAJVZhCDI7thTCMoQxnSMMa2vCGOMyhDnfIwx768IdADKIQh0jEIhrxiEhMohKXyMQmOvGJUIyiFKdIxSpa8YpYzKIWt8jFLnrxi2AMoxjHSMaWMprxjGhMoxrXyMY2uvGNcIyjHOdIxzra8Y54zKMe98jHPvrxj4AMpCAHSchCGvKQiEykIhfJyEY68pGQjKQkJ0nJSlrykpjMpCY3yclOevKToAylKEdJylKa8pSoTKUqV8nKVrrylbCMpSxnScta2vKWuMylLnfJy1768pfADKYwh0nMYhrzmMhMpjKXycxmOvOZaAgBACH5BAUyABAALNgAxgAJAAcAAAUKICCOZGmeaKqiIQAh+QQFMgAQACzvAMYACQAHAAAFCiAgjmRpnmiqoiEAIfkEBTIAEAAsBgHGAAkABwAABQogII5kaZ5oqqIhACH5BAUyABAALB0BxgAJAAcAAAUKICCOZGmeaKqiIQAh+QQFMgAQACw0AcYACQAHAAAFCiAgjmRpnmiqoiEAIfkEBTIAEAAsSwHGAAkABwAABQogII5kaZ5oqqIhACH5BAUyABAALGIBxgAJAAcAAAUKICCOZGmeaKqiIQA7" />');//显示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
				if(Data.cursor.resultCount==0){
					$('.wxz-content').html('<div align="center"><img  src=http://blog.fpweb.net/media/2011/11/No-Search-Results-325x287.png></div>');
					}//无结果时提示
				else{
					showList="<p align='right'>---- by Google Custome Search </p><p white-space='normal' class='temp' >keyword is    '"+keyword+"'    found  '"+Data.cursor.resultCount+"'  Results</p><p>--------------------------------------------------<p>";
					$.each(Data.results,function(index,element){
						pageIndex++;
						tempNode='<a href="'+element.unescapedUrl+'"target="_blank">'+element.titleNoFormatting+'</a>';
						showList+='<p><p class="myTitle">'+tempNode+'</p>';
						showList+='<p class="mySnippet">'+element.contentNoFormatting+'</p>';
						});				
					showList+='<p><p>-------------------------------------------------------------<p class="temp" margin-left="20px">"'+pageIndex+'"  items have been load </p><p align="right"><a href="javascript:alert('+"'By WangHsinche @ 2014.04'"+')" ><font color="#333">About me</font></a></p>';
					$('.wxz-content').html(showList);//替换原来内容,之所以用了showlist作为缓存是为了提升速度
					$('.wxz-content').scrollTop(0);//滚到顶端
				}
			  },
			  onerror:function(){
				$('.wxz-content').html('<img src=http://icongal.com/gallery/image/297514/cancel_quit_terminate_exit_error_close_delete.png>');//出错的图片
				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-content').css({height:myDivHeight});
    $('.wxz-myDiv').css({ top: myDivTop, left: myDivLeft });
	  $("#wxz_myDiv").draggable({handle:"#wxz_myDiv_title"});

    //绑定各种函数
    $('#wxz_searchButton').click(function(){frontIndex=0;pageIndex=0;search($('#wxz_input').val());});
    $('#wxz_closeButton').click(function(){searchClear();});
    $('#wxz_nextPageButton').click(function(){if(pageIndex<totalResults){search($('#wxz_input').val());}else{alert("It is the last page!");}});
    $('#wxz_frontPageButton').click(function(){if(frontIndex>=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);