您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
知轩藏书书籍详情页添加优书网评分和直链
当前为
// ==UserScript== // @name 获取优书网评分 // @namespace http://tampermonkey.net/ // @description 知轩藏书书籍详情页添加优书网评分和直链 // @author tianxin // @match *://www.zxcs8.com/post/* // @match *://www.yousuu.com/book/* // @grant GM.xmlHttpRequest // @connect www.yousuu.com // @connect www.zxcs8.com // @version 0.2 // ==/UserScript== function getResult(url, callback) { GM.xmlHttpRequest({ method: 'GET', url: url, onload: function(response) { if (response.status >= 200 && response.status < 400){ callback(response.responseText);} else{ console.log( 'Error getting ' + url + ' (' + this.status + ' ' + this.statusText + '): ' + this.responseText); } }, onerror: function(response) { console.log('Error during GM.xmlHttpRequest to ' + url + ': ' + response.statusText); } }); } (function() { 'use strict'; var site = location.hostname; if(site == 'www.zxcs8.com'){ var bookText = document.getElementsByTagName('h1')[0].innerHTML; var bookName = bookText.match('《(.*?)》')[1]; var bookAuthor = bookText.split(':').pop(); getResult('http://www.yousuu.com/search/' + bookName + bookAuthor + '?type=all', function(response){ var rate = 0; var rateNum = 0; var rateText = '暂未查询到优书网评分'; var rateItem = '<p class="yinyong"><span style="font-size:14px;color:#FF0000;font-weight:bold">'+ rateText +'</span><p>'; var html = document.createElement( 'html' ); html.innerHTML = response; var matchBook = html.getElementsByClassName('col-lg-4 col-md-6 col-xs-12')[0]; var matchTitle = matchBook.getElementsByClassName('title')[0]; var matchName = matchTitle.innerText; var matchAbstract = matchBook.getElementsByClassName('abstract')[0].innerHTML.split('<br>'); var matchAuthor = matchAbstract[0].split(':')[1].replace(/<\/?[^>]*>/g,'').trim(); if(matchAuthor == bookAuthor && matchName == bookName){ rate = matchBook.getElementsByClassName('num2star')[0].innerHTML; rateNum = matchBook.getElementsByClassName('rating')[0].innerText.replace(/[^0-9]/ig,""); } // console.log(matchAuthor + ':' + bookAuthor + ';' + matchName + ':' + bookName); var obj = document.getElementsByClassName('yinyong')[0]; if(!obj){ obj = document.getElementsByClassName('pagefujian')[0]; } if(rate != 0 || rateNum != 0){ var bookLink = 'http://www.yousuu.com' + matchTitle.getElementsByTagName('a')[0].pathname; rateItem = '<p class="yinyong"><span style="font-size:14px;color:#FF0000;font-weight:bold"><a href = "' + bookLink + '" target="_blank">' + '优书网' + '</a>' + '评分: ' + rate + '</span><p>' + '<p class="yinyong"><span style="font-size:14px;color:#FF0000;font-weight:bold">评分人数: ' + rateNum + '</span><p>'; } obj.insertAdjacentHTML('beforebegin',rateItem); }) }else if(site == 'www.yousuu.com'){ var youBookName = document.getElementsByClassName('col-sm-7')[0].children[0].innerText; var youBookAuthor = document.getElementsByClassName('list-unstyled list-sm')["0"].firstChild.children["0"].innerText; getResult('http://www.zxcs8.com/index.php?keyword=' + youBookName,function(response){ var html = document.createElement( 'html' ); html.innerHTML = response; var bookList = Array.prototype.slice.call(html.getElementsByTagName('dl')); if(bookList.length > 0){ bookList.forEach(function(item){ var bookSum = item.children["0"]; var bookLink = bookSum.getElementsByTagName('a')[0].href; var matchBookName = bookSum.innerText.match('《(.*?)》')[1]; var matchBookAuthor = bookSum.innerText.split(':').pop(); // console.log(matchBookName + ':' + youBookName + ';' + matchBookAuthor + ':' + youBookAuthor ); if(matchBookName == youBookName && matchBookAuthor == youBookAuthor){ getResult(bookLink,function(response){ var html = document.createElement( 'html' ); html.innerHTML = response; var downloadLink = html.getElementsByClassName('down_2')[0].getElementsByTagName('a')[0].href; var obj = document.getElementsByClassName('sokk-book-button-groups')[0]; var button = '<div class="btn-group"><a href="' + downloadLink + '" target="_blank" class="btn btn-warning">去下载</a></div>'; obj.insertAdjacentHTML('beforeend',button); }) } }) } return ''; }) } })();