~stick/print-xkcd

aa6522bfab2a7d0a003e4bcb8a818b78e8556924 — Stick 1 year, 19 days ago 8c18cad
add permalink and number detection
1 files changed, 9 insertions(+), 4 deletions(-)

M html/index.html
M html/index.html => html/index.html +9 -4
@@ 6,16 6,23 @@
    <link rel="icon" href="logo.svg"/>
    <script>
      function updateComic() {
        const comicNum = document.getElementById('comicNum').value;
        let comicNum = document.getElementById('comicNum').value;
        fetch('https://hackwhacktackbang.fyi/print-xkcd/proxy/' + comicNum).then(response => {
          return response.text()
        }).then(text => {
          const xkcd = new DOMParser().parseFromString(text, 'text/html');

          // Get the link and update the comic number (if no number entered)
          const link = xkcd.getElementById('middleContainer').innerHTML.match(/Permanent link.*/g)[0].split(": ")[1].split("<")[0]
          comicNum = link.split("/")[3]

          // Set the link
          document.getElementById('link').innerHTML = link

          // Get the page title
          const ctitle = xkcd.getElementById('ctitle').innerHTML;
          document.title = 'print xkcd: ' + ctitle;
          document.getElementById('ctitle').innerHTML = ctitle;
          document.getElementById('ctitle').innerHTML = comicNum + ': ' + ctitle;

          // Get the comic image
          const img = xkcd.getElementById('comic').innerHTML;


@@ 26,8 33,6 @@
          document.getElementById('mouseover').innerHTML = mouseover;
        })

        // Set the link
        document.getElementById('link').innerHTML = 'https://xkcd.com/' + comicNum
        return false;
      }
    </script>