From 8d8d292ac26d58b3bb5fa6ee716f6ea8fffdca60 Mon Sep 17 00:00:00 2001 From: zutto Date: Sat, 15 Jun 2024 14:02:36 +0300 Subject: [PATCH] add opencollective --- src/js/components/shield.js | 36 +++++++++++++++++++ src/js/plugins/opencollective.js | 61 ++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/js/components/shield.js create mode 100644 src/js/plugins/opencollective.js diff --git a/src/js/components/shield.js b/src/js/components/shield.js new file mode 100644 index 0000000..5f8634e --- /dev/null +++ b/src/js/components/shield.js @@ -0,0 +1,36 @@ +import { html } from '../html.js'; +export class shield extends vhtml { + constructor() { + super(); + this.loader = undefined; + this.colour = "blue"; + this.style = "plastic"; + this.logo = "opencollective"; + this.logoColour = "blue"; + this.label = "gives"; + + return this; + } + /* + async loadingStart(element){ + if (this.loader !== undefined) this.loader.loadingEnd(element); + this.loader = new loader(); + this.loader.loadingStart(element); + return super.loadingStart(element); + } + + + async loadingEnd(element){ + if (this.loader !== undefined) + this.loader.loadingEnd(element); + + return super.loadingEnd(element); + } +*/ + async render(element, content) { + content = encodeURIComponent(content); + return super.render(element, ` + Static Badge of opencollective contributions + `); + } +} diff --git a/src/js/plugins/opencollective.js b/src/js/plugins/opencollective.js new file mode 100644 index 0000000..31623a5 --- /dev/null +++ b/src/js/plugins/opencollective.js @@ -0,0 +1,61 @@ +import { vj } from "../vjfw.js"; +import { shield } from "../components/shield.js"; +import { fetcher } from "../fetch.js"; + +export class OpenCollective extends shield { + constructor() { + super(); + + this._ip = ""; + this._source = "https://ip.zutto.fi/" + + vj.watcher.watch('[content="myip"]', (element) => { + this.loadingStart(element); + this.ip().then((data) => { + try { + this._ip = data.trim(); + vj.ps.publish("ip", {"ip": this._ip}); + this.render(element); + this.loadingEnd(element); + } catch (e) { + console.log("error here", e) + throw e; + } + }); + }) + } + + async ip() { + try { + const fetch = new fetcher(); + console.log("ok"); + return fetch.go({"url": `${this._source}/ip` }); + } catch (e) { + throw e; + } + } + + + async loadingStart(element) { + vj.ps.publish("ip.load.start", {"element": element}); + return super.loadingStart(element); + } + + async loadingEnd(element) { + vj.ps.publish("ip.load.end", {"element": element}); + return super.loadingEnd(element); + } + + async render(element) { + try { + const rendered = await super.render(element, "4.00 USD/Month"); + vj.ps.publish("ip.rendered", { "element": element, "rendered": rendered }); + } catch (e) { + throw e; + } + + } + +} + +