Greasy Fork

Greasy Fork is available in English.

豆瓣 ReadFree 传送门

在“豆瓣读书”页面增加到ReadFree电子书的传送门

当前为 2016-06-01 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        豆瓣 ReadFree 传送门
// @namespace   https://github.com/JiajunW/douban2readfree
// @description 在“豆瓣读书”页面增加到ReadFree电子书的传送门
// @icon        https://raw.githubusercontent.com/JiajunW/douban2readfree/master/res/icon.png
// @include     https://book.douban.com/subject/*
// @version     1.0.2
// @resource    custom_css https://raw.githubusercontent.com/JiajunW/douban2readfree/master/style/style.css
// @grant       GM_xmlhttpRequest
// @grant       GM_addStyle
// @grant       GM_getResourceText
// ==/UserScript==

(function() {
    function get_book_id() {
        var path = document.location.pathname;
        var re = /^\/subject\/(\d+)/g;
        var matches = re.exec(path);
        if (matches && matches.length > 1) {
            return parseInt(matches[1]);
        }
    }

    function add_readfree_style() {
        GM_addStyle(GM_getResourceText("custom_css"));
    }

    function dom(tag, attr, inner) {
        var tag = document.createElement(tag);
        for (var key in attr) {
            if (attr.hasOwnProperty(key)) {
                tag.setAttribute(key,attr[key]);
            }
        }
        if (inner) {
            tag.innerHTML = inner;
        }
        return tag;
    }

    var id = get_book_id();
    if (id === undefined) {
        return;
    }

    var rf_url = 'http://readfree.me/book/' + id;

    GM_xmlhttpRequest({
        method: "HEAD",
        url: rf_url,
        onload: function(response) {
            if (response.status == 200) {
                var panel = dom('div', { id : 'readfree-link' }),
                    ahref = dom('a', { href : rf_url, target : '_blank' }, 'ReadFree!')
                panel.appendChild(ahref);
                document.body.appendChild(panel);

                add_readfree_style();
            }
        }
    });
})();