// ==UserScript== // @name 百度云插件+APIKey // @namespace // @version 4.4.4.1 beta // @description 在百度云网盘的页面添加一个搜索框,调用搜索API搜索所有公开分享文件// To add a search frame that calls some 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== ////////////////////////////////////////////////////////////////////// /////jQuery draggable plugin v0.2 by Wang Hsin-che @ 2014 08/////////////// /////usage: $(selector).draggable({handel:'handle',msg:{},callfunction:function(){}}); ////////////////////////////////////////////////////////////////////// (function($) { $.fn.draggable = function(options) { var settings = $.extend({ handle: undefined, msg: {}, callfunction: function() {} }, options); var _eleFunc = function() { var x0, y0, ele = $(this), handle; handle = (settings.handle === undefined ? ele : ele.find(settings.handle).eq(0) === undefined ? ele : ele.find(settings.handle).eq(0)); ele.css({ position: "absolute" }); //make sure that the "postion" is "absolute" handle.bind('mousedown', function(e0) { 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" 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" }); $(document).one('mouseup', settings.msg, function(e) { //when the mouse up,unbind the mousemove event,bind only once settings.callfunction(e); //callback function $(document).unbind('mousemove'); handle.css({ cursor: "auto" }); }); }); // 從這裡開始 }; return this.each(_eleFunc); }; })(jQuery); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// ////// /////定义 var SearchObject = function($, replaceEle) { var keyword = '', flag = '', info = 'Created by Wang Hsin-che @ 2014 04. The current version is 4.4.4.1'; function searchClear() { $('#wxz_myDiv').slideUp(); $('#wxz_input').val(''); keyword = ''; $('.wxz-content').empty(); //清空原来的内容 console.log('clear'); } function search(keyword, startIndex) { var url; if (keyword === '') { console.log('fail'); return 0; } console.log('search'); switch (flag) { case 'Bing': url = 'http://cn.bing.com/search?q=';//http://cn.bing.com/search?q=rk3368+site:pan.baidu.com;ie=utf-8 url = url + keyword + '+site%3Apan.baidu.com' + '&first=' + startIndex; break; case 'repigu': url = 'https://repigu.com/uds/GwebSearch?rsz=filtered_cse&hl=zh_CN&cx=018177143380893153305:yk0qpgydx_e&v=1.0&key=AIzaSyCVAXiUzRYsML1Pv6RwSG1gunmMikTzQqY&q='; url = url + keyword + '&start=' + startIndex; break; case 'Repigu': url = 'https://repigu.com/search?q='; url = url + keyword + '+site:pan.baidu.com'+'&start=' + startIndex; break; case 'Google': 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='; url = url + keyword + '&start=' + startIndex; break; case 'SOSO': url = 'http://www.sogou.com/web?query='; url = url + keyword + '+site%3Apan.baidu.com' + '&page=' + parseInt(startIndex / 10, 10) + 1; break; default: console.log('error'); return 0; } //显示loading条 $('.wxz-content').html(''); $('#wxz_myDiv').slideDown(); GM_xmlhttpRequest({ method: "GET", url: url, 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) { var data, showList, tempNode, totalPage = 1, totalResults; switch (flag) { case 'Google': data = JSON.parse(response.responseText); break; case 'Bing': data = bingToData(response.responseText); break; case 'repigu': data = mirrorToData(response.responseText); break; case 'Repigu': data = repiguToData(response.responseText); break; case 'SOSO': data = sosoToData(response.responseText); break; default: console.log('error'); return 0; } totalResults = parseInt(data.cursor.estimatedResultCount, 10); //把json数据转为html,存入缓存showlist if (parseInt(data.cursor.resultCount, 10) === 0) { $('.wxz-content').html('
无搜索结果...换个关键词重新试试?
'); } //无结果时提示 else { totalPage = parseInt((totalResults - 1) / 10, 10) + 1 > 10 ? 10 : parseInt((totalResults - 1) / 10, 10) + 1; //坑比,google自定义搜索只提供最大10页(每页10条) showList = "

---- by " + flag + ".com Search

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

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

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

' + tempNode + '

'; showList += '

' + element.contentNoFormatting + '

'; }); showList += '

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

"' + data.results.length + '" items have been load

'; $('.wxz-content').html(showList); //替换原来内容,之所以用了showlist作为缓存是为了提升速度 $('.wxz-content').scrollTop(0); //滚到顶端 } addAboutInfo(info); pageBar(parseInt(startIndex / 10, 10) + 1, totalPage); data = null; tempNode = null; totalPage = null; totalResults = null; showList = null; }, onerror: function() { $('.wxz-content').html('
出错了......
'); console.log("error"); return 0; } }); } function addAboutInfo(info) { var temp = '

About me

'; $('.wxz-content').append(temp); } function bingToData(html) { var data = { cursor: { estimatedResultCount: 0, resultCount: 0 }, results: [] }; //其中一条结果: //
  • //YFK-RK3368-8189-20150821.rar_免费高速下载|百度云 网盘 ...

    //

    文件名:YFK-RK3368-8189-20150821.rar 文件大小:497.55M 分享者:晨芯FAE 分享时间:2015-8-21 14:07 下载次数:5 ... 登录百度云客户端送2T空间 电脑版

    //
    pan.baidu.com/wap/link?uk=2923110658&shareid=3468815834&... //
  • //http://www.jb51.net/article/49083.htm在JS中解析HTML字符串示例代码: var el = $( '
    ' ); el.html(html); var b_results = $("#b_results", el); var b_algo_Arry = $("li.b_algo", b_results); $.each(b_algo_Arry, function(index, val) { var tempResult = { unescapedUrl: "", titleNoFormatting: "", contentNoFormatting: "" }; tempResult.unescapedUrl = $(val).find("h2 a").attr('href'); tempResult.titleNoFormatting = $(val).find("h2 a").text(); tempResult.contentNoFormatting = $(val).find('div.b_caption p').text(); data.results.push(tempResult); }); ////处理统计结果 var rawResultCount=$('.sb_count',b_results).text(); var matchLst=[]; matchLst=rawResultCount.match(/([0-9]{1,3}(,[0-9]{3})+)/g); if(matchLst!==null){//匹配100,000,111之类的情况 data.cursor.resultCount=matchLst[0].replace(',',''); }else{ matchLst=rawResultCount.match(/\d+/g); if(matchLst!==null){//匹配10 个结果之类的情况,以及1-11,共11个的情况 data.cursor.resultCount=matchLst.pop(); }else{//匹配无的情况 data.cursor.resultCount=0; } } data.cursor.resultCount = parseInt( data.cursor.resultCount.toString(),10); data.cursor.estimatedResultCount = data.cursor.resultCount; return data; } function mirrorToData(text){ var tempData=JSON.parse(text).responseData; var data = { cursor: { estimatedResultCount: 0, resultCount: 0 }, results: [] }; data.cursor.resultCount = parseInt(tempData.cursor.resultCount.replace(',', ''), 10); data.cursor.estimatedResultCount = data.cursor.resultCount; $.each(tempData.results, function(index, val) { var tempResult = { unescapedUrl: "", titleNoFormatting: "", contentNoFormatting: "" }; tempResult.unescapedUrl = val.unescapedUrl; tempResult.titleNoFormatting = val.titleNoFormatting; tempResult.contentNoFormatting = val.content; data.results.push(tempResult); /* iterate through array or object */ }); return data; } function sosoToData(html) { var begin = html.search('
    '), end = html.search('
    '); 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('