mirror of
https://github.com/nunocoracao/blowfish.git
synced 2026-01-30 15:31:52 +00:00
fixe issue with analytics and new hugo update
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
const sitePreference = document.documentElement.getAttribute("data-default-appearance");
|
||||
const userPreference = localStorage.getItem("appearance");
|
||||
|
||||
if ((sitePreference === "dark" && userPreference === null) || userPreference === "dark") {
|
||||
document.documentElement.classList.add("dark");
|
||||
}
|
||||
|
||||
if (document.documentElement.getAttribute("data-auto-appearance") === "true") {
|
||||
if (
|
||||
window.matchMedia &&
|
||||
window.matchMedia("(prefers-color-scheme: dark)").matches &&
|
||||
userPreference !== "light"
|
||||
) {
|
||||
document.documentElement.classList.add("dark");
|
||||
}
|
||||
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (event) => {
|
||||
if (event.matches) {
|
||||
document.documentElement.classList.add("dark");
|
||||
} else {
|
||||
document.documentElement.classList.remove("dark");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener("DOMContentLoaded", (event) => {
|
||||
const switcher = document.getElementById("appearance-switcher");
|
||||
const switcherMobile = document.getElementById("appearance-switcher-mobile");
|
||||
|
||||
updateMeta();
|
||||
this.updateLogo?.(getTargetAppearance());
|
||||
|
||||
if (switcher) {
|
||||
switcher.addEventListener("click", () => {
|
||||
document.documentElement.classList.toggle("dark");
|
||||
var targetAppearance = getTargetAppearance();
|
||||
localStorage.setItem(
|
||||
"appearance",
|
||||
targetAppearance
|
||||
);
|
||||
updateMeta();
|
||||
this.updateLogo?.(targetAppearance);
|
||||
});
|
||||
switcher.addEventListener("contextmenu", (event) => {
|
||||
event.preventDefault();
|
||||
localStorage.removeItem("appearance");
|
||||
});
|
||||
}
|
||||
if (switcherMobile) {
|
||||
switcherMobile.addEventListener("click", () => {
|
||||
document.documentElement.classList.toggle("dark");
|
||||
var targetAppearance = getTargetAppearance();
|
||||
localStorage.setItem(
|
||||
"appearance",
|
||||
targetAppearance
|
||||
);
|
||||
updateMeta();
|
||||
this.updateLogo?.(targetAppearance);
|
||||
});
|
||||
switcherMobile.addEventListener("contextmenu", (event) => {
|
||||
event.preventDefault();
|
||||
localStorage.removeItem("appearance");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
var updateMeta = () => {
|
||||
var elem, style;
|
||||
elem = document.querySelector('body');
|
||||
style = getComputedStyle(elem);
|
||||
document.querySelector('meta[name="theme-color"]').setAttribute('content', style.backgroundColor);
|
||||
}
|
||||
|
||||
{{ if and (.Site.Params.Logo) (.Site.Params.SecondaryLogo) }}
|
||||
{{ $primaryLogo := resources.Get .Site.Params.Logo }}
|
||||
{{ $secondaryLogo := resources.Get .Site.Params.SecondaryLogo }}
|
||||
{{ if and ($primaryLogo) ($secondaryLogo) }}
|
||||
var updateLogo = (targetAppearance) => {
|
||||
var elems;
|
||||
elems = document.querySelectorAll("img.logo")
|
||||
targetLogoPath =
|
||||
targetAppearance == "{{ .Site.Params.DefaultAppearance }}" ?
|
||||
"{{ $primaryLogo.RelPermalink }}" : "{{ $secondaryLogo.RelPermalink }}"
|
||||
for (const elem of elems) {
|
||||
elem.setAttribute("src", targetLogoPath)
|
||||
}
|
||||
}
|
||||
{{ end }}
|
||||
{{- end }}
|
||||
|
||||
var getTargetAppearance = () => {
|
||||
return document.documentElement.classList.contains("dark") ? "dark" : "light"
|
||||
}
|
||||
|
||||
window.addEventListener("DOMContentLoaded", (event) => {
|
||||
const scroller = document.getElementById("top-scroller");
|
||||
const footer = document.getElementById("site-footer");
|
||||
if(scroller && footer && scroller.getBoundingClientRect().top > footer.getBoundingClientRect().top) {
|
||||
scroller.hidden = true;
|
||||
}
|
||||
});
|
||||
+17
File diff suppressed because one or more lines are too long
+1
@@ -0,0 +1 @@
|
||||
var layouts=["background","hero","profile","page","card"],list_config,titles,currentConfig,currentLayout=0;function switchHomeLayout(){var e,t,n=currentLayout;currentLayout=currentLayout==layouts.length-1?0:currentLayout+1,e=document.getElementById(layouts[n]),t=document.getElementById(layouts[currentLayout]);const s=document.querySelectorAll("code[id=layout]");t.style.display="block",e.style.display="none",s.forEach(function(e){e.innerText=layouts[currentLayout]})}window.addEventListener("DOMContentLoaded",e=>{document.querySelectorAll("#switch-layout-button").forEach(e=>e.addEventListener("click",function(e){e.preventDefault(),switchHomeLayout()}))}),list_config=["CardViewProse","CardViewScreenWidth","NormalView"],titles={CardViewProse:"card view with constrained width",CardViewScreenWidth:"card view with full width",NormalView:"standard list view"},currentConfig=0;function switchList(){var e,t,n=currentConfig;currentConfig=currentConfig==list_config.length-1?0:currentConfig+1,e=document.getElementById(list_config[n]),t=document.getElementById(list_config[currentConfig]);const s=document.querySelectorAll("code[id=config]");t.style.display="block",e.style.display="none",s.forEach(function(e){e.innerText=titles[list_config[currentConfig]]})}window.addEventListener("DOMContentLoaded",e=>{document.querySelectorAll("#switch-config-button").forEach(e=>e.addEventListener("click",function(e){e.preventDefault(),switchList()}))})
|
||||
+1
@@ -0,0 +1 @@
|
||||
if(typeof auth!="undefined"){var viewsCollection=db.collection("views"),update_views,update_likes,likesCollection=db.collection("likes");function numberWithCommas(e){return e.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")}update_views=function(e,t){viewsCollection.doc(t).onSnapshot(t=>{var n=t.data();n&&(e.innerText=numberWithCommas(n.views))})},update_likes=function(e,t){likesCollection.doc(t).onSnapshot(t=>{var n=t.data();n&&(e.innerText=numberWithCommas(n.likes))})},auth.signInAnonymously().then(()=>{var e,t,n,s,o=document.querySelectorAll("span[id^='views_']");for(n in o)e=o[n],t=e.id?e.id.replaceAll("/","-"):e.id,t&&update_views(e,t);s=document.querySelectorAll("span[id^='likes_']");for(n in s)e=s[n],t=e.id?e.id.replaceAll("/","-"):e.id,t&&update_likes(e,t)}).catch(e=>{var t=e.code,n=e.message;console.error(t,n)})}
|
||||
Reference in New Issue
Block a user