Skip to content

Instantly share code, notes, and snippets.

@piouc
Last active December 16, 2020 14:58
Show Gist options
  • Save piouc/8ad8ef07de747a7323bdc70d99581743 to your computer and use it in GitHub Desktop.
Save piouc/8ad8ef07de747a7323bdc70d99581743 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Amazon URL normalizer
// @namespace https://piou.dev
// @include https://www.amazon.co.jp/*
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
const regex = /^https:\/\/www.amazon.co.jp\/(?:.+\/)?(?:dp|gp\/product)\/([a-zA-Z0-9]+?)(?:[?\/].*|$)/
const id = location.href.match(regex)?.[1]
if(id !== null){
history.replaceState(history.state, document.title, `https://www.amazon.co.jp/dp/${id}`)
}
document.addEventListener('DOMContentLoaded', () => {
if(id !==null){
const iframe = document.createElement('iframe')
iframe.src = `https://keepa.com/iframe_addon.html#5-0-${id}`
iframe.style = 'width: 100%; height: 491px; border: 0 none'
const prevElement = document.getElementById('hover-zoom-end')
if(prevElement){
prevElement.parentNode.insertBefore(iframe, prevElement.nextElementSibling)
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment