mirror of
https://github.com/nunocoracao/blowfish.git
synced 2025-01-23 06:55:43 -06:00
1 line
No EOL
2.3 KiB
JavaScript
1 line
No EOL
2.3 KiB
JavaScript
var liked_page=!1,id,viewed,id_likes,liked;typeof auth!="undefined"&&(id=oid&&oid.replaceAll("/","-"),viewed=localStorage.getItem(id),viewed||auth.signInAnonymously().then(()=>{var e=db.collection("views").doc(id);localStorage.setItem(id,!0),e.get().then(e=>{e.exists?db.collection("views").doc(id).update({views:firebase.firestore.FieldValue.increment(1)}):db.collection("views").doc(id).set({views:1})}).catch(e=>{console.log("Error getting document:",e)})}).catch(e=>{var t=e.code,n=e.message;console.error(t,n)}),id_likes=oid_likes&&oid_likes.replaceAll("/","-"),liked=localStorage.getItem(id_likes),liked&&(liked_page=!0,document.querySelectorAll("span[id='likes_button_heart']")[0].style.display="",document.querySelectorAll("span[id='likes_button_emtpty_heart']")[0].style.display="none",document.querySelectorAll("span[id='likes_button_text']")[0].innerText=""));function like_article(e){auth.signInAnonymously().then(()=>{var t=db.collection("likes").doc(e);t.get().then(t=>{liked_page=!0,localStorage.setItem(e,!0),document.querySelectorAll("span[id='likes_button_heart']")[0].style.display="",document.querySelectorAll("span[id='likes_button_emtpty_heart']")[0].style.display="none",document.querySelectorAll("span[id='likes_button_text']")[0].innerText="",t.exists?db.collection("likes").doc(e).update({likes:firebase.firestore.FieldValue.increment(1)}):db.collection("likes").doc(e).set({likes:1})}).catch(e=>{console.log("Error getting document:",e)})}).catch(e=>{var t=e.code,n=e.message;console.error(t,n)})}function remove_like_article(e){auth.signInAnonymously().then(()=>{var t=db.collection("likes").doc(e);t.get().then(t=>{liked_page=!1,localStorage.removeItem(e),document.querySelectorAll("span[id='likes_button_heart']")[0].style.display="none",document.querySelectorAll("span[id='likes_button_emtpty_heart']")[0].style.display="",document.querySelectorAll("span[id='likes_button_text']")[0].innerText="\xa0Like",t.exists?db.collection("likes").doc(e).update({likes:firebase.firestore.FieldValue.increment(-1)}):db.collection("likes").doc(e).set({likes:0})}).catch(e=>{console.log("Error getting document:",e)})}).catch(e=>{var t=e.code,n=e.message;console.error(t,n)})}function process_article(){var e=oid_likes&&oid_likes.replaceAll("/","-");liked_page?remove_like_article(e):like_article(e)} |