// ==UserScript== // @name 豆瓣读书资源助手 // @namespace yueye // @version 1.1.5 // @description 在豆瓣读书页面展示资源站下载链接 // @author yueye // @match https://book.douban.com/subject/* // @require http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js // @grant GM.xmlHttpRequest // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== (function () { var website = [{ site: '我的小书屋', searchLink: 'http://mebook.cc/?s=', selector: '.list li', itemSelector: ' .content h2 a', state: -1 },{ site: 'sobooks', searchLink: 'https://sobooks.cc/search/', selector: '.cardlist .card', itemSelector: ' .shop-item h3 a', state: -1 }] var title = document.querySelector('h1 span').innerText var author = document.querySelectorAll('#info a')[0].innerText var splitStart = document.querySelectorAll('#info a')[0].innerText.indexOf(']') var splitEnd = document.querySelectorAll('#info a')[0].innerText.indexOf('(') !== -1 ? document.querySelectorAll('#info a')[0].innerText.indexOf('(') : author.length author = author.substr(splitStart + 1, splitEnd - splitStart -1).trim() function getSearchPage (searchLink, title, selector, itemSelector) { return new Promise(function(resolve, reject) { GM_xmlhttpRequest({ method: 'GET', url: searchLink + title, onload: function (res) { var state = -1 var doc = (new DOMParser()).parseFromString(res.responseText, 'text/html'); var list_length = doc.querySelectorAll(selector).length if (list_length > 0) { var bookTitle = doc.querySelectorAll(selector + itemSelector)[0].innerText || '' state = bookTitle.indexOf(title) } resolve(state) } }) }) } /* function getDownloadLink (title, website) { return new Promise(function(resolve, reject) { GM.xmlHttpRequest({ method: 'POST', url: 'http://127.0.0.1:3000/index?keywords=' + title, data: website, onload: function(response) { console.log(JSON.parse(response.responseText)) resolve(JSON.parse(response.responseText)) } }) }) } */ function showInDoubanPage (title) { var html = [ '