Skip to content

Instantly share code, notes, and snippets.

@3110
Last active October 13, 2022 15:17
Show Gist options
  • Save 3110/74c109ce3505da28830f9c3963d6e0c5 to your computer and use it in GitHub Desktop.
Save 3110/74c109ce3505da28830f9c3963d6e0c5 to your computer and use it in GitHub Desktop.
Amazonが出荷元になっている商品ページを表示する
// ==UserScript==
// @name Amazon Lover
// @namespace https://github.com/3110
// @version 0.5
// @include https://www.amazon.co.jp/*
// @run-at document-start
// @description Remove all parameters in URL and add the parameter m=AN1VRQENFRJN5 to URL
// @author SAITO, Tetsuya <saito.tetsuya@gmail.com>
// @grant none
// ==/UserScript==
const AMAZON_URL_BASE = 'https://www.amazon.co.jp/dp/';
const AMAZON_ONLY_PARAM = "?m=AN1VRQENFRJN5";
const AUTHOR_PAGE_REGEX = /\/(e|author)\//;
const KINDLE_REGEX = /-ebook\//;
const ASIN_REGEX = /\/([a-zA-Z0-9]{10})[/?]/;
(function() {
'use strict';
const url = location.href;
if (url.indexOf(AMAZON_ONLY_PARAM) != -1) { // already added
return;
}
if (url.match(KINDLE_REGEX)) { // do not add the param to Kindle page
return;
}
if (url.match(AUTHOR_PAGE_REGEX)) { // do not add the param to author's page
return;
}
const asin = url.match(ASIN_REGEX);
if (asin) {
location.href = AMAZON_URL_BASE + asin[1] + '/' + AMAZON_ONLY_PARAM;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment