mirror of
https://github.com/aljazceru/satshkd-vercel.git
synced 2025-12-16 20:54:23 +01:00
working
This commit is contained in:
39
calculate.js
39
calculate.js
@@ -3,17 +3,16 @@ const fs = require('fs');
|
||||
|
||||
module.exports = {
|
||||
bfx: async function() {
|
||||
const eurrate = 0.92 // approximate EUR/USD rate
|
||||
const btcDataURL = "https://api-pub.bitfinex.com/v2/ticker/tBTCUSD"
|
||||
const btcDataURL = "https://api-pub.bitfinex.com/v2/ticker/tBTCEUR"
|
||||
const response = await axios.get(btcDataURL)
|
||||
const data = response.data
|
||||
//console.log(data[6])
|
||||
|
||||
const satDenominator = 100000000
|
||||
// see docs : https://docs.bitfinex.com/reference#rest-public-ticker
|
||||
btcLastPrice = data[6]
|
||||
const btcLastPrice = data[6] // LAST_PRICE in EUR
|
||||
|
||||
const sateur = Math.round((1 / btcLastPrice) * satDenominator * eurrate)
|
||||
const sateur = Math.round(satDenominator / btcLastPrice)
|
||||
//console.log("bitfinex last price: ", btcLastPrice, "current satEUR: ", sateur)
|
||||
return sateur
|
||||
},
|
||||
@@ -28,22 +27,34 @@ module.exports = {
|
||||
hist_entries = []
|
||||
let datelist = []
|
||||
|
||||
// get all the years you need from 1 - 10
|
||||
for (let i = 1; i < 11; i++) {
|
||||
const targetDate = new Date(new Date().setFullYear(new Date().getFullYear() - i))
|
||||
const targetDateStr = targetDate.toISOString().slice(0, 10)
|
||||
// Get all years from 2011 to previous year (skip current year since it's shown at top)
|
||||
const currentDate = new Date()
|
||||
const currentYear = currentDate.getFullYear()
|
||||
const previousYear = currentYear - 1
|
||||
const startYear = 2011
|
||||
|
||||
// Find the closest date in historical data
|
||||
for (let year = startYear; year <= previousYear; year++) {
|
||||
let targetDate
|
||||
let targetDateStr
|
||||
|
||||
// For all years, use January 1st (or close to it) to find historical data
|
||||
targetDate = new Date(year, 0, 1) // January 1st of target year
|
||||
targetDateStr = targetDate.toISOString().slice(0, 10)
|
||||
|
||||
// Find the closest date in historical data for this specific year
|
||||
let closestEntry = null
|
||||
let minDiff = Infinity
|
||||
|
||||
for (let j = 0; j < historical.length; j++) {
|
||||
const entryDate = new Date(historical[j]['date'])
|
||||
const diff = Math.abs(entryDate - targetDate)
|
||||
// Only consider entries from the target year
|
||||
if (entryDate.getFullYear() === year) {
|
||||
const diff = Math.abs(entryDate - targetDate)
|
||||
|
||||
if (diff < minDiff) {
|
||||
minDiff = diff
|
||||
closestEntry = historical[j]
|
||||
if (diff < minDiff) {
|
||||
minDiff = diff
|
||||
closestEntry = historical[j]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +82,7 @@ module.exports = {
|
||||
percentage = (-100 * ((rawsat - today_sats) / rawsat)).toFixed(3)
|
||||
final_list.push({ "year": date.toLocaleDateString(), "sats": rawsat.toLocaleString("en-US"), "percent": percentage });
|
||||
}
|
||||
return final_list.reverse()
|
||||
return final_list
|
||||
} catch (error) {
|
||||
console.error("Error trying to read file ", error)
|
||||
}
|
||||
|
||||
98
index.js
98
index.js
@@ -8,7 +8,7 @@ const path = require('path');
|
||||
const app = express();
|
||||
|
||||
const handlebars = require('express-handlebars');
|
||||
const port = 3000;
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
const calculate = require('./calculate')
|
||||
const enjson = require('./locales/en-eur.json');
|
||||
@@ -54,8 +54,102 @@ app.use('/static', express.static(path.join(__dirname, 'public')));
|
||||
app.use(express.static(path.join(__dirname, 'public', 'css')));
|
||||
|
||||
|
||||
// Language mapping from browser codes to app routes
|
||||
const languageMap = {
|
||||
'en': '/en-eur',
|
||||
'en-US': '/en-eur',
|
||||
'en-GB': '/en-eur',
|
||||
'de': '/de',
|
||||
'de-DE': '/de',
|
||||
'de-AT': '/de',
|
||||
'de-CH': '/de',
|
||||
'fr': '/fr',
|
||||
'fr-FR': '/fr',
|
||||
'fr-CA': '/fr',
|
||||
'fr-BE': '/fr',
|
||||
'es': '/es',
|
||||
'es-ES': '/es',
|
||||
'es-MX': '/es',
|
||||
'es-AR': '/es',
|
||||
'it': '/it',
|
||||
'it-IT': '/it',
|
||||
'nl': '/nl',
|
||||
'nl-NL': '/nl',
|
||||
'nl-BE': '/nl',
|
||||
'pt': '/pt',
|
||||
'pt-PT': '/pt',
|
||||
'pt-BR': '/pt',
|
||||
'pl': '/pl',
|
||||
'pl-PL': '/pl',
|
||||
'bg': '/bg',
|
||||
'bg-BG': '/bg',
|
||||
'hr': '/hr',
|
||||
'hr-HR': '/hr',
|
||||
'cs': '/cs',
|
||||
'cs-CZ': '/cs',
|
||||
'da': '/da',
|
||||
'da-DK': '/da',
|
||||
'et': '/et',
|
||||
'et-EE': '/et',
|
||||
'fi': '/fi',
|
||||
'fi-FI': '/fi',
|
||||
'el': '/el',
|
||||
'el-GR': '/el',
|
||||
'hu': '/hu',
|
||||
'hu-HU': '/hu',
|
||||
'ga': '/ga',
|
||||
'ga-IE': '/ga',
|
||||
'lv': '/lv',
|
||||
'lv-LV': '/lv',
|
||||
'lt': '/lt',
|
||||
'lt-LT': '/lt',
|
||||
'mt': '/mt',
|
||||
'mt-MT': '/mt',
|
||||
'ro': '/ro',
|
||||
'ro-RO': '/ro',
|
||||
'sk': '/sk',
|
||||
'sk-SK': '/sk',
|
||||
'sl': '/sl',
|
||||
'sl-SI': '/sl',
|
||||
'sv': '/sv',
|
||||
'sv-SE': '/sv'
|
||||
};
|
||||
|
||||
function getLanguageFromHeader(acceptLanguage) {
|
||||
if (!acceptLanguage) return '/en-eur';
|
||||
|
||||
// Parse Accept-Language header
|
||||
const languages = acceptLanguage.split(',').map(lang => {
|
||||
const [locale, quality = 'q=1.0'] = lang.trim().split(';');
|
||||
const q = quality.split('=')[1] || '1.0';
|
||||
return { locale, q: parseFloat(q) };
|
||||
});
|
||||
|
||||
// Sort by quality (highest first)
|
||||
languages.sort((a, b) => b.q - a.q);
|
||||
|
||||
// Find first supported language
|
||||
for (const { locale } of languages) {
|
||||
// Check exact match first
|
||||
if (languageMap[locale]) {
|
||||
return languageMap[locale];
|
||||
}
|
||||
|
||||
// Check primary language (e.g., 'en' from 'en-US')
|
||||
const primaryLang = locale.split('-')[0];
|
||||
if (languageMap[primaryLang]) {
|
||||
return languageMap[primaryLang];
|
||||
}
|
||||
}
|
||||
|
||||
// Default to English if no supported language found
|
||||
return '/en-eur';
|
||||
}
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
res.redirect('/en-eur');
|
||||
const acceptLanguage = req.headers['accept-language'];
|
||||
const targetLanguage = getLanguageFromHeader(acceptLanguage);
|
||||
res.redirect(targetLanguage);
|
||||
});
|
||||
|
||||
// EUR routes
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Дата",
|
||||
"price": "Цена",
|
||||
"percentchange": "Процентна Промяна",
|
||||
"footnote": "източник на данни от usdsat.com, адаптиран за EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Datum",
|
||||
"price": "Cena",
|
||||
"percentchange": "Procentní Změna",
|
||||
"footnote": "zdroj dat z usdsat.com, přizpůsobeno pro EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Dato",
|
||||
"price": "Pris",
|
||||
"percentchange": "Procentvis Ændring",
|
||||
"footnote": "datakilde fra usdsat.com, tilpasset til EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Datum",
|
||||
"price": "Preis",
|
||||
"percentchange": "Prozentuale Änderung",
|
||||
"footnote": "Datenquelle von usdsat.com, angepasst für EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/fr/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Ημερομηνία",
|
||||
"price": "Τιμή",
|
||||
"percentchange": "Ποσοστιαία Αλλαγή",
|
||||
"footnote": "πηγή δεδομένων από usdsat.com, προσαρμοσμένο για EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Date",
|
||||
"price": "Price",
|
||||
"percentchange": "Percent Change",
|
||||
"footnote": "data source from usdsat.com, adapted for EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/de/",
|
||||
"lang1": "Deutsch",
|
||||
"lang2_link": "/fr/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Fecha",
|
||||
"price": "Precio",
|
||||
"percentchange": "Cambio Porcentual",
|
||||
"footnote": "fuente de datos de usdsat.com, adaptado para EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Kuupäev",
|
||||
"price": "Hind",
|
||||
"percentchange": "Protsentuaalne Muutus",
|
||||
"footnote": "andmete allikas usdsat.com, kohandatud EUR jaoks",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Päivämäärä",
|
||||
"price": "Hinta",
|
||||
"percentchange": "Prosentuaalinen Muutos",
|
||||
"footnote": "tietolähde usdsat.com, mukautettu EUR:lle",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Date",
|
||||
"price": "Prix",
|
||||
"percentchange": "Variation en Pourcentage",
|
||||
"footnote": "source de données de usdsat.com, adaptée pour EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Dáta",
|
||||
"price": "Praghas",
|
||||
"percentchange": "Athrú Céatadáin",
|
||||
"footnote": "foinse sonraí ó usdsat.com, curtha in oiriúint d'EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Datum",
|
||||
"price": "Cijena",
|
||||
"percentchange": "Postotna Promjena",
|
||||
"footnote": "izvor podataka od usdsat.com, prilagođeno za EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Dátum",
|
||||
"price": "Ár",
|
||||
"percentchange": "Százalékos Változás",
|
||||
"footnote": "adatforrás usdsat.com, adaptálva EUR-ra",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Data",
|
||||
"price": "Prezzo",
|
||||
"percentchange": "Variazione Percentuale",
|
||||
"footnote": "fonte dati da usdsat.com, adattato per EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Data",
|
||||
"price": "Kaina",
|
||||
"percentchange": "Procentinis Pokytis",
|
||||
"footnote": "duomenų šaltinis iš usdsat.com, pritaikytas EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Datums",
|
||||
"price": "Cena",
|
||||
"percentchange": "Procentuālā Izmaiņa",
|
||||
"footnote": "datu avots no usdsat.com, pielāgots EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Data",
|
||||
"price": "Prezz",
|
||||
"percentchange": "Bidla Perċentwali",
|
||||
"footnote": "sors tad-dejta minn usdsat.com, adattat għal EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Datum",
|
||||
"price": "Prijs",
|
||||
"percentchange": "Procentuele Verandering",
|
||||
"footnote": "gegevensbron van usdsat.com, aangepast voor EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Data",
|
||||
"price": "Cena",
|
||||
"percentchange": "Zmiana Procentowa",
|
||||
"footnote": "źródło danych z usdsat.com, dostosowane dla EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Data",
|
||||
"price": "Preço",
|
||||
"percentchange": "Variação Percentual",
|
||||
"footnote": "fonte de dados de usdsat.com, adaptado para EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Data",
|
||||
"price": "Preț",
|
||||
"percentchange": "Schimbare Procentuală",
|
||||
"footnote": "sursa de date de la usdsat.com, adaptată pentru EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Dátum",
|
||||
"price": "Cena",
|
||||
"percentchange": "Percentuálna Zmena",
|
||||
"footnote": "zdroj údajov z usdsat.com, prispôsobené pre EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Datum",
|
||||
"price": "Cena",
|
||||
"percentchange": "Odstotna Sprememba",
|
||||
"footnote": "vir podatkov iz usdsat.com, prilagojen za EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
"date": "Datum",
|
||||
"price": "Pris",
|
||||
"percentchange": "Procentuell Förändring",
|
||||
"footnote": "datakälla från usdsat.com, anpassad för EUR",
|
||||
"footnote": "",
|
||||
"data_file": "historical",
|
||||
"rate_field": "sateur_rate",
|
||||
"exchange_rate": "0.92",
|
||||
"lang1_link": "/en-eur/",
|
||||
"lang1": "English",
|
||||
"lang2_link": "/de/",
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
"description": "EUR/Sats historical chart - Deploy express js to vercel.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
"start": "node index.js",
|
||||
"dev": "node index.js",
|
||||
"port8080": "PORT=8080 node index.js",
|
||||
"port5000": "PORT=5000 node index.js",
|
||||
"port8000": "PORT=8000 node index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22"
|
||||
|
||||
8953
public/historical
8953
public/historical
File diff suppressed because one or more lines are too long
@@ -12,7 +12,18 @@
|
||||
<script src="/static/chart.min.js"></script>
|
||||
<script src="/static/chartjs-adapter-date-fns.min.js"></script>
|
||||
<script src="/static/chartjs-plugin-annotation.min.js"></script>
|
||||
<script async src="https://analytics.umami.is/script.js" data-website-id="d35ba036-3531-422c-be04-74711c97799c"></script>
|
||||
<script>
|
||||
// Auto-detect domain for Plausible Analytics
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const domain = window.location.hostname;
|
||||
const script = document.createElement('script');
|
||||
script.async = true;
|
||||
script.defer = true;
|
||||
script.setAttribute('data-domain', domain);
|
||||
script.src = 'https://your-plausible-instance.com/js/script.js';
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
</script>
|
||||
<!-- JavaScript Bundle with Popper -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-p34f1UUtsS3wqzfto5wAAmdvj+osOnFyQFpp4Ua3gs/ZVWx6oOypYoCJhGGScy+8" crossorigin="anonymous"></script>
|
||||
<style>
|
||||
@@ -25,42 +36,7 @@
|
||||
|
||||
<body>
|
||||
|
||||
<header class="p-1 bg-dark text-white">
|
||||
<nav class="navbar navbar-expand-lg navbar-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="http://bitcoin.org.hk">
|
||||
<img src="/static/bahk-logo-big-white.svg" alt="Bitcoin HK Logo" width="60">
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="true" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarText">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active px-2 text-secondary" aria-current="page" href="http://sats.bitcoin.org.hk">Sats</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link px-2 text-white" href="http://blocks.bitcoin.org.hk">Blocks</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link px-2 text-white" href="https://rates.bitcoin.org.hk">Rates</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link px-2 text-white" href="http://stack.bitcoin.org.hk/">Stack</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link px-2 text-white" href="https://laisee.org">Laisee</a>
|
||||
</li>
|
||||
</ul>
|
||||
<span class="navbar-item" style="color: #fff">
|
||||
<a class="px-2" href="{{ lang1_link }}" style="color: rgb(6, 168, 231)"> {{ lang1 }} </a>{{#if lang2}} | <a class="px-2" href="{{ lang2_link }}" style="color: rgb(6, 168, 231)"> {{ lang2 }}</a>{{/if}}{{#if lang3}} | <a class="px-2" href="{{ lang3_link }}" style="color: rgb(6, 168, 231)"> {{ lang3 }}</a>{{/if}}{{#if lang4}} | <a class="px-2" href="{{ lang4_link }}" style="color: rgb(6, 168, 231)"> {{ lang4 }}</a>{{/if}}{{#if lang5}} | <a class="px-2" href="{{ lang5_link }}" style="color: rgb(6, 168, 231)"> {{ lang5 }}</a>{{/if}}{{#if lang6}} | <a class="px-2" href="{{ lang6_link }}" style="color: rgb(6, 168, 231)"> {{ lang6 }}</a>{{/if}}{{#if lang7}} | <a class="px-2" href="{{ lang7_link }}" style="color: rgb(6, 168, 231)"> {{ lang7 }}</a>{{/if}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="container" style="margin-top: 40px;">
|
||||
<div class="container" style="margin-top: 20px;">
|
||||
<div class="row">
|
||||
<center>
|
||||
<h3> {{ Title }} <span id="current"></span> sats</h3>
|
||||
@@ -77,12 +53,12 @@
|
||||
t = new WebSocket("wss://api-pub.bitfinex.com/ws/2");
|
||||
|
||||
t.onmessage = function(e) {
|
||||
var i = JSON.parse(e.data);
|
||||
if (i.event === 'subscribed' && i.channel == 'ticker') {
|
||||
ws_ticker_id = i.chanId;
|
||||
var msg = JSON.parse(e.data);
|
||||
if (msg.event === 'subscribed' && msg.channel == 'ticker') {
|
||||
ws_ticker_id = msg.chanId;
|
||||
}
|
||||
if (ws_ticker_id == i[0]) {
|
||||
updatePrice(i);
|
||||
if (Array.isArray(msg) && msg[0] === ws_ticker_id && Array.isArray(msg[1])) {
|
||||
updatePrice(msg[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +67,7 @@
|
||||
t.send(JSON.stringify({
|
||||
"event": "subscribe",
|
||||
"channel": "ticker",
|
||||
"symbol": "BTCUSD"
|
||||
"symbol": "tBTCEUR"
|
||||
}));
|
||||
setPingTimer();
|
||||
}
|
||||
@@ -114,18 +90,12 @@
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
function updatePrice(i) {
|
||||
if (Array.isArray(i)) {
|
||||
i.forEach(function(item) {
|
||||
if (Array.isArray(item)) {
|
||||
var btc_price = item[0];
|
||||
currentPrice = Math.round((1 / btc_price) * 100000000 / {{ exchange_rate }}); // satoshis per currency unit
|
||||
document.title = currentPrice.toLocaleString() + " sats";
|
||||
document.querySelector('#current').textContent = currentPrice.toLocaleString();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
function updatePrice(tickerArray) {
|
||||
// Bitfinex ticker format: [ BID, BID_SIZE, ASK, ASK_SIZE, DAILY_CHANGE, DAILY_CHANGE_PERC, LAST_PRICE, VOLUME, HIGH, LOW ]
|
||||
var lastPriceEur = tickerArray[6];
|
||||
currentPrice = Math.round(100000000 / lastPriceEur); // sats per EUR
|
||||
document.title = currentPrice.toLocaleString() + " sats";
|
||||
document.querySelector('#current').textContent = currentPrice.toLocaleString();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -155,10 +125,7 @@
|
||||
</table>
|
||||
|
||||
|
||||
<p style="font-size: small;">
|
||||
* {{ footnote }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
// Load data and initialize chart
|
||||
fetch('/{{ data_file }}')
|
||||
@@ -176,9 +143,9 @@
|
||||
const minValue = Math.min(...values);
|
||||
const maxValue = Math.max(...values);
|
||||
|
||||
// Add padding for logarithmic scale (multiply/divide by factor)
|
||||
const yAxisMin = Math.floor(minValue / 2);
|
||||
const yAxisMax = Math.ceil(maxValue * 2);
|
||||
// Add more padding for better visualization, especially at bottom
|
||||
const yAxisMin = Math.floor(minValue / 50); // Much more padding at bottom
|
||||
const yAxisMax = Math.ceil(maxValue * 2.5); // Less padding at top for flatter look
|
||||
|
||||
// Calculate responsive height
|
||||
const windowWidth = window.innerWidth;
|
||||
@@ -197,10 +164,6 @@
|
||||
const qeLink = () => window.open('https://en.wikipedia.org/wiki/Quantitative_easing', '_blank');
|
||||
|
||||
const markers = [{
|
||||
date: new Date('2008-11-25T00:00:00.000Z'),
|
||||
label: 'QE1',
|
||||
click: qeLink,
|
||||
}, {
|
||||
date: new Date('2010-11-03T00:00:00.000Z'),
|
||||
label: 'QE2',
|
||||
click: qeLink,
|
||||
|
||||
Reference in New Issue
Block a user