Skip to content

Instantly share code, notes, and snippets.

@uhyo
Created November 4, 2020 01:44
Show Gist options
  • Save uhyo/d52ca650225a4c34b55b60312f9d1a16 to your computer and use it in GitHub Desktop.
Save uhyo/d52ca650225a4c34b55b60312f9d1a16 to your computer and use it in GitHub Desktop.
Googleの大統領選の結果の州をクリックすると色を変えられるやつ2020
(()=>{
const svg = document.querySelector('svg.vlmbi.H21Mnd');
const svg2 = cl(svg);
const paths = svg2.querySelectorAll('path.xH0v4d');
const cs = [
'rgb(218, 220, 224)',
'rgb(0, 155, 216)',
'rgb(166, 220, 241)',
'rgb(241, 176, 180)',
'rgb(219, 29, 40)',
];
for (let i=0, l=paths.length; i<l; i++){
const p = paths[i];
p.addEventListener('click', e=>{
const f = p.style.fill;
const i = cs.indexOf(f);
p.style.fill = cs[(i+1)%cs.length];
}, false);
}
function cl(svg){
const re = svg.getBoundingClientRect();
const svg2 = svg.cloneNode(true);
document.body.appendChild(svg2);
svg2.style.position='absolute';
svg2.style.left=(re.left+window.pageXOffset)+'px';
svg2.style.top=(re.top+window.pageYOffset)+'px';
svg2.style.zIndex='100000';
return svg2;
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment