Last active
August 6, 2022 08:58
-
-
Save htsutsui/37a9b49ed41d75700ffe4f3f29d121f0 to your computer and use it in GitHub Desktop.
amazon の URL から無駄な文字列を除去する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>Amazon URL Shortner</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> | |
<script> | |
$(function () { | |
const re = /(https:\/\/www\.amazon\.co\.jp\/)(?:.*?\/){0,1}(?:dp|gp\/product)\/([0-9A-Z]{10})/ | |
$('button#clear').on('click', function () { | |
$('textarea').val('') | |
$('#result').empty() | |
}) | |
$('button#submit').on('click', function () { | |
$('#result').empty() | |
$('textarea').val().split(/\r\n|\r|\n/).forEach(line => { | |
const m = line.match(re) | |
if (m) { | |
const url = m[1] + 'dp/' + m[2] + '/' | |
$('#result').append( | |
$('<li/>').html($('<a/>', { href: url, text: url })) | |
) | |
} | |
}) | |
}) | |
}) | |
</script> | |
<style> | |
#text | |
{ | |
width: 100%; | |
height: 100pt; | |
} | |
</style> | |
</head> | |
<body> | |
<textarea id="text"></textarea> | |
<p><button id="submit">Convert</button><button id="clear">Clear</button></p> | |
<ul id="result"></ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://htsutsui.github.io/amazon.html