Show centimetre product sizes on Bad Dragon
Bad Dragonのサイズ表にセンチメートル単位を併記するTampermonkeyスクリプト。 ここをクリックしてインストールします。
Bad Dragonのサイズ表にセンチメートル単位を併記するTampermonkeyスクリプト。 ここをクリックしてインストールします。
// ==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 }); |