// ==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/*
// @include https://kns.cnki.net/*
// @include https://ct.istic.ac.cn/*
// @include https://weread.qq.com/*
// @include https://yabook.org/*
// @include https://www.jiumodiary.com/*
// @include http://www.ncpssd.org/*
// @version 0.2.0
// @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';
$(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');
} else if (location.href.includes('https://kns.cnki.net/kns8/defaultresult/index')) {
handleCNKI();
} else if (location.href.includes('https://ct.istic.ac.cn/site/organize/word')) {
handleIstic();
} else if (location.href.includes('https://weread.qq.com/')) {
handleWeread();
} else if (location.href.includes('https://yabook.org/')) {
handleYabook();
} else if (location.href.includes('https://www.jiumodiary.com/')) {
handleJiumodiary();
} else if (location.href.includes('http://www.ncpssd.org/index.aspx')) {
handleNcpssd();
}
})
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)
});
}
}
function handleCNKI() {
let q = getQuery(location.search)
if (q) {
$('#txt_search').val(decodeURIComponent(q))
$('.search-btn').click()
}
}
function handleIstic() {
let q = getQuery(location.search)
if (q) {
$('#termname').val(decodeURIComponent(q))
$('#btn-search').click()
}
}
function handleWeread() {
let q = getQuery(location.search)
if (q) {
setTimeout(() => {
$('.search_input_text').val(decodeURIComponent(q))
$('.search_input_right').click()
}, 2000)
}
}
function handleYabook() {
let q = getQuery(location.search)
if (q) {
$('#bdcsMain').val(decodeURIComponent(q))
$('.btn').click()
}
}
function handleJiumodiary() {
let q = getQuery(location.search)
if (q) {
$('#SearchWord').val(decodeURIComponent(q))
$('#SearchButton').click()
}
}
function handleNcpssd() {
let q = getQuery(location.search)
if (q) {
$('#text_search').val(decodeURIComponent(q))
$('#but_search').click()
}
}
function getQuery(url) {
if (!url) return false;
var q = url.match(/[?&]q=([^]*)/i);
if (!q || !q[1]) return false;
return q[1];
}
// 判断,空返回空字符串
function opt(val) {
if (!val) return '';
if (val instanceof Array) {
if (val.length > 0) {
return val[0];
}
} else {
return val;
}
}
// 对使用GM_xmlhttpRequest返回的html文本进行处理并返回DOM树
function page_parser(responseText) {
// 替换一些信息防止图片和页面脚本的加载,同时可能加快页面解析速度
responseText = responseText.replace(/s+src=/ig, ' data-src='); // 图片,部分外源脚本
responseText = responseText.replace(/