Skip to content

Instantly share code, notes, and snippets.

@Protoff
Last active December 28, 2023 23:00
Show Gist options
  • Select an option

  • Save Protoff/d6643387f03d47b44b2d7c3cf7b3e0a0 to your computer and use it in GitHub Desktop.

Select an option

Save Protoff/d6643387f03d47b44b2d7c3cf7b3e0a0 to your computer and use it in GitHub Desktop.

Revisions

  1. Protoff revised this gist Jul 14, 2020. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions testWebp.js
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,12 @@
    function testWebP() {
    const classes = document.body.classList
    document.addEventListener('DOMContentLoaded', function() {
    testWebP(document.body)
    })

    function testWebP(elem) {
    const webP = new Image();
    webP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
    webP.onload = webP.onerror = function () {
    webP.height === 2 ? classes.add('webp-true') : classes.add('webp-false')
    webP.height === 2 ? elem.classList.add('webp-true') : elem.classList.add('webp-false')
    }
    console.log(webP)
    }
  2. Protoff revised this gist Jul 14, 2020. 1 changed file with 8 additions and 17 deletions.
    25 changes: 8 additions & 17 deletions testWebp.js
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,9 @@
    const backHeader = document.querySelector('body')
    function testWebP(callback) {
    var webP = new Image();
    webP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
    webP.onload = webP.onerror = function () {
    callback(webP.height === 2);
    };
    };

    function notify(supported) {
    if(supported) {
    backHeader.classList.add('backwebp')
    } else {
    backHeader.classList.add('notbackwebp')
    }
    function testWebP() {
    const classes = document.body.classList
    const webP = new Image();
    webP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
    webP.onload = webP.onerror = function () {
    webP.height === 2 ? classes.add('webp-true') : classes.add('webp-false')
    }

    testWebP(notify)
    console.log(webP)
    }
  3. Protoff revised this gist Jul 14, 2020. No changes.
  4. Protoff revised this gist Jul 14, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions testWebp.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    const backHeader = document.querySelector('.header .bg')
    const backHeader = document.querySelector('body')
    function testWebP(callback) {
    var webP = new Image();
    webP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
    @@ -15,4 +15,4 @@
    }
    }

    testWebP(notify)
    testWebP(notify)
  5. Protoff created this gist Apr 27, 2020.
    18 changes: 18 additions & 0 deletions testWebp.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    const backHeader = document.querySelector('.header .bg')
    function testWebP(callback) {
    var webP = new Image();
    webP.src = 'data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
    webP.onload = webP.onerror = function () {
    callback(webP.height === 2);
    };
    };

    function notify(supported) {
    if(supported) {
    backHeader.classList.add('backwebp')
    } else {
    backHeader.classList.add('notbackwebp')
    }
    }

    testWebP(notify)