Revert "Revert "🐛 Fixed error getting views and likes on a Windows built site.""

This commit is contained in:
Nuno Coração 2023-05-08 21:36:49 +01:00 committed by GitHub
parent cb77f886ea
commit 9914624b84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,22 +7,22 @@ if (typeof auth !== 'undefined') {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
var update_views = function (oid, id) {
var update_views = function (node, id) {
viewsCollection.doc(id).onSnapshot(doc => {
var data = doc.data();
if (data) {
var label = document.querySelectorAll("span[id='" + oid + "']")[0].innerText.split(' ')[1]
document.querySelectorAll("span[id='" + oid + "']")[0].innerText = numberWithCommas(data.views)
//var label = node.innerText.split(' ')[1]
node.innerText = numberWithCommas(data.views)
}
})
}
var update_likes = function (oid, id) {
var update_likes = function (node, id) {
likesCollection.doc(id).onSnapshot(doc => {
var data = doc.data();
if (data) {
var label = document.querySelectorAll("span[id='" + oid + "']")[0].innerText.split(' ')[1]
document.querySelectorAll("span[id='" + oid + "']")[0].innerText = numberWithCommas(data.likes)
//var label = node.innerText.split(' ')[1]
node.innerText = numberWithCommas(data.likes)
}
})
}
@ -33,20 +33,20 @@ if (typeof auth !== 'undefined') {
var views_nodes = document.querySelectorAll("span[id^='views_']")
for (var i in views_nodes) {
var oid = views_nodes[i].id
var id = oid ? oid.replaceAll("/", "-") : oid
var node = views_nodes[i]
var id = node.id ? node.id.replaceAll("/", "-") : node.id
if (id) {
update_views(oid, id)
update_views(node, id)
}
}
var likes_nodes = document.querySelectorAll("span[id^='likes_']")
for (var i in likes_nodes) {
var oid = likes_nodes[i].id
var id = oid ? oid.replaceAll("/", "-") : oid
var node = likes_nodes[i]
var id = node.id ? node.id.replaceAll("/", "-") : node.id
if (id) {
update_likes(oid, id)
update_likes(node, id)
}
}
})