~stick/print-xkcd

915f3ba8274c3f554f3a9e01e5a3f88c024c99a6 — Stick 6 months ago 1f9632a master
fix the link
1 files changed, 34 insertions(+), 29 deletions(-)

M html/index.html
M html/index.html => html/index.html +34 -29
@@ 1,37 1,40 @@
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="logo.svg"/>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="icon" href="logo.svg" />
    <script>
      function updateComic() {
        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');
        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
            link = "https://xkcd.com/" + comicNum + "/";
            document.getElementById("link").innerHTML =
              '<a href="' + link + '">' + link + "</a>";

          // 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 =
              comicNum + ": " + ctitle;

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

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

          // Get the mouseover
          const mouseover = document.getElementsByTagName('img')[0].getAttribute('title');
          document.getElementById('mouseover').innerHTML = mouseover;
        })
            // Get the mouseover
            const mouseover = document
              .getElementsByTagName("img")[0]
              .getAttribute("title");
            document.getElementById("mouseover").innerHTML = mouseover;
          });

        return false;
      }


@@ 73,7 76,9 @@
        padding: 0.2em;
      }
      @media print {
        h1, form, button {
        h1,
        form,
        button {
          display: none;
        }
      }


@@ 83,15 88,15 @@
  <body>
    <h1>print xkcd</h1>
    <main>
      <h2 id='ctitle'></h2>
      <h2 id="ctitle"></h2>
      <div id="link"></div>
      <div id="comic"></div>
      <div id="mouseover"></div>
    </main>
    <form onsubmit="return updateComic();">
      <label for="comicNum">Comic Number:</label>
      <input id="comicNum" type="text" value="1234">
      <input type="submit" value="Update">
      <input id="comicNum" type="text" value="1234" />
      <input type="submit" value="Update" />
    </form>
    <button type="button" onclick="window.print(); return false;">Print</button>
  </body>