在亚马逊显示豆瓣书籍评分

By udonmai Last update Oct 8, 2013 — Installed 2,053 times.

Add your review

2 reviews


1 out of 1 person found this review helpful
3 stars
use \uxxxx to instead the 中文 , Apr 6, 2012
Review written by HelloCZ - see all my reviews (1)

// ==UserScript==
// @name douban_marks_on_amazon
// @namespace douban_marks_on_amazon
// @version 0.1
// @include http://www.amazon.cn/*
// author udonmai@gmail.com
// 2012-02-22 inition
// 2012-02-25 Thanks to wong2
// 2012-02-26 Taking into use
// ==/UserScript==

var $ = function(selector){
return document.querySelectorAll(selector);
}

!function(){
var nav = $('.navCat a.navCatA')[0].text;
if(nav.indexOf('\u56FE\u4E66') == -1) {
return;

}

var isbn = "";

var infos = $("div.content b");
//遍历目标节点获取isbn
for (var i = 0; i <=>
var info = infos[i];
if (info.textContent == "ISBN:") {
isbn = info.nextSibling.data;
isbn = isbn.split(",")[0].substring(1);
break;
}
}

GM_xmlhttpRequest({
method: 'GET',
url: 'http://api.douban.com/book/subject/isbn/' + isbn + '?alt=json',
onload: function(res) {
var rejson = JSON.parse(res.responseText);

var numRaters = rejson['gd:rating']['@numRaters'];
var average = rejson['gd:rating']['@average'];
var link = rejson['link'][1]['@href'];
var emp = $('.buying')[2];

var pos;

if(average < 1) pos = -151;
else if(average >=1 && average < 2) pos = -136;
else if(average >=2 && average < 3) pos = -121;
else if(average >=3 && average < 4) pos = -106;
else if(average >=4 && average < 5) pos = -91;
else if(average >=5 && average < 6) pos = -76;
else if(average >=6 && average < 7) pos = -61;
else if(average >=7 && average < 8) pos = -46;
else if(average >=8 && average < 9) pos = -31;
else if(average >=9 && average < 10) pos = -16;
else if(average = 10) pos = -1;

var htmlstr = document.createElement("span");
htmlstr.innerHTML = "&nbsp|&nbsp\u8C46\u74E3\u8BC4\u5206:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";

if(numRaters < 10) htmlstr.innerHTML += "&nbsp\u5C11\u4E8E10\u4EBA\u8BC4\u4EF7&nbsp\u94FE\u63A5";
else htmlstr.innerHTML += ""+ average +"&nbsp("+ numRaters +"\u4EBA\u8BC4\u4EF7)&nbsp\u94FE\u63A5";
emp.appendChild(htmlstr);
}
});
}();

1 comment |

5 stars
非常感谢 , Dec 8, 2013
Review written by kramer_happy - see all my reviews (4)

有了这个脚本就方便多了

0 comments |