From: Elijah Cohen Date: Fri, 29 Jan 2021 02:22:47 +0000 (-0600) Subject: backend for comics project done X-Git-Url: https://git.eli173.com/?a=commitdiff_plain;h=9257059fa7a8997fd70f97c348dd195db01eb355;p=comics backend for comics project done --- 9257059fa7a8997fd70f97c348dd195db01eb355 diff --git a/comics.js b/comics.js new file mode 100644 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 index 0000000..03f0791 --- /dev/null +++ b/index.html @@ -0,0 +1,12 @@ + + + + + Comics + + + + + + + diff --git a/negative.png b/negative.png new file mode 100644 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 index 0000000..2b0d1a4 --- /dev/null +++ b/node/index.js @@ -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 index 0000000..1e956be --- /dev/null +++ b/node/runner.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# runner for comics api thingy + + +while : +do + node index.js +done