Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>H5P Content Type Files</h1>
<p>
This is a tiny, simple gateway to H5P Group's Content Type Hub. It allows you to download the currently available H5P content types with all their dependencies as H5P files.
</p>
<div id="loadingIndicator">Loading list of content types ...</div>
<div id="errors"></div>
<div id="output"></div>
              
            
!

CSS

              
                * {
  font-family: sans-serif;
}

h1 {
  background-color: #004047;
  color: #fff;
  font-weight: bold;
  padding: 0.5rem;
}

#loadingIndicator {
  font-style: italic;

  &.display-none {
    display: none;
  }
}

#errors {
  color: #a00000;
  font-weight: bold;
  
  &.display-none {
    display: none;
  }
}
              
            
!

JS

              
                // Quick and dirty ...

const fetchH5PContentTypeCache = async () => {
    const url = 'https://api.h5p.org/v1/content-types/';
    const uuid = crypto.randomUUID();

    const formData = new FormData();
    formData.append('uuid', uuid);

    try {
      const response = await fetch(url, { method: 'POST', body: formData });

      if (!response.ok) {
        return `Error: HTTP status ${response.status}`;
      }

      const data = await response.json();
        return data.contentTypes;
      }
    catch (error) {
      return `Error fetching content types: ${error.message}`;
    }
  };

  const renderContentTypeList = (contentTypes, output, errors) => {
    output.innerHTML = '';

    if (typeof contentTypes === 'string') {
      errors.innerText = contentTypes;
      return;
    }

    const sortedContentTypes = contentTypes.sort((a, b) => a.title.localeCompare(b.title));

    const listContainer = document.createElement('ul');
    sortedContentTypes.forEach(item => {
      const version = `${item.version.major}.${item.version.minor}.${item.version.patch}`;

      const listItem = document.createElement('li');
      const link = document.createElement('a');
      link.href = '#';
      link.textContent = `${item.title} ${version}`;
      link.addEventListener('click', (event) => {
        errors.classList.add('display-none');
        event.preventDefault();
        downloadH5PContent(item.id, version, errors);
      });
      listItem.appendChild(link);
      listContainer.appendChild(listItem);
    });

    output.appendChild(listContainer);
  };

  const downloadH5PContent = async (machineName, version, errors) => {
    const url = `https://api.h5p.org/v1/content-types/${machineName}`;

    try {
      const response = await fetch(url, { method: 'POST' });

      if (!response.ok) {
        errors.classList.remove('display-none');
        errors.innerText = `HTTP error! Status: ${response.status}`;
        return;
      }

      const blob = await response.blob();
      const downloadUrl = window.URL.createObjectURL(blob);
      const a = document.createElement("a");
      a.href = downloadUrl;
      a.download = `${machineName}-${version}.h5p`;
      document.body.append(a);
      a.click();
      document.body.removeChild(a);
    }
    catch (error) {
      errors.classList.remove('display-none');
      errors.innerText = `Error downloading content type: ${error.message}`;
    }
  };

  const errors = document.querySelector('#errors');
  const output = document.querySelector('#output');
  fetchH5PContentTypeCache().then((contentTypes) => {
    document.querySelector('#loadingIndicator').classList.add('display-none');
    renderContentTypeList(contentTypes, output, errors);
  });

              
            
!
999px

Console