Bad Dragonのサイズ表にセンチメートル単位を併記するTampermonkeyスクリプト。 ここをクリックしてインストールします。
Last active
June 29, 2022 19:50
-
-
Save sounisi5011/60bf67955923d29bec720597991cb7c2 to your computer and use it in GitHub Desktop.
[Tampermonkey] Bad Dragonのサイズ表にセンチメートル単位を併記するTampermonkeyスクリプト。
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
// ==UserScript== | |
// @name Show centimetre product sizes on Bad Dragon | |
// @namespace https://gist.github.com/sounisi5011/60bf67955923d29bec720597991cb7c2 | |
// @version 0.2 | |
// @author sounisi5011 | |
// @match https://bad-dragon.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=bad-dragon.com | |
// @grant none | |
// ==/UserScript== | |
function inch2centimetre(inch) { | |
return new Intl.NumberFormat('en-US', { maximumFractionDigits: 2 }) | |
.format(Number(inch) * 2.54); | |
} | |
window.addEventListener('click', () => { | |
document.querySelectorAll('table.sizing-chart__table td') | |
.forEach(tdElem => { | |
const value = tdElem.textContent; | |
if (!/^[0-9]+(?:\.[0-9]+)?$/.test(value)) return; | |
const typeName = tdElem | |
.parentElement | |
.querySelector('td:first-child').textContent; | |
if (!/\(inches\)$/i.test(typeName)) return; | |
tdElem.append( | |
document.createElement('br'), | |
`( ${inch2centimetre(value)} cm )`, | |
); | |
}); | |
}, { passive: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment