// ==UserScript== // @name Movie CSE for douban // @name:zh-CN 豆瓣电影自定义搜索 // @namespace http://www.einverne.tk // @version 1.3 // @description find useful movie download link from Google Custom Search Engine // @description:zh-cn 利用Google自定义搜索引擎给豆瓣电影加上下载链接 // @match http://movie.douban.com/subject/* // @copyright 2014+, einverne // @downloadURL https://update.greasyfork.icu/scripts/7915/Movie%20CSE%20for%20douban.user.js // @updateURL https://update.greasyfork.icu/scripts/7915/Movie%20CSE%20for%20douban.meta.js // ==/UserScript== (function () { var nextpage_index = 0; var url; var keyword2; var cx = "013193653470345952139:rmavzl75vbq"; var CSEFunction = function () { console.log("CSEFunction"); var douban_url = this.location.href; var reg = /(\d{7,8})/g; //正則 var douban_id = douban_url.match(reg); //獲取movie id var title = $('html head title').text(); var keyword1 = title.replace('(豆瓣)', '').trim(); keyword2 = encodeURIComponent(keyword1); var html_title_start = '

可下载的资源  · · 共有' var html_title_end = '条结果 (全部)

'; var html_body_start = '
'; var html_body_nextpage = '
第1页'; var html_body_morelinks = 'More on BTDigg 豆瓣皮 Google '; var html_body_endmore = '
'+html_body_morelinks+'
反馈
'; var html_body_endend = '
'; url = 'https://www.googleapis.com/customsearch/v1?key=AIzaSyAEPLlfl_OvTjYXc_-Vv7oKKVaBYEfl1kA&cx=013193653470345952139:rmavzl75vbq&alt=json&q=' + keyword2; var length = 30; $.ajax({ type:'GET', //HTTP請求方法 dataType:'json', //一旦獲取到數據,立刻當做腳本執行 url:url, //獲取數據url success:function (data) { if (data.queries.request[0].totalResults > 0) { var totalResults = data.queries.request[0].totalResults; var html_title = html_title_start + totalResults + html_title_end; nextpage_index = data.queries.nextPage[0].startIndex; var items = data.items; for (var i = 0; i < items.length; i++) { var title = items[i].title; var link = items[i].link; html_body_yes += '
  • ' + title + '
  • '; } $('.aside').prepend(html_title + html_body_start + html_body_yes + html_body_end + html_body_nextpage + html_body_endmore + html_body_endend); var b_nextpage = document.getElementById("nextPageButton"); b_nextpage.addEventListener('click', nextPage, false); } else { $('.aside').prepend(html_title + html_body_start + html_body_no + html_body_end + html_body_endend); } }, error:function (jqXHR, textStatus, errorThrown) { //console.log("error"+jqXHR.status+textStatus+errorThrown); //jqXHR.responseText.message $('.aside').prepend(html_title_start + "0" + html_title_end + html_body_start + html_body_error + html_body_end + html_body_endmore + html_body_endend); } }); function nextPage() { console.log("nextPage" + nextpage_index); html_body_yes = ""; url = 'https://www.googleapis.com/customsearch/v1?key=AIzaSyAEPLlfl_OvTjYXc_-Vv7oKKVaBYEfl1kA&cx=013193653470345952139:rmavzl75vbq&alt=json&q=' + keyword2 + '&start=' + nextpage_index; $.ajax({ type:'GET', //HTTP請求方法 dataType:'json', //一旦獲取到數據,立刻當做腳本執行 url:url, //獲取數據url success:function (data) { console.log("success"); var pager = document.getElementById("pager"); pager.innerHTML = "第" + Math.floor(nextpage_index / 10 + 1) + "页"; if (data.queries.request[0].count > 0) { nextpage_index = data.queries.nextPage[0].startIndex; var items = data.items; for (var i = 0; i < items.length; i++) { var title = items[i].title; var link = items[i].link; html_body_yes += '
  • ' + title + '
  • '; } var html_body = html_body_start + html_body_yes + html_body_end; $("#movie_cse>.csecontent").replaceWith(html_body); //$('.aside').prepend(html_title + html_body_start + html_body_yes + html_body_end + html_body_endmore + html_body_endend); } else { //$('.aside').prepend(html_title + html_body_start + html_body_no + html_body_end + html_body_endend); } } }); } } function contentEval(source) { console.log("contentEval"); // Check for function input. if ('function' == typeof source) { // Execute this function with no arguments, by adding parentheses. // One set around the function, required for valid syntax, and a // second empty set calls the surrounded function. source = '(' + source + ')();' } // Create a script node holding this source code. var script = document.createElement('script'); script.setAttribute("type", "application/javascript"); script.textContent = source; // Insert the script node into the page, so it will run, and immediately // remove it to clean up. document.body.appendChild(script); document.body.removeChild(script); } contentEval(CSEFunction()); }());