Skip to content

Instantly share code, notes, and snippets.

@sounisi5011
Last active June 29, 2022 19:50
Show Gist options
  • Save sounisi5011/60bf67955923d29bec720597991cb7c2 to your computer and use it in GitHub Desktop.
Save sounisi5011/60bf67955923d29bec720597991cb7c2 to your computer and use it in GitHub Desktop.
[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 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment