Skip to content

Instantly share code, notes, and snippets.

@kusaanko
Last active December 2, 2022 14:12
Show Gist options
  • Save kusaanko/3dc9d04f99a4f7c6f76a6950f04c0b9c to your computer and use it in GitHub Desktop.
Save kusaanko/3dc9d04f99a4f7c6f76a6950f04c0b9c to your computer and use it in GitHub Desktop.
Amazon Keepa and Sakura Checker Plugin for Amazon Japan
// ==UserScript==
// @name Amazon Keepa and Sakura Checker
// @description Amazon Keepa and Sakura Checker Plugin for Amazon Japan
// @author Maxeo | maxeo.net, Kusaanko
// @license https://creativecommons.org/licenses/by-sa/4.0/
// @match https://www.amazon.co.jp/*
// @version 1.3.2
// @namespace https://greasyfork.org/users/88678
// ==/UserScript==
// Forked from https://greasyfork.org/ja/scripts/26852-amazon-keepa
// Added support for Amazon Japan and fixed problem not to show keepa
// Added support for Sakura Checker https://sakura-checker.jp/
function place() {
if(window.location.href.match(/https:\/\/www.amazon.*\/(dp\/*|gp\/product\/*)/)) {
var prod_code;
if (prod_code = window.location.pathname.match(/^\/gp\/product\/(.*)\/.*$/)) {
prod_code = prod_code[1]
}
else if (prod_code = window.location.pathname.match(/^\/.*\/dp\/(.*)\/.*$/)) {
prod_code = prod_code[1];
}
else if (prod_code = window.location.pathname.match(/^\/dp\/(.*)\/.*$/)) {
prod_code = prod_code[1];
}
else if(prod_code = window.location.pathname.match(/^\/gp\/product\/(.*)\\?.*$/)) {
prod_code = prod_code[1];
}
else if (prod_code = window.location.pathname.match(/^\/.*\/dp\/(.*)\\?.*$/)) {
prod_code = prod_code[1];
}
else if (prod_code = window.location.pathname.match(/^\/dp\/(.*)\\?.*$/)) {
prod_code = prod_code[1];
}
var numl=0;
switch(document.location.hostname.match('.*\.amazon\.(.*)$')[1]){
case 'com':
numl=1;
break;
case 'ca':
numl=6;
break;
case 'mx':
numl=11;
break;
case 'uk':
numl=2;
break;
case 'de':
numl=3;
break;
case 'fr':
numl=4;
break;
case 'it':
numl=8;
break;
case 'es':
numl=9;
break;
case 'co.jp':
numl=5;
break;
case 'in':
numl=10;
break;
}
var target = '#hover-zoom-end';
if(document.querySelector(target) == null) {
// Mobile
target = '#productTitleGroupAnchor';
}
appendHtml(document.querySelector(target), '<iframe style="width: 100%; height: 489px; border:0 none;overflow: hidden;" src="https://keepa.com/iframe_addon.html#'+numl+'-0-'+prod_code+'" scrolling="no" id="keepa"></iframe>');
appendHtml(document.querySelector(target), '<iframe style="width: 100%; height: 600px; border:0 none;overflow: hidden;" src="https://sakura-checker.jp/search/'+prod_code+'/" id="sakura_checker"></iframe>');
}
}
var preURL = '';
setInterval(function() {
if(window.location.href != preURL) {
preURL = window.location.href;
if(document.querySelector('#keepa') != null) {
document.querySelector('#keepa').remove();
document.querySelector('#sakura_checker').remove();
}
place();
}
}, 1000);
function appendHtml(el, str) {
var div = document.createElement('div');
div.innerHTML = str;
while (div.children.length > 0) {
el.appendChild(div.children[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment