Greasy Fork

Greasy Fork is available in English.

豆瓣读书导出到 EndNote

从豆瓣读书的图书页面一键获取 EndNote Import 类型参考文献文件

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @id            [email protected]
// @name          豆瓣读书导出到 EndNote
// @namespace     lib.pku.edu.cn
// @version       1.0
// @description   从豆瓣读书的图书页面一键获取 EndNote Import 类型参考文献文件
// @author        馆君
// @match         https://book.douban.com/subject/*
// @connect       api.douban.com
// @grant         GM_xmlhttpRequest
// @grant         GM_setClipboard
// @grant         GM_addStyle
// @grant         GM_setValue
// @grant         GM_getValue
// ==/UserScript==
var styles = "@charset utf-8;";
styles += " .icoPlus {display: inline-block; zoom: 1; width: 10px; height: 16px; vertical-align: middle; overflow: hidden; background: #fff url(https://img3.doubanio.com/f/sns/61cc48ba7c40e0272d46bb93fe0dc514f3b71ec5/pics/add-doulist.gif) no-repeat 0 0;}";
GM_addStyle(styles); // 油猴脚本附加 CSS


function getJSON(url, meta, callback) { // XHR 回调函数模板——使用该函数可成功跨域请求 JSON
  GM_xmlhttpRequest({
    method: 'GET',
    url: url,
    headers: {
      'User-agent': window.navigator.userAgent,
      //'Content-type': 'application/json',
      'Accept': 'application/atom+xml,application/xml,text/xml'
    },
    onload: function(responseDetail) {
      var doc = {};
      if (responseDetail.status == 200) {
        doc = $.parseJSON(responseDetail.responseText);
      }
      callback(doc, responseDetail, meta);
    }
  });
}


(function() {
  'use strict';
  var hostName = window.location.hostname; // 当前网址的域名
  var pathName = window.location.pathname; // 当前网址的路径
  if (hostName == "book.douban.com" && /^\/subject\/\d+\/$/.test(pathName)) {
    // 豆瓣读书的图书页面,在写笔记之前添加一个按钮
    $(".ul_subject_menu").prepend("<li><i class='icoPlus'></i><a id='downloadEndNoteImport'>导出到 EndNote</a></li>");
    getJSON("https://api.douban.com/v2/book/" + window.location.pathname.match(/\d+/)[0], null, function(thisBook, resp, meta) {
      var content = "%0 Book\n%T " + thisBook.title; // Reference Types + Title
      $("#downloadEndNoteImport").attr("download", "[豆瓣图书]" + thisBook.title + ".txt");
      try {
        content += "\n%T " + thisBook.subtitle; // Title
        content += "\n%Q " + thisBook.alt_title; // Translated Title
        if (thisBook.series)
          content += "\n%B " + thisBook.series.title; // Series Title
        content += "\n%A " + thisBook.author.join("\n%A ").replace(/\[/,"[").replace(/]/, "]"); // Author
        content += "\n%? " + thisBook.translator.join("\n%? "); // Translator
        content += "\n%I " + thisBook.publisher; // Publisher
        content += "\n%D " + thisBook.pubdate.match(/\d{4}/)[0]; // Year
        content += "\n%8 " + thisBook.pubdate; // Date
        content += "\n%@ " + (thisBook.isbn13 ? thisBook.isbn13 : (thisBook.isbn10 ? thisBook.isbn10.replace(/^SH/, "统一书号 ") :"(无)")); // ISBN
        content += "\n%& " + thisBook.pages; // Pages
        content += "\n%U " + thisBook.alt; // URL
      } catch (e) {console.log(e);} // 主要是缺少属性的错误,直接忽略
      $("#downloadEndNoteImport").attr("href", "data:text/plain;charset=UTF-8," + encodeURIComponent(content));
    });
  }
})();