// ==UserScript== // @name 百度云插件+APIKey++ // @namespace // @version 4.5.0.0 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== /*thanks to the tutorial of mvc at https://alexatnet.com/articles/model-view-controller-mvc-javascript*/ //Event is a simple class for implementing the Observer pattern: function Event(sender) { this._sender = sender; this._listeners = []; } Event.prototype = { attach : function (listener) {//push the callback function into _listeners[]; this._listeners.push(listener); }, notify : function (args) {//pop all the callback functions and execute the functions with same args? var index; for (index = 0; index < this._listeners.length; index += 1) { this._listeners[index](this._sender, args);//auto pass sender and args into callback function, so the default form of callback function is function(sender,args){} } } }; //Javascript-template-engine-in-just-20-line //by by Krasimir http://krasimirtsonev.com/blog/article/Javascript-template-engine-in-just-20-line var TemplateEngine = function(html, options) { var re = /<%([^%>]+)?%>/g, reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g, code = 'var r=[];\n', cursor = 0, match; var add = function(line, js) { js? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') : (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : ''); return add; }; while(match = re.exec(html)) { add(html.slice(cursor, match.index))(match[1], true); cursor = match.index + match[0].length; } add(html.substr(cursor, html.length - cursor)); code += 'return r.join("");'; return new Function(code.replace(/[\r\t\n]/g, '')).apply(options); }; ////////////////////////////////////////////////////////////////////// /////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); ///////////////////////////////////////////////////////////////////////////////////////////////////////////// ////// /** * The Model. Model stores items and notifies * observers about changes. */ var BaseModel=function(engineLst){ this.keyword=""; this.engine="default"; this.engineLst=engineLst; this.jsonObj={ cursor: { estimatedResultCount: 0, resultCount: 0 }, results: [] }; this.curr=1; this.totalPage=1; this.urls={default:'http://',}; this.state=false; this.contentUpdated=new Event(this); this.requestEvent=new Event(this); }; BaseModel.prototype={ setEngine:function(engine){ this.engine=engine; }, updateCurr:function(curr){ this.curr=curr; }, updateKeyword:function(keyword){ this.keyword=keyword; }, request:function(){ this.requestEvent.notify(); var _this=this; GM_xmlhttpRequest({ method: "GET", url: _this.compileUrl[_this.engine](_this), 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) { _this.jsonObj=_this.toJson[_this.engine](response.responseText); _this.totalPage=(parseInt(_this.jsonObj.cursor.resultCount)-parseInt(_this.jsonObj.cursor.resultCount)%10)/10+1; _this.state=true; var _self=_this; _this.contentUpdated.notify(_self.state); }, onerror: function() { _this.jsonObj={ cursor: { estimatedResultCount: 0, resultCount: 0 }, results: [] }; _this.totalPage=1; _this.state=false; var _self=_this; _this.contentUpdated.notify(_self.state); } }); }, destory:function(){ this.jsonObj={}; this.totalPage=0; this.state=false; this.curr=0; this.keyword=""; }, toJson:{ default:function(text){ var jsonObj = { cursor: { estimatedResultCount: 0, resultCount: 0 }, results: [] }; return jsonObj; }, }, compileUrl:{ default:function(_this){ return _this.url + _this.keyword + '+site%3Apan.baidu.com' + '&first=' + _this.curr; }, }, }; var Viewer=function(model,UIelements){ this.model=model; this.UI=UIelements; this.searchClick=new Event(this); this.closeClick=new Event(this); this.nextClick=new Event(this); this.preClick=new Event(this); this.toPageClick=new Event(this); this.engineOptChange=new Event(this); var _self=this; this.UI.searchBtn.click(function(event) { /* Act on the event */ var curr=1; var keyword=_self.UI.inputEle.val(); if(keyword.replace(/\s*/,'')!==''){ _self.searchClick.notify({curr:curr,keyword:keyword}); } }); this.UI.closeBtn.click(function(event) { /* Act on the event */ _self.closeClick.notify(); }); this.UI.inputEle.keyup(function(event) { if (event.which == 13) { _self.UI.searchBtn.trigger('click'); } }); $('body').on('click',this.UI.engineBtn.selector,function(){ var engine=$(this).data('engine'); _self.engineOptChange.notify(engine); }); $('body').on('click',this.UI.toPageBtn.selector,function(){ var page=$(this).data('page'); _self.toPageClick.notify(page); }); this.UI.myDiv.draggable({ handle: "#wxz_myDiv_title" }); }; Viewer.prototype={ refleshEngineLst:function(){ var template='<%for(var i in this){%>'+ '
'+ '<%}%>'; var html=TemplateEngine(template,this.model.engineLst); this.UI.engineLst.html(html); }, updateEngine:function(){ this.UI.menu.text(this.model.engine); }, show:function(){ this.UI.myDiv.show(); }, reflesh:function(success){ var template="---- by <%this.engine%>.com Search
keyword is '<%this.keyword%>' found '<%this.jsonObj.cursor.resultCount%>' Results
--------------------------------------------------
"; template+='<%for(var i in this.jsonObj.results){%>'+ '
'+ '<%this.jsonObj.results[i].titleNoFormatting%>'+ '
'+ '<%this.jsonObj.results[i].contentNoFormatting%>
'+ '<%}%>'; template+='-------------------------------------------------------------
" <%this.jsonObj.results.length%> " items have been load
'; var html; if(success===false){ html='文件名:YFK-RK3368-8189-20150821.rar 文件大小:497.55M 分享者:晨芯FAE 分享时间:2015-8-21 14:07 下载次数:5 ... 登录百度云客户端送2T空间 电脑版
//