Skip to content

Instantly share code, notes, and snippets.

@shikachii
Last active December 23, 2017 14:29
Show Gist options
  • Save shikachii/64ece107706a354a1da0 to your computer and use it in GitHub Desktop.
Save shikachii/64ece107706a354a1da0 to your computer and use it in GitHub Desktop.
chrome extend
{
"name" : "AmazonWishlistPriceSum",
"version" : "2.0.0",
"manifest_version" : 2,
"description" : "アマゾンのウィッシュリスト内のアイテムの合計の値段を表示するやつ",
"content_scripts" : [
{
"matches" : [
"https://www.amazon.co.jp/gp/registry/wishlist/*",
"https://www.amazon.co.jp/registry/wishlist/*",
"https://www.amazon.co.jp/hz/wishlist/ls/*"
],
"js" : ["script.js"]
}
]
}
(function(){
"use strict";
const section = "div.price-section span span.a-offscreen"
const name = "#profile-list-name"
let sum = 0;
let prices = document.querySelectorAll(section);
for(let value of prices.values()){
if(value !== null){
const price = value.innerHTML.replace(/[^-^0-9^\.]/g,"");
sum += (price === '') ? 0 : parseInt(price,10);
}
}
console.log("合計金額:"+sum+"円");
let parent = document.querySelector(".a-container");
let listname = document.querySelector(name);
let displabel = document.createElement("h2");
let pages = document.querySelector(".a-pagination");
let page = (pages === null) ? 1 : document.querySelector("li.a-selected").firstChild.innerHTML;
displabel.innerHTML = " [" + page + "ページ目の合計金額 : " + sum + "円]";
listname.innerHTML += displabel.innerHTML;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment