// ==UserScript== // @name 今日优读 // @description 主要搭建一个知识平台以及读书辅助工具,提供书籍搜索,中图分类和学科搜索。 // @author 018(lyb018@gmail.com) // @contributor Rhilip // @connect * // @grant GM_xmlhttpRequest // @grant GM_addStyle // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js // @require https://greasyfork.org/scripts/32927-md5-hash/code/MD5%20Hash.js?version=225078 // @require https://unpkg.com/vue/dist/vue.js // @require https://unpkg.com/element-ui/lib/index.js // @include http://uread.today/* // @include http://127.0.0.1:9090/* // @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://yabook.blog/* // @include https://www.jiumodiary.com/* // @include http://www.ncpssd.org/* // @version 0.4.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'; $(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'); addZoteroCapture(); } 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/welcome')) { handleIsticWelcome(); } 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.')) { handleYabook(); } else if (location.href.includes('https://www.jiumodiary.com/')) { handleJiumodiary(); } else if (location.href.includes('http://www.ncpssd.org/index.aspx')) { handleNcpssd(); } else if (location.href.includes('http://uread.today/')) { handleuRead(); } else if (location.href.includes('http://127.0.0.1:9090/')) { handleuRead(); } }) function addZoteroCapture() { //$('body').append('
' + // '
' + '
') $('body').append(`
自定义Zotero抓取 请保持显示状态下抓取
初步评价:
豆瓣短评:
目录: 重置
加载中...
{{zotero.tags.length}} 个标签。 清空 重置
{{tag}}
需要安装油猴插件「豆瓣京东当当中图法分类」。
刷新

辅助页(版权页、前言页、目录页)

正文试读

微信读书《{{zotero.title}}》

