]> git.eli173.com Git - comics/commitdiff
backend for comics project done
authorElijah Cohen <eli@eli173.com>
Fri, 29 Jan 2021 02:22:47 +0000 (20:22 -0600)
committerElijah Cohen <eli@eli173.com>
Fri, 29 Jan 2021 02:22:47 +0000 (20:22 -0600)
comics.js [new file with mode: 0644]
index.html [new file with mode: 0644]
negative.png [new file with mode: 0644]
node/index.js [new file with mode: 0644]
node/runner.sh [new file with mode: 0755]

diff --git a/comics.js b/comics.js
new file mode 100644 (file)
index 0000000..ef7db7e
--- /dev/null
+++ b/comics.js
@@ -0,0 +1,38 @@
+
+
+function onload() {
+    //imgtag = document.getElementById("image")
+    //imgtag.src = "negative.png"
+    //imgtag.src = "https://qwantz.com/comics/comic2-3900.png"
+    
+    
+    drawcomic("https://qwantz.com/comics/comic2-675.png")
+
+
+    num = window.location.search.substring(window.location.search.indexOf('=')+1)
+    getimageurl(num)
+}
+
+function getimageurl(number) {
+    // takes the comic no (from the ?comic=<>) and gets the url we want
+    // returns a promise?
+    console.log(number)
+    fetch("https://qwantz.com/index.php?comic=" + number, {mode: "cors"})
+}
+
+
+function drawcomic(imgurl) {
+    canvas = document.getElementById("canvas")
+    ctx = canvas.getContext('2d')
+    img = new Image()
+    mask = new Image()
+    mask.onload = function() {
+       ctx.drawImage(img,0,0)
+       ctx.drawImage(mask,0,0)
+    }
+    img.onload = function() {
+       mask.src = "negative.png"
+    }
+    img.src = imgurl
+    //img.src = "https://qwantz.com/comics/comic2-675.png"
+}
diff --git a/index.html b/index.html
new file mode 100644 (file)
index 0000000..03f0791
--- /dev/null
@@ -0,0 +1,12 @@
+<!doctype html>
+<meta charset="utf-8">
+<html>
+  <head>
+    <title>Comics</title>
+    <script type="text/javascript" src="comics.js"></script>
+  </head>
+  <body style="background-color: #f8f8ff;" onload="onload()">
+    <canvas id="canvas" width="735" height="500"></canvas>
+  </body>
+</html>
+
diff --git a/negative.png b/negative.png
new file mode 100644 (file)
index 0000000..80cbc51
Binary files /dev/null and b/negative.png differ
diff --git a/node/index.js b/node/index.js
new file mode 100644 (file)
index 0000000..2b0d1a4
--- /dev/null
@@ -0,0 +1,25 @@
+
+const express = require('express')
+const fetch = require('node-fetch')
+const jsdom = require('jsdom')
+const { JSDOM } = jsdom
+const app = express()
+const port = 4453
+
+
+app.get('/id/:num', (req, res) => {
+    fetch("https://qwantz.com/index.php?comic=" + req.params["num"])
+       .then(response => {
+           return response.text()
+       }).then(s => {
+           var { document } = (new JSDOM(s)).window
+           res.send(document.getElementsByClassName('comic')[0].src)
+       })
+       .catch(() => {
+           res.send("error!")
+       })
+})
+
+app.listen(port, () => {
+    console.log("listening")
+})
diff --git a/node/runner.sh b/node/runner.sh
new file mode 100755 (executable)
index 0000000..1e956be
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+# runner for comics api thingy
+
+
+while :
+do
+    node index.js
+done