mirror of
https://github.com/ThisIsBenny/iOS-Widgets.git
synced 2025-04-19 15:27:40 +00:00
Ecosia Widget
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
a1f4d70eab
commit
6f5bff8165
6 changed files with 93 additions and 0 deletions
77
Ecosia/Ecosia.js
Normal file
77
Ecosia/Ecosia.js
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
// Variables used by Scriptable.
|
||||||
|
// These must be at the very top of the file. Do not edit.
|
||||||
|
// icon-color: brown; icon-glyph: magic;
|
||||||
|
// Version 1.0.0
|
||||||
|
|
||||||
|
let widgetInputRAW = args.widgetParameter;
|
||||||
|
let token;
|
||||||
|
if (widgetInputRAW !== null) {
|
||||||
|
token = widgetInputRAW.toString();
|
||||||
|
} else {
|
||||||
|
throw new Error('No token set via widget parameter! You can request a token here: https://www.ecosia.org/account/login')
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
async function getTreeCounter(token) {
|
||||||
|
let req = new Request("https://api.ecosia.org/v1/accounts/personalcounter?token=" + token)
|
||||||
|
let res = await req.loadJSON()
|
||||||
|
return parseInt(res.counterValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getLogo() {
|
||||||
|
let fm = FileManager.local()
|
||||||
|
const pathLogo = fm.joinPath(fm.temporaryDirectory(), 'ecosiaLogo')
|
||||||
|
|
||||||
|
if (fm.fileExists(pathLogo)) {
|
||||||
|
return fm.readImage(pathLogo)
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
let req = new Request('https://uc948e7ad6c396973f81d540ee4f.dl.dropboxusercontent.com/cd/0/get/BCSgEaIvDEkR-T7KEmiGl3_qHREwC9xuXRJpUM61i27BB3_qczSDa8yH6wlK5CoRtSKikI6G-iGN7AdM-xRpFO9g5ahznpU7kfJVEy7SGvR2Gw/file?_download_id=9234590427327855751170888564094591338853848773569417305635998585&_notify_domain=www.dropbox.com&dl=1')
|
||||||
|
let logo = await req.loadImage()
|
||||||
|
fm.writeImage(pathLogo, logo)
|
||||||
|
return logo
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let treeCounter = await getTreeCounter(token);
|
||||||
|
let ecosiaLogo = await getLogo()
|
||||||
|
// Create Widget
|
||||||
|
let widget = new ListWidget();
|
||||||
|
widget.url = 'https://ecosia.org/'
|
||||||
|
|
||||||
|
widget.setPadding(10, 10, 10, 10)
|
||||||
|
|
||||||
|
if (ecosiaLogo !== null) {
|
||||||
|
let titleLogo = widget.addImage(ecosiaLogo)
|
||||||
|
titleLogo.imageSize = new Size(50, 50)
|
||||||
|
titleLogo.rightAlignImage()
|
||||||
|
if (config.widgetFamily === 'large') {
|
||||||
|
widget.addSpacer()
|
||||||
|
} else {
|
||||||
|
widget.addSpacer(5)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let title = widget.addText("Ecosia")
|
||||||
|
title.font = Font.mediumSystemFont(12)
|
||||||
|
widget.addSpacer()
|
||||||
|
}
|
||||||
|
|
||||||
|
let counterText = widget.addText(`${treeCounter.toLocaleString(Device.locale().replace('_', '-'))} 🌳`)
|
||||||
|
counterText.font = Font.regularSystemFont(36)
|
||||||
|
counterText.minimumScaleFactor = 0.7;
|
||||||
|
counterText.lineLimit = 1
|
||||||
|
counterText.centerAlignText()
|
||||||
|
|
||||||
|
widget.addSpacer()
|
||||||
|
|
||||||
|
if (!config.runsInWidget) {
|
||||||
|
await widget.presentSmall()
|
||||||
|
} else {
|
||||||
|
// Tell the system to show the widget.
|
||||||
|
Script.setWidget(widget)
|
||||||
|
Script.complete()
|
||||||
|
}
|
16
Ecosia/README.md
Normal file
16
Ecosia/README.md
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# Ecosia Tree Counter
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
This widget allows you to save the location of your car, which will then displayed in the widget as a map. So you know exactly where you parked.
|
||||||
|
If you don't know the way to the car anymore, you can start the navigation to the car's location with one click and let Apple Maps or Google Maps navigate you.
|
||||||
|
|
||||||
|
[[Download]](https://raw.githubusercontent.com/ThisIsBenny/iOS-Widgets/main/Ecosia/Ecosia.js)
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
For this widget is a ecosia account required. Go to https://www.ecosia.org/account/login and enter your E-Mail address. You will recieve a E-Mail with a link.
|
||||||
|
Use this Link on all your devices where you use Ecosia to connect all Devices to one counter (you can request the Mail multiple time, import is that the E-Mail address is always the same).
|
||||||
|
After this, you have to copy the token from the Link in the E-Mail and paste the token to the widget parameter
|
||||||
|
|
||||||
|

|
||||||
|

|
BIN
Ecosia/previewDark.jpeg
Normal file
BIN
Ecosia/previewDark.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.2 KiB |
BIN
Ecosia/previewLight.jpeg
Normal file
BIN
Ecosia/previewLight.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
BIN
Ecosia/setup.jpeg
Normal file
BIN
Ecosia/setup.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 28 KiB |
BIN
Ecosia/token.jpeg
Normal file
BIN
Ecosia/token.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
Loading…
Add table
Reference in a new issue