Greasy Fork

Greasy Fork is available in English.

豆瓣读书资源助手

在豆瓣读书页面展示资源站下载链接

目前为 2018-08-30 提交的版本,查看 最新版本

// ==UserScript==
// @name         豆瓣读书资源助手
// @namespace    yueye
// @version      1.0.1
// @description  在豆瓣读书页面展示资源站下载链接
// @author       yueye
// @match        https://book.douban.com/subject/*
// @require      http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js
// @grant        GM.xmlHttpRequest
// ==/UserScript==

(function () {

  var title = document.querySelector('h1 span').innerText

  var website = [{
    site: '我的小书屋',
    searchLink: 'http://mebook.cc/?s='
  },{
    site: 'sobooks',
    searchLink: 'https://sobooks.cc/search/'
  }]

  /*
  function getDownloadLink (title) {
    return new Promise(function(resolve, reject) {
      GM.xmlHttpRequest({
        method: 'GET',
        url: 'http://127.0.0.1:3000/index?keywords=' + title,
        onload: function(response) {
          console.log(JSON.parse(response.responseText))
          resolve(JSON.parse(response.responseText))
        }
      })
    })
  }
  */

  function showInDoubanPage (list) {
    var html = [
      '<div class="gray_ad" id="doubanBookDL">',
        '<div id="buyinfo-printed" class="no-border">',
          '<h2>'+ title +'资源下载&nbsp;·&nbsp;·&nbsp;·&nbsp;·&nbsp;·&nbsp;·</h2>',
          '<ul class="bs noline">',
          ...list,
          '</ul>',
        '</div>',
      '</div>',
    ].join('')
    var sidebar = document.querySelector('.aside')
    sidebar.innerHTML = html + sidebar.innerHTML
  }

  if (/book.douban.com/.test(location.href)) {
    if (!title) return false
    /*
    getDownloadLink(title).then(res => {
      console.log('请求完成')
    })
    */
    var res = []
    website.map((item) => {
      var html = [
        '<li>',
          '<a target="_blank" href="javascript:;" style="display:inline-block;width:100px;">'+ item.site +'</a>',
          '<a target="_blank" class="buylink-price" href="'+ item.searchLink + title +'" style="display:inline-block;color:#fff;background-color:#ffc160;height:22px;margin-left:50px;padding:0 12px;border-radius:2px;font-size:12px;line-height:22px;text-align:center;">去查看</a>',
        '</li>',
      ]
      res = res.concat(html)
      console.log(html)
    })
    showInDoubanPage(res)
  }

})()