`); GM_addStyle(` .uread-color { color: #009193 !important; } .major-color { color: #303133 !important; } .minor-color { color: #909399 !important; } .placeholder-color { color: #C0C4CC !important; } .headline-size { font-size: 20px !important; } .headline-content { font-size: 20px !important; color: #303133 !important; } .major-size { font-size: 13px !important; } .minor-size { font-size: 12px !important; } .article-content { color: #303133 !important; font-size: 14px !important; } .major-content { color: #303133 !important; font-size: 13px !important; } .minor-content { color: #909399 !important; font-size: 12px !important; } .zotero .el-drawer__body { overflow: scroll; } .zotero .drawer-content { margin: 0 10px 20px; } .zotero .el-form-item--mini.el-form-item { margin-bottom: 5px; } .zotero .el-form-item__label { color: #909399; font-size: 12px; } .zotero .el-tag { margin-right: 15px; margin-bottom: 10px; } .zotero .button-new-tag { margin-right: 10px; width: 70px; padding-top: 7px; height: 27px; } .zotero .input-new-tag { width: 70px; margin-right: 10px; } .zotero .image { width: 100px; height: 120px; } .zotero .el-drawer__header { margin-bottom: 10px; } .zotero .tools { display: flex; align-items: center; justify-content: space-between; margin-top: 15px; } .fill { width: 100%; }`); var style = document.createElement('link'); style.type = 'text/css'; style.rel = 'stylesheet'; style.href = 'https://unpkg.com/element-ui/lib/theme-chalk/index.css'; document.getElementsByTagName('head')[0].appendChild(style); const LocalStorage = { get (key, item, def) { if (!item) { const sk = window.localStorage.getItem(key) if (sk) { return JSON.parse(sk) } } else { var obj = this.get(key) return (obj && `${item}` in obj) ? obj[`${item}`] : def } }, set (key, objectOrItem, value) { if (objectOrItem && typeof objectOrItem === 'object' && objectOrItem.constructor === Object) { window.localStorage.setItem(key, JSON.stringify(objectOrItem)) } else { var obj = this.get(key) if (!obj) { obj = {} } obj[`${objectOrItem}`] = value window.localStorage.setItem(key, JSON.stringify(obj)) } }, remove (key, item) { if (!item) { window.localStorage.removeItem(key) } else { var obj = this.get(key) if (obj && `${item}` in obj) { delete obj[`${item}`] this.set(key, obj) } } }, keys () { return Object.keys(window.localStorage) } } const LocalHistory = { max: 10, localHistorys: undefined, get (key) { const sk = window.localStorage.getItem(key) if (sk) { this.localHistorys = JSON.parse(sk) } else { this.localHistorys = [] } return this.localHistorys }, activate (key, obj) { this.push(key, obj) return this.get(key) }, push (key, obj) { this.localHistorys = this.get(key) let find for (let index = 0; index < this.localHistorys.length; index++) { const element = this.localHistorys[index] if (element.keyword === obj.keyword) { find = index break } } if (find >= 0) { this.localHistorys.splice(find, 1) } if (this.localHistorys.length >= this.max) { this.localHistorys.pop() } this.localHistorys = [obj, ...this.localHistorys] window.localStorage.setItem(key, JSON.stringify(this.localHistorys)) return this.localHistorys }, splice (key, index) { if (index >= 0) { this.localHistorys.splice(index, 1) window.localStorage.setItem(key, JSON.stringify(this.localHistorys)) } } } new Vue({ el: '#zotero-plus', data: function() { return { zotero: { title: '', creators: [{ creatorType: 'author', lastName: '' }], abstractNote: '', series: '', seriesNumber: '', volume: '', numberOfVolumes: '', edition: '', place: '', publisher: '', date: '', numPages: '', language: '', ISBN: '', shortTitle: '', url: '', archive: '', archiveLocation: '', callNumber: '', rights: '', extra: '', notes: [{ enabled: false, note: '' }, { enabled: true, note: '' }, { enabled: true, note: '' }], attachments:[{ enabled: true, linkMode: '', mimeType: 'application/pdf', url: '' }, { enabled: true, linkMode: '', mimeType: 'application/pdf', url: '' }, { enabled: true, linkMode: 'linked_url', mimeType: '', url: '' }], tags: [], tagenabled: true, initd: false, drawer: false, tagVisible: false, tagValue: '', zoteroTagsHistory: [] } } }, methods: { doPerson(data, creatorType) { if (!data || data.length <= 0) return; const persons = data.split('/'); var creators = [] for (var person of persons) { creators.push({ lastName: person.trim().replace(/(更多\.\.\.|. 著)/, ''), creatorType: creatorType, fieldMode: 1 }); } return creators; }, getIDFromURL(url) { if (!url) return ''; var id = url.match(/subject\/.*\//g); if (!id) return ''; return id[0].replace(/subject|\//g, ''); }, showZotero() { if (!this.zotero.initd) { this.zotero.title = text(document, 'h1 span[property="v:itemreviewed"]'); this.zotero.creators = []; var infos = text(document, 'div[class*="subject"] div#info'); infos = infos.replace(/^[\xA0\s]+/gm, '') .replace(/[\xA0\s]+$/gm, '') .replace(/\n+/g, '\n') .replace(/:\n+/g, ': ') .replace(/]\n/g, ']') .replace(/】\n/g, '】') .replace(/\n\/\n/g, '/'); for (var section of Object.values(infos.split('\n'))) { if (!section || section.trim().length <= 0) continue; let index = section.indexOf(':'); if (index <= -1) continue; let key = section.substr(0, index).trim(); let value = section.substr(index + 1).trim(); switch (key) { // book case "作者": this.zotero.creators.push(...this.doPerson(value, "author")); break; case "译者": this.zotero.creators.push(...this.doPerson(value, "translator")); break; case "原作名": case "副标题": if (this.zotero.shortTitle && this.zotero.shortTitle.length >= 1) { this.zotero.shortTitle += " / " + value; } else { this.zotero.shortTitle = value; } break; case "ISBN": this.zotero.ISBN = value; break; case "页数": this.zotero.numPages = value; break; case "出版社": this.zotero.publisher = value; break; case "出品方": this.zotero.rights = value; break; case "丛书": this.zotero.series = value; break; case "出版年": this.zotero.date = value; break; case "语言": this.zotero.language = value; break; default: break; } } this.zotero.seriesNumber = ''; this.zotero.volume = ''; this.zotero.numberOfVolumes = ''; this.zotero.place = ''; var edition = this.zotero.title.match(/第(.*?)版/); this.zotero.edition = edition ? edition[1] : ''; this.zotero.url = location.href; this.zotero.callNumber = ''; this.zotero.cover_url = document.querySelector('.nbg').href; // 中图clc作为标签,需要安装油猴插件:https://greasyfork.org/zh-CN/scripts/408682 var clc = text(document, '#clc'); if (clc) { this.zotero.archiveLocation = clc; } var subject = text(document, '#subject'); if (subject) { this.zotero.archive = subject; } // 摘要 let abstractNote; var h2s = document.querySelectorAll('div.related_info h2'); for (var i = 0; i < h2s.length; i++) { let h2 = h2s[i]; let span = h2.querySelector('span'); if (span && span.textContent === '内容简介') { var intro = h2.nextElementSibling.querySelector('.all div.intro'); if (!intro) { intro = h2.nextElementSibling.querySelector('div.intro'); } if (intro) { abstractNote = intro.textContent; } break; } } if (abstractNote) { this.zotero.abstractNote = abstractNote.trim().replace(/(([\xA0\s]*)\n([\xA0\s]*))+/g, '\n'); } this.zotero.notes = [{ enabled: false, note: '' }, { enabled: LocalStorage.get('Zotero-config', 'captureCatalogues', true), note: '' }, { enabled: LocalStorage.get('Zotero-config', 'captureComments', true), note: '' }]; let id = this.getIDFromURL(this.zotero.url); let dir = text(document, '#dir_' + id + '_full'); if (dir) { dir = dir.replace(/(([\xA0\s]*)\n([\xA0\s]*))+/g, '\n').replace('· · · · · · (收起)', ''); this.zotero.notes[1].note = dir; } this.zotero.attachments = [{ enabled: LocalStorage.get('Zotero-config', 'captureAssistUrl', true), mimeType: 'application/pdf', url: '' }, { enabled: LocalStorage.get('Zotero-config', 'captureCntUrl', true), mimeType: 'application/pdf', url: '' }, { enabled: LocalStorage.get('Zotero-config', 'captureWereadUrl', true), linkMode: 'linked_url', url: '' }]; var assistUrl = document.getElementById('assistUrl'); this.zotero.attachments[0].url = assistUrl ? assistUrl.href : ''; var cntUrl = document.getElementById('cntUrl'); this.zotero.attachments[1].url = cntUrl ? cntUrl.href : ''; var weread = document.querySelector('#weread a'); this.zotero.attachments[2].url = weread ? weread.href : ''; // 豆瓣短评 /*for (let item of document.querySelectorAll('#new_score li.comment-item')) { var people = item.querySelector('.comment-info a').textContent; var time = item.querySelector('.comment-time').textContent; var count = item.querySelector('.vote-count').textContent; var content = item.querySelector('.comment-content .short').textContent; var stars = item.querySelector('.user-stars').getAttribute('class').match(/\d/g).join('.'); this.zotero.notes[2].note += `

(${time}): [${stars}] ${content} (${count}有用)

\n`; }; this.zotero.notes[2].note += '

' + document.querySelector('#comment-list-wrapper + p a').outerHTML + '

';*/ this.zotero.notes[2].note = '获取中...'; loadDoc(`${this.zotero.url}/comments`, {vue: this}, function(doc, responseDetail, meta) { meta.vue.zotero.notes[2].note = ''; for (let item of doc.querySelectorAll('#comments li.comment-item')) { var people = item.querySelector('.comment-info a').textContent; var time = item.querySelector('.comment-time').textContent; var count = item.querySelector('.vote-count').textContent; var content = item.querySelector('.comment-content .short').textContent; var stars = item.querySelector('.user-stars') ? item.querySelector('.user-stars').getAttribute('class').match(/\d/g).join('.') : '0'; meta.vue.zotero.notes[2].note += `

${people}(${time}): [${stars}] ${content} (${count}有用)

\n`; }; meta.vue.zotero.notes[2].note += '

' + document.querySelector('#comment-list-wrapper + p a').outerHTML + '

'; }, function(err, meta) { meta.vue.zotero.notes[2].note = '发生异常,请刷新重试。'; }); this.zotero.tags = []; var tags = text(document, 'div#db-tags-section div.indent'); if (tags) { tags = tags.replace(/((\s*)\n(\s*))+/g, '\n'); for (var tag of tags.split('\n')) { if (!tag || tag.trim().length <= 0) continue; this.zotero.tags.push(tag); } } // 评分 & 评价人数 var rating = text(document, 'strong[property*="v:average"]'); if (rating && (rating = rating.trim()).length >= 1) { var ratingPeople = text(document, 'div.rating_sum a.rating_people span[property="v:votes"]'); if (!ratingPeople || ratingPeople.toString().trim().length <= 0) { ratingPeople = 0; } this.zotero.extra = rating + "/" + ratingPeople; } this.zotero.tagenabled = LocalStorage.get('Zotero-config', 'captureTags', true); this.zotero.zoteroTagsHistory = LocalHistory.get('ZoteroTagsHistory'); this.zotero.initd = true; } this.zotero.drawer = true; }, zoteroReset(field) { switch (field) { case 'title': this.zotero.title = text(document, 'h1 span[property="v:itemreviewed"]'); break; case 'series': var infos = text(document, 'div[class*="subject"] div#info'); infos = infos.replace(/^[\xA0\s]+/gm, '') .replace(/[\xA0\s]+$/gm, '') .replace(/\n+/g, '\n') .replace(/:\n+/g, ': ') .replace(/]\n/g, ']') .replace(/】\n/g, '】') .replace(/\n\/\n/g, '/'); for (var section of Object.values(infos.split('\n'))) { if (!section || section.trim().length <= 0) continue; let index = section.indexOf(':'); if (index <= -1) continue; let key = section.substr(0, index).trim(); let value = section.substr(index + 1).trim(); switch (key) { case "丛书": this.zotero.series = value; break; default: break; } } break; case 'seriesNumber': this.zotero.seriesNumber = ''; break; case 'volume': this.zotero.volume = ''; break; case 'numberOfVolumes': this.zotero.numberOfVolumes = ''; break; case 'edition': var title = text(document, 'h1 span[property="v:itemreviewed"]'); var edition = title.match(/第(.*?)版/); this.zotero.edition = edition ? edition[1] : ''; break; case 'place': this.zotero.place = ''; break; case 'publisher': infos = text(document, 'div[class*="subject"] div#info'); infos = infos.replace(/^[\xA0\s]+/gm, '') .replace(/[\xA0\s]+$/gm, '') .replace(/\n+/g, '\n') .replace(/:\n+/g, ': ') .replace(/]\n/g, ']') .replace(/】\n/g, '】') .replace(/\n\/\n/g, '/'); for (section of Object.values(infos.split('\n'))) { if (!section || section.trim().length <= 0) continue; let index = section.indexOf(':'); if (index <= -1) continue; let key = section.substr(0, index).trim(); let value = section.substr(index + 1).trim(); switch (key) { case "出版社": this.zotero.publisher = value; break; default: break; } } break; case 'date': infos = text(document, 'div[class*="subject"] div#info'); infos = infos.replace(/^[\xA0\s]+/gm, '') .replace(/[\xA0\s]+$/gm, '') .replace(/\n+/g, '\n') .replace(/:\n+/g, ': ') .replace(/]\n/g, ']') .replace(/】\n/g, '】') .replace(/\n\/\n/g, '/'); for (section of Object.values(infos.split('\n'))) { if (!section || section.trim().length <= 0) continue; let index = section.indexOf(':'); if (index <= -1) continue; let key = section.substr(0, index).trim(); let value = section.substr(index + 1).trim(); switch (key) { case "出版年": this.zotero.date = value; break; default: break; } } break; case 'numPages': infos = text(document, 'div[class*="subject"] div#info'); infos = infos.replace(/^[\xA0\s]+/gm, '') .replace(/[\xA0\s]+$/gm, '') .replace(/\n+/g, '\n') .replace(/:\n+/g, ': ') .replace(/]\n/g, ']') .replace(/】\n/g, '】') .replace(/\n\/\n/g, '/'); for (section of Object.values(infos.split('\n'))) { if (!section || section.trim().length <= 0) continue; let index = section.indexOf(':'); if (index <= -1) continue; let key = section.substr(0, index).trim(); let value = section.substr(index + 1).trim(); switch (key) { case "页数": this.zotero.numPages = value; break; default: break; } } break; case 'language': this.zotero.language = ''; infos = text(document, 'div[class*="subject"] div#info'); infos = infos.replace(/^[\xA0\s]+/gm, '') .replace(/[\xA0\s]+$/gm, '') .replace(/\n+/g, '\n') .replace(/:\n+/g, ': ') .replace(/]\n/g, ']') .replace(/】\n/g, '】') .replace(/\n\/\n/g, '/'); for (section of Object.values(infos.split('\n'))) { if (!section || section.trim().length <= 0) continue; let index = section.indexOf(':'); if (index <= -1) continue; let key = section.substr(0, index).trim(); let value = section.substr(index + 1).trim(); switch (key) { case "语言": this.zotero.language = value; break; default: break; } } break; case 'shortTitle': infos = text(document, 'div[class*="subject"] div#info'); infos = infos.replace(/^[\xA0\s]+/gm, '') .replace(/[\xA0\s]+$/gm, '') .replace(/\n+/g, '\n') .replace(/:\n+/g, ': ') .replace(/]\n/g, ']') .replace(/】\n/g, '】') .replace(/\n\/\n/g, '/'); this.zotero.shortTitle = ''; for (section of Object.values(infos.split('\n'))) { if (!section || section.trim().length <= 0) continue; let index = section.indexOf(':'); if (index <= -1) continue; let key = section.substr(0, index).trim(); let value = section.substr(index + 1).trim(); switch (key) { case "原作名": case "副标题": if (this.zotero.shortTitle && this.zotero.shortTitle.length >= 1) { this.zotero.shortTitle += " / " + value; } else { this.zotero.shortTitle = value; } break; default: break; } } break; case 'archive': this.zotero.archive = ''; var subject = text(document, '#subject'); if (subject) { this.zotero.archive = subject; } break; case 'archiveLocation': this.zotero.archiveLocation = ''; var clc = text(document, '#clc'); if (clc) { this.zotero.archiveLocation = clc; } break; case 'callNumber': this.zotero.callNumber = ''; break; case 'rights': this.zotero.rights = ''; infos = text(document, 'div[class*="subject"] div#info'); infos = infos.replace(/^[\xA0\s]+/gm, '') .replace(/[\xA0\s]+$/gm, '') .replace(/\n+/g, '\n') .replace(/:\n+/g, ': ') .replace(/]\n/g, ']') .replace(/】\n/g, '】') .replace(/\n\/\n/g, '/'); for (section of Object.values(infos.split('\n'))) { if (!section || section.trim().length <= 0) continue; let index = section.indexOf(':'); if (index <= -1) continue; let key = section.substr(0, index).trim(); let value = section.substr(index + 1).trim(); switch (key) { case "出品方": this.zotero.rights = value; break; default: break; } } break; case 'extra': this.zotero.extra = ''; var rating = text(document, 'strong[property*="v:average"]'); if (rating && (rating = rating.trim()).length >= 1) { var ratingPeople = text(document, 'div.rating_sum a.rating_people span[property="v:votes"]'); if (!ratingPeople || ratingPeople.toString().trim().length <= 0) { ratingPeople = 0; } this.zotero.extra = rating + "/" + ratingPeople; } break; case 'catalogues': this.zotero.notes[1].note = ''; var id = this.getIDFromURL(this.zotero.url); var dir = text(document, '#dir_' + id + '_full'); if (dir) { dir = dir.replace(/(([\xA0\s]*)\n([\xA0\s]*))+/g, '\n').replace('· · · · · · (收起)', ''); this.zotero.notes[1].note = dir; } break; case 'tags': this.zotero.tags = []; var tags = text(document, 'div#db-tags-section div.indent'); if (tags) { tags = tags.replace(/((\s*)\n(\s*))+/g, '\n'); for (var tag of tags.split('\n')) { if (!tag || tag.trim().length <= 0) continue; this.zotero.tags.push(tag); } } break; case 'attachments': this.zotero.attachments = [{ enabled: LocalStorage.get('Zotero-config', 'captureAssistUrl', true), mimeType: 'application/pdf', url: '' }, { enabled: LocalStorage.get('Zotero-config', 'captureCntUrl', true), mimeType: 'application/pdf', url: '' }, { enabled: LocalStorage.get('Zotero-config', 'captureWereadUrl', true), linkMode: 'linked_url', url: '' }]; var assistUrl = document.getElementById('assistUrl'); this.zotero.attachments[0].url = assistUrl ? assistUrl.href : ''; var cntUrl = document.getElementById('cntUrl'); this.zotero.attachments[1].url = cntUrl ? cntUrl.href : ''; var weread = document.querySelector('#weread a'); this.zotero.attachments[2].url = weread ? weread.href : ''; this.$message.success('刷新成功'); break; default: break; } }, zoteroCreatorUp(index) { let {creatorType, lastName} = this.zotero.creators[index]; this.zotero.creators[index].creatorType = this.zotero.creators[index - 1].creatorType; this.zotero.creators[index].lastName = this.zotero.creators[index - 1].lastName; this.zotero.creators[index - 1].creatorType = creatorType; this.zotero.creators[index - 1].lastName = lastName; }, zoteroCreatorDown(index) { let {creatorType, lastName} = this.zotero.creators[index]; this.zotero.creators[index].creatorType = this.zotero.creators[index + 1].creatorType; this.zotero.creators[index].lastName = this.zotero.creators[index + 1].lastName; this.zotero.creators[index + 1].creatorType = creatorType; this.zotero.creators[index + 1].lastName = lastName; }, zoteroCreatorAdd(creator, index) { this.zotero.creators.splice(index + 1, 0, { creatorType: creator.creatorType, lastName: '' }); }, zoteroCreatorRemove(creator, index) { this.zotero.creators.splice(index, 1); }, zoteroRemoveTag(tag) { this.zotero.tags.splice(this.zotero.tags.indexOf(tag), 1); this.zotero.tagenabled = this.zotero.tags.length > 0; this.zoteroEnabledChange('captureTags', this.zotero.tagenabled); }, zoteroClearTags() { this.zotero.tags = []; this.zotero.tagenabled = false; this.zoteroEnabledChange('captureTags', this.zotero.tagenabled); }, zoteroShowInputTag() { this.zotero.tagValue = ''; this.zotero.tagVisible = true; this.$nextTick(_ => { this.$refs.zoteroSaveTagInput.focus(); }); }, zoteroInputTagConfirm() { let tagValue = this.zotero.tagValue; if (tagValue) { this.zotero.tags.push(tagValue); this.zotero.zoteroTagsHistory = LocalHistory.activate('ZoteroTagsHistory', {keyword: tagValue}); this.zotero.tagenabled = true; this.zoteroEnabledChange('captureTags', this.zotero.tagenabled); } this.zotero.tagVisible = false; this.zotero.tagValue = ''; }, zoteroSelectTagConfirm(tagHistory) { this.zotero.tags.push(tagHistory.keyword); this.zotero.zoteroTagsHistory = LocalHistory.activate('ZoteroTagsHistory', tagHistory); this.zotero.tagenabled = true; this.zoteroEnabledChange('captureTags', this.zotero.tagenabled); this.zotero.tagVisible = false; this.zotero.tagValue = ''; }, zoteroEnabledChange(item, checked) { LocalStorage.set('Zotero-config', item, checked) }, zoteroNote2Input() { this.zotero.notes[0].enabled = this.zotero.notes[0].note.length > 0; }, zoteroNote2Change() { this.zotero.notes[1].enabled = this.zotero.notes[1].note.length > 0; this.zoteroEnabledChange('captureCatalogues', this.zotero.notes[1].enabled); }, zoteroTagsHistoryQuerySearch(queryString, cb) { var zoteroTagsHistory = this.zotero.zoteroTagsHistory || []; var results = queryString ? zoteroTagsHistory.filter((tag) => { return (tag.keyword.toLowerCase().indexOf(queryString.toLowerCase()) === 0); }) : zoteroTagsHistory; cb(results); } } }) } 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 similar(s, t) { if (!s || !t) { return 0 } var l = s.length > t.length ? s.length : t.length var n = s.length var m = t.length var d = [] var min = function(a, b, c) { return a < b ? (a < c ? a : c) : (b < c ? b : c) } var i, j, si, tj, cost if (n === 0) return m if (m === 0) return n for (i = 0; i <= n; i++) { d[i] = [] d[i][0] = i } for (j = 0; j <= m; j++) { d[0][j] = j } for (i = 1; i <= n; i++) { si = s.charAt(i - 1) for (j = 1; j <= m; j++) { tj = t.charAt(j - 1) if (si === tj) { cost = 0 } else { cost = 1 } d[i][j] = min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost) } } let res = (1 - d[n][m] / l) return res } function handleuRead() { // 试读 $('#tags').parent().after('试读: ...') var a = $('#superlibnet'); if (a) { loadSrcDoc (a.attr('href'), {}, function (doc, responseDetail, meta) { var element = Object.values(doc.scripts).find(element => element.textContent.includes('send_requestajax')) if (element) { var pattern = /".*?"/ if (pattern.test(element.textContent)) { var url = pattern.exec(element.textContent)[0].replaceAll('"', ''); doText ('http://book.ucdrs.superlib.net/' + url, {}, function (responseText, responseDetail, meta) { var htmlText = unescape(responseText.trim()); var html = (new DOMParser()).parseFromString(htmlText, 'text/html'); var as = ''; var href; for(var a of html.querySelectorAll('.link a')) { if (as.length > 0) { as += ' | ' } if (a.textContent === '图书馆文献传递') { as += '' + a.textContent + '' } else { href = a.href.replace(location.origin, 'http://book.ucdrs.superlib.net'); as += '' + a.textContent + '' } } loadDoc(href, {}, function(doc, responseDetail, meta) { let $assistUrl = $(doc.querySelector('#downpdf [name=assistUrl]')); let assistUrl = $assistUrl.attr('value'); let $cntUrl = $(doc.querySelector('#downpdf [name=cntUrl]')); let cntUrl = $cntUrl.attr('value'); as += ' | 下载辅助页'; if (cntUrl) { as += ' | 下载正文试读'; } $('#tryread').html(as) }, function (responseDetail, meta) { $('#tryread').html(as) }); }, function (responseDetail, meta) { $('#tryread').html('
') }) } } }, function (responseDetail, meta) { $('#tryread').html('
发生异常,请刷新重试。
') }) } else { $('#tryread').html('
') } // 电子书 let title = $('#title').text(); let srctitle = $('#title > span:nth-child(1)').text(); let isbn = $('#isbn').text(); $('#ebook').parent().after('其他: Z-Library(...)' + ' | Library Genesis(...)' + ' | 微信读书(...)' + ' | 互助联盟(...)' + ' | LoreFree(...)' + ' | 雅书搜索' + '') // Z-Library loadDoc('https://1lib.us/s/' + isbn, {title: title, isbn: isbn}, function(doc, responseDetail, meta) { let found = false; for (let a of doc.querySelectorAll('table.resItemTable h3[itemprop=name] a')) { //if (a.textContent.includes(meta.title) || meta.title.includes(a.textContent)) { if (similar(a.textContent, meta.title) > 0.5) { let url = a.href.replace(location.host, 'b-ok.global').replace('http:', 'https:'); found = true; loadDoc(url, {}, function(doc, responseDetail, meta) { let addDownloadedBook = doc.querySelector('.addDownloadedBook'); if (addDownloadedBook) { let txt = addDownloadedBook.textContent.match(/\(.*\)/g); url = addDownloadedBook.href.replace(location.host, 'b-ok.global').replace('http:', 'https:'); if ($('#ZLibrary').text().includes('(...)')) { $('#ZLibrary').html(' Z-Library' + txt + ''); } else { $('#ZLibrary').append(' Z-Library' + txt + ''); } } else { $('#ZLibrary').html(' Z-Library(暂无资源)'); } }, function(err, meta) { $('#ZLibrary').html(' Z-Library(发生异常,请刷新重试。)'); }); } } if (!found) { $('#ZLibrary').html(' Z-Library(暂无资源)'); } }, function(err, meta) { $('#ZLibrary').html(' Z-Library(发生异常,请刷新重试。)'); }); // Library Genesis loadDoc('https://libgen.rs/search.php?req=' + isbn + '&lg_topic=libgen&open=0&view=simple&res=25&phrase=1&column=identifier', {title: title, isbn: isbn}, function(doc, responseDetail, meta) { let tr = doc.querySelector('body > table.c > tbody > tr:nth-child(2)'); if (tr) { let size = tr.querySelector('td:nth-child(8)').textContent; let extension = tr.querySelector('td:nth-child(9)').textContent; let download = tr.querySelector('td:nth-child(10) a'); $('#libgen').html(' Library Genesis(' + extension + ', ' + size + ')'); } else { $('#libgen').html(' Library Genesis(暂无资源)'); } }, function(err, meta) { $('#libgen').html(' Library Genesis(发生异常,请刷新重试。)'); }); // 微信读书 doGet('https://weread.qq.com/web/search/global?keyword=' + title + '&maxIdx=0&fragmentSize=120&count=40', {title: title, isbn: isbn}, function(json, responseDetail, meta) { if (json.books && json.books.length > 0) { let bookId let paring = function (val) { return val.replace(/(/g, '') .replace(/)/g, '') .replace(/【|﹝|〔/g, '') .replace(/】|﹞|〕/g, '') .replace(/ *编|著|译|等|校/g, '') .replace(/翻译/g, '') .replace(/\(审校\)/g, '') .replace(/译校/g, '') .replace(/编译/g, '') .replace(/正校/g, '') .replace(/•|・|▪/g, '') .replace(/\] +/g, '') .replace(/ *· */g, '') .replace(/ /g, '') .replace(/./g, '') .replace(/\. */g, '.') } let createId = function (bookId) { let str = MD5(bookId, false) let strSub = str.substr(0, 3) let func = function (id) { if (/^\d*$/.test(id)) { for (var len = id['length'], c = [], a = 0; a < len; a += 9) { var b = id['slice'](a, Math.min(a + 9, len)) c['push'](parseInt(b)['toString'](16)) } return ['3', c] } for (var d = '', i = 0; i < id['length']; i++) { d += id['charCodeAt'](i)['toString'](16) } return ['4', [d]] } let fa = func(bookId) strSub += fa[0], strSub += 2 + str['substr'](str['length'] - 2, 2) for (var m = fa[1], j = 0; j < m.length; j++) { var n = m[j].length.toString(16) 1 === n['length'] && (n = '0' + n), strSub += n, strSub += m[j], j < m['length'] - 1 && (strSub += 'g') } return strSub.length < 20 && (strSub += str.substr(0, 20 - strSub.length)), strSub += MD5(strSub, false).substr(0, 3) } for (let index = 0; index < json.books.length; index++) { const book = json.books[index] var creators = document.querySelectorAll('#author a') if (creators) { for (const creator of creators) { let author = paring(book.bookInfo.author) let lastName = paring(creator.textContent || '') if (lastName && (lastName.startsWith(author) || lastName.endsWith(author) || author.startsWith(lastName) || author.endsWith(lastName))) { bookId = book.bookInfo.bookId break } } } if (bookId) { break } } if (bookId) { let urlid = createId(bookId) let url = `https://weread.qq.com/web/reader/${urlid}` $('#weread').html(' 微信读书'); } else { $('#weread').html(' 微信读书(暂无资源)'); } } else { $('#weread').html(' 微信读书(暂无资源)'); } }, function(err, meta) { $('#weread').html('互助联盟(发生异常,请刷新重试。)'); }); // 互助联盟 loadDoc('https://www.readersteam.com/vip/?aff=readersteam&q=' + isbn, {title: title, isbn: isbn}, function(doc, responseDetail, meta) { let a = doc.querySelector('dl.result-list > dt:nth-child(1) a'); if (a) { $('#readersteam').html('互助联盟(发起互助)'); } else { $('#readersteam').html('互助联盟(暂无资源)'); } }, function(err, meta) { $('#readersteam').html('互助联盟(发生异常,请刷新重试。)'); }); // LoreFree let lorefreeurl = 'https://ebook2.lorefree.com/site/index?s=' + srctitle loadDoc(lorefreeurl, {title: title, isbn: isbn}, function(doc, responseDetail, meta) { let divs = doc.querySelectorAll('div.body-content > div:nth-child(2) div'); if (divs && divs.length > 0) { $('#LoreFree').html(' LoreFree(' + divs.length + '+)'); } else { $('#LoreFree').html(' LoreFree(暂无资源)'); } }, function(err, meta) { $('#LoreFree').html(' LoreFree(发生异常,请刷新重试。)'); }); } function handleCNKI() { let q = getQuery(location.search) if (q) { $('#txt_search').val(decodeURIComponent(q)) $('.search-btn').click() } } function handleIsticWelcome() { if (document.referrer) { let q = getQuery(document.referrer) if (q) { location.href = `https://ct.istic.ac.cn/site/organize/word?q=${q}` } } } 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, src) { // 替换一些信息防止图片和页面脚本的加载,同时可能加快页面解析速度 if (!src) { responseText = responseText.replace(/s+src=/ig, ' data-src='); // 图片,部分外源脚本 responseText = responseText.replace(/]*?>[\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, false) callback(doc, responseDetail, meta) } else if (fail){ fail(responseDetail, meta); } }, onerror: function(err) { if (fail) { fail(err, meta); } } }) } // 加载网页 function loadSrcDoc (url, meta, callback, fail) { GM_xmlhttpRequest({ method: 'GET', url: url, onload: function (responseDetail) { if (responseDetail.status === 200) { let doc = page_parser(responseDetail.responseText, true) callback(doc, responseDetail, meta) } else if (fail){ fail(responseDetail, meta); } }, onerror: function(err) { if (fail) { fail(err, meta); } } }) } // get请求 function doText (url, meta, callback, fail) { GM_xmlhttpRequest({ method: 'GET', url: url, onload: function (responseDetail) { if (responseDetail.status === 200) { callback(responseDetail.responseText, 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); } } }) } function text(docOrElem,selector,index) { var elem = index ? docOrElem.querySelectorAll(selector).item(index) : docOrElem.querySelector(selector); return elem ? elem.textContent : null; } })()