您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Shows the ratings from Goodreads on Amazon book pages
当前为
"use strict"; // ==UserScript== // @name Amazon - Goodreads metadata // @description Shows the ratings from Goodreads on Amazon book pages // @version 0.0.1 // @include *://amazon.tld/* // @include *://*.amazon.tld/* // @license MIT // @author Brice McIver // @grant GM_xmlhttpRequest // @namespace https://gf.qytechs.cn/users/9112 // ==/UserScript== Object.defineProperty(exports, "__esModule", { value: true }); const asinRegex = /\/([A-Z0-9]{10})/; const findASIN = () => { const asinArray = []; const array = asinRegex.exec(document.location.pathname); const asin = array && array.length > 1 ? array[1] : ""; console.log(`ASIN in pathname: ${asin}`); // determine if book const dp = document.getElementById("dp"); if (dp === null || dp === void 0 ? void 0 : dp.className.includes("book")) { asinArray.push(asin); } else { // see if we are on a page with multiple books const images = document.getElementsByTagName("img"); if (images) { const coverImages = Array.from(images).filter((item) => item.classList.contains("cover-image")); if (coverImages) { coverImages.forEach((image) => { const ciArray = asinRegex.exec(image.src); const ciAsin = ciArray && ciArray.length > 1 ? ciArray[1] : ""; console.log(`ASIN on book image: ${ciAsin}`); asinArray.push(ciAsin); }); } } } return asinArray; }; const findInsertPoint = () => { // on book page const insertPoint = []; const reviewElement = document.getElementById("averageCustomerReviews"); if (reviewElement) { insertPoint.push(reviewElement); } else { // check for SHOP NOW button with review stars above. Return array const reviewArray = document.getElementsByClassName("pf-image-w"); if (reviewArray) { insertPoint.push(...Array.from(reviewArray)); } } return insertPoint; }; const insertElement = (isbn, insertPoint) => { GM.xmlHttpRequest({ method: "GET", url: `https://www.goodreads.com/book/isbn/${isbn}`, onload: (response) => { const node = new DOMParser().parseFromString(response.responseText, "text/html"); // get styles we need const head = document.getElementsByTagName("head")[0]; const styles = Array.from(node.getElementsByTagName("link")).filter((item) => item.rel === "stylesheet"); styles.forEach((item) => head.appendChild(item)); const meta = node.getElementById("bookMeta"); if (meta) { // replace links Array.from(meta.getElementsByTagName("a")).forEach((item) => { item.href = response.finalUrl + item.href.replace(item.baseURI, ""); return item; }); insertPoint.appendChild(meta); } }, }); }; const main = () => { const ASIN = findASIN(); const insertPoint = findInsertPoint(); for (let i = 0; i < ASIN.length && i < insertPoint.length; i++) { const insertPointElement = insertPoint[i].parentElement; if (insertPointElement) { insertElement(ASIN[i], insertPointElement); } } }; main(); //# sourceMappingURL=amazon-goodreads-meta.user.js.map
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址