init opencollective
This commit is contained in:
parent
9c8be1a264
commit
51736175b7
3 changed files with 24 additions and 11 deletions
|
@ -4,10 +4,11 @@ import '../css/tripledot.css';
|
|||
|
||||
import { MyIP } from './plugins/myip.js';
|
||||
import { Time } from './plugins/time.js';
|
||||
|
||||
import { OpenCollective } from './plugins/opencollective.js';
|
||||
|
||||
|
||||
(function() {
|
||||
var time = new Time();
|
||||
var myip = new MyIP();
|
||||
var opencollective = new OpenCollective();
|
||||
})();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { html } from '../html.js';
|
||||
import { vhtml } from './vhtml.js';
|
||||
export class shield extends vhtml {
|
||||
constructor() {
|
||||
super();
|
||||
|
|
|
@ -7,14 +7,22 @@ export class OpenCollective extends shield {
|
|||
super();
|
||||
|
||||
this._ip = "";
|
||||
this._source = "https://ip.zutto.fi/"
|
||||
this._source = "https://rest.opencollective.com/v2/zutto/transactions.json"
|
||||
|
||||
vj.watcher.watch('[content="myip"]', (element) => {
|
||||
vj.watcher.watch('[content="opencollective"]', (element) => {
|
||||
this.loadingStart(element);
|
||||
this.ip().then((data) => {
|
||||
try {
|
||||
this._ip = data.trim();
|
||||
vj.ps.publish("ip", {"ip": this._ip});
|
||||
this.json = JSON.parse(data);
|
||||
this.total = {};
|
||||
this.json.data.forEach((item) => {
|
||||
if (this.total[item.currency]) {
|
||||
this.total[item.currency] += item.amount * -1;
|
||||
} else {
|
||||
this.total[item.currency] = item.amount * -1;
|
||||
}
|
||||
});
|
||||
|
||||
this.render(element);
|
||||
this.loadingEnd(element);
|
||||
} catch (e) {
|
||||
|
@ -29,13 +37,13 @@ export class OpenCollective extends shield {
|
|||
try {
|
||||
const fetch = new fetcher();
|
||||
console.log("ok");
|
||||
return fetch.go({"url": `${this._source}/ip` });
|
||||
return fetch.go({"url": `${this._source}` });
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
async loadingStart(element) {
|
||||
vj.ps.publish("ip.load.start", {"element": element});
|
||||
return super.loadingStart(element);
|
||||
|
@ -45,11 +53,15 @@ export class OpenCollective extends shield {
|
|||
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 });
|
||||
var total = "";
|
||||
this.total.forEach((currency) => {
|
||||
total += `${this.total[currency]} ${currency}/Month`;
|
||||
});
|
||||
|
||||
const rendered = await super.render(element, `${total}`);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue