// ==UserScript==
// @name 今日优读
// @description 主要搭建一个知识平台以及读书辅助工具,提供书籍搜索,中图分类和学科搜索。
// @author 018([email protected])
// @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
// ==/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('<a target="_blank" href="http://uread.today/book?doi=' + ret.data + '" style="margin-left: 20px !important"><img title="查看" width="15px" src="data:image/jpeg;base64,/9j/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQECAgICAgICAgICAgMDAwMDAwMDAwMBAQEBAQEBAgEBAgICAQICAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA//dAAQAAv/uAA5BZG9iZQBkwAAAAAH/wAARCAAPAA8DABEAAREBAhEB/8QAbAABAQEAAAAAAAAAAAAAAAAACAkKAQEBAQAAAAAAAAAAAAAAAAAFBgQQAAEFAAIDAQEAAAAAAAAAAAUCAwQGBwEICRESEyIRAAICAgEDBAIDAAAAAAAAAAECAxEEBSESEzEABiJBFBUyUXH/2gAMAwAAARECEQA/ANNvm77NTOtHUMNO+XBgHS9goVGslyZuJCkSqyOFyZOk8xBhcRHlFeSVuTQli/hpvn3DkSPf9fHHNL7Y1eDtcuSLOyvxQkJZWpWJawvh6U0CSQSOBf1RN2+xzdTrptjrtadxnQxsyYQmXGOSwHEQyHKpEx8qzkKzAISOsEVVza8D9LoFOv4tthiFb66KPNw45oDY0DnSERp6UJcOVYmZrZSUJlqXGedgy5MVTzSvzcWn0rmemjEUrRg9QViLoiwPBo8gHyL59a8WWWbGjmnjMM7opaMlWKMQCUZkLIWU/ElGZSQelmFE/wD/0HB526b3G7jGcspNj69RMko+I2bRTIQ4F7DVXSoGgyTMULHrJktnkuvZy3WjbMYKthmTyRIuQIxaY3wlfClfdp7f/W4/UZJj81Bvtm1K8hf5chjwTxVA0ar0Pu591jYAm0GJDm7LvxL2pZzjp2WcLPL3RFN84YyZEj7dTMvbLx31hU+FU524wzND+JBuklNgZwc0MtoabKz2jrAxusqmZ1Ta48OFZwMzsoJRyesNKWRIOwpQ5qQTMS5rkdT7j7j523jw5ZTO0xElVXQT9k+bHi6FjwB/gXIVXKxnqjs0TwSPokc0SPqzX9n1/9k="></a>');
} else {
$(titleselecter).append('<a target="_blank" href="http://uread.today/embody?isbn=' + meta.isbn + '" style="margin-left: 20px !important"><img title="收录" width="15px" src="data:image/jpeg;base64,/9j/2wCEAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQECAgICAgICAgICAgMDAwMDAwMDAwMBAQEBAQEBAgEBAgICAQICAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA//dAAQAAv/uAA5BZG9iZQBkwAAAAAH/wAARCAAPAA8DABEAAREBAhEB/8QAbAABAQEAAAAAAAAAAAAAAAAACAkKAQEBAQAAAAAAAAAAAAAAAAAFBgQQAAEFAAIDAQEAAAAAAAAAAAUCAwQGBwEICRESEyIRAAICAgEDBAIDAAAAAAAAAAECAxEEBSESEzEABiJBFBUyUXH/2gAMAwAAARECEQA/ANNvm77NTOtHUMNO+XBgHS9goVGslyZuJCkSqyOFyZOk8xBhcRHlFeSVuTQli/hpvn3DkSPf9fHHNL7Y1eDtcuSLOyvxQkJZWpWJawvh6U0CSQSOBf1RN2+xzdTrptjrtadxnQxsyYQmXGOSwHEQyHKpEx8qzkKzAISOsEVVza8D9LoFOv4tthiFb66KPNw45oDY0DnSERp6UJcOVYmZrZSUJlqXGedgy5MVTzSvzcWn0rmemjEUrRg9QViLoiwPBo8gHyL59a8WWWbGjmnjMM7opaMlWKMQCUZkLIWU/ElGZSQelmFE/wD/0HB526b3G7jGcspNj69RMko+I2bRTIQ4F7DVXSoGgyTMULHrJktnkuvZy3WjbMYKthmTyRIuQIxaY3wlfClfdp7f/W4/UZJj81Bvtm1K8hf5chjwTxVA0ar0Pu591jYAm0GJDm7LvxL2pZzjp2WcLPL3RFN84YyZEj7dTMvbLx31hU+FU524wzND+JBuklNgZwc0MtoabKz2jrAxusqmZ1Ta48OFZwMzsoJRyesNKWRIOwpQ5qQTMS5rkdT7j7j523jw5ZTO0xElVXQT9k+bHi6FjwB/gXIVXKxnqjs0TwSPokc0SPqzX9n1/9k="></a>');
}
}, 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(/<script[^>]*?>[\S\s]*?<\/script>/ig, ''); //页面脚本
return (new DOMParser()).parseFromString(responseText, 'text/html');
}
// 加载网页
function loadDoc (url, meta, callback, fail) {
GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function (responseDetail) {
if (responseDetail.status === 200) {
let doc = page_parser(responseDetail.responseText)
callback(doc, responseDetail, meta)
} else if (fail){
fail(responseDetail, meta);
}
},
onerror: function(err) {
if (fail) {
fail(err, meta);
}
}
})
}
// get请求
function doGet (url, meta, callback, fail) {
GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function (responseDetail) {
if (responseDetail.status === 200) {
callback(JSON.parse(responseDetail.responseText), responseDetail, meta)
} else if (fail){
fail(responseDetail, meta);
}
},
onerror: function(err) {
if (fail) {
fail(err, meta);
}
}
})
}
// post请求
function doPost (url, headers, data, meta, callback, fail) {
GM_xmlhttpRequest({
method: "POST",
url: url,
data: data,
headers: headers,
onload: function(responseDetail){
if (responseDetail.status === 200) {
callback(JSON.parse(responseDetail.responseText), responseDetail, meta)
} else if (fail){
fail(responseDetail, meta);
}
},
onerror: function(err) {
if (fail) {
fail(err, meta);
}
}
})
}
})()