File: extra.js

package info (click to toggle)
pdm 2.23.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,516 kB
  • sloc: python: 24,994; javascript: 34; makefile: 12
file content (36 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
document.addEventListener('DOMContentLoaded', function () {
  const expansionRepo = 'https://github.com/pdm-project/pdm-expansions';
  const expansionsApi = 'https://expansion.pdm-project.org/api/sample';
  const el = document.querySelector('a.pdm-expansions');

  function loadExpansions() {
    fetch(expansionsApi, { mode: 'cors', redirect: 'follow' })
      .then((response) => {
        console.log(response);
        return response.json();
      })
      .then((data) => {
        window.expansionList = data.data;
        setExpansion();
      });
  }

  function setExpansion() {
    const { expansionList } = window;
    if (!expansionList || !expansionList.length) {
      window.location.href = expansionRepo;
      return;
    }
    const expansion = expansionList[expansionList.length - 1];
    expansionList.splice(expansionList.length - 1, 1);
    el.innerText = expansion;
    if (el.style.display == 'none') {
      el.style.display = '';
    }
  }
  loadExpansions();
  el.addEventListener('click', function (e) {
    e.preventDefault();
    setExpansion();
  });
});