Skip to content

Instantly share code, notes, and snippets.

@dorianmariecom
Created January 16, 2022 21:04
Show Gist options
  • Select an option

  • Save dorianmariecom/7c126099ba54d1c3b7ba00243d360712 to your computer and use it in GitHub Desktop.

Select an option

Save dorianmariecom/7c126099ba54d1c3b7ba00243d360712 to your computer and use it in GitHub Desktop.
= javascript_tag nonce: true do
' (function() {
' const images = [...document.querySelectorAll("img")];
' let count = 0;
'
' const ready = () => {
' const div = document.createElement("div");
' div.id = "HCTIReadyNow";
' document.body.appendChild(div);
' };
'
' const onLoad = () => {
' count += 1;
' if (count >= images.length) {
' ready()
' }
' };
'
' images.forEach((image) => {
' image.onload = onLoad;
'
' if (image.complete && image.naturalHeight !== 0) {
' count += 1;
' }
' });
'
' if (images.length === count) {
' ready()
' }
' })()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment