// ==UserScript==
// @name           今日优读
// @description    主要搭建一个知识平台以及读书辅助工具,提供书籍搜索,中图分类和学科搜索。
// @author         018(lyb018@gmail.com)
// @contributor    Rhilip
// @connect        *
// @grant          GM_xmlhttpRequest
// @require        https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @require        https://greasyfork.org/scripts/420063-018-js/code/018js.js?version=890174
// @include        http://book.ucdrs.superlib.net/views/specific/*
// @include        http://product.dangdang.com/*
// @include        https://item.jd.com/*
// @include        https://book.douban.com/subject/*
// @version        0.1.1
// @icon           http://uread.today/static/img/favicon.ico
// @run-at         document-end
// @namespace      http://uread.today
// @downloadURL none
// ==/UserScript==
// This Userscirpt can't run under Greasemonkey 4.x platform
if (typeof GM_xmlhttpRequest === 'undefined') {
    alert('不支持Greasemonkey 4.x,请换用暴力猴或Tampermonkey')
    return
}
;(function () {
    'use strict';
    function addViewOrEmbody(isbnselecter, titleselecter) {
        let match = document.querySelector(isbnselecter).innerText.match(/ISBN.*/)
        if (match) {
            let isbn = match[0].replace(/\D/g, '');
            doGet('http://api.uread.today/master/anon/book/get?isbn=' + isbn, {isbn: isbn}, function(ret, responseDetail, meta) {
                if (ret && ret.resultcode === 1) {
                    $(titleselecter).append('
');
                } else {
                    $(titleselecter).append('
');
                }
            }, function(err, meta) {
                console.warn(err)
            });
        }
    }
    $(document).ready(function () {
        if (location.href.includes('http://book.ucdrs.superlib.net/views/specific')) {
            addViewOrEmbody('.tubox dl', '.tutilte');
        } else if (location.href.includes('http://product.dangdang.com')) {
            addViewOrEmbody('#detail_describe', '.name_info h1');
        } else if (location.href.includes('https://item.jd.com')) {
            addViewOrEmbody('.p-parameter-list', '.sku-name');
        } else if (location.href.includes('https://book.douban.com/subject')) {
            addViewOrEmbody('#info', '#wrapper > h1 > span');
        }
    })
})()