2019-05-22 01:22:58 +00:00
|
|
|
// Search button function
|
2020-03-20 05:37:09 +00:00
|
|
|
document.getElementById('search-click').addEventListener('click', () => {
|
2019-06-07 09:09:51 +00:00
|
|
|
searchForm.submit()
|
|
|
|
}, false)
|
2019-06-01 09:21:51 +00:00
|
|
|
|
2020-03-20 05:37:09 +00:00
|
|
|
document.getElementById('search-click-mobile').addEventListener('click', () => {
|
2019-08-10 14:39:23 +00:00
|
|
|
searchFormMob.submit()
|
2019-06-01 09:21:51 +00:00
|
|
|
}, false)
|
2020-03-06 08:47:37 +00:00
|
|
|
|
2020-04-04 05:53:32 +00:00
|
|
|
// Hide mobile menu when click outside of the menu
|
|
|
|
document.addEventListener('click', (evt) => {
|
|
|
|
const mainNavDisplay = window.getComputedStyle(document.getElementsByClassName('main-nav')[0]).getPropertyValue('display')
|
|
|
|
const mobileNav = document.getElementById('mobile-nav-link')
|
|
|
|
const mobileToggle = document.getElementById('mobile-menu-toggle')
|
|
|
|
const isClickedOutside = !mobileNav.contains(evt.target)
|
|
|
|
|
2020-04-12 09:18:12 +00:00
|
|
|
// Exit if not in mobile view or menu button is clicked or menu is currently hidden
|
2020-04-04 05:53:32 +00:00
|
|
|
// Menu button click triggers `menu-button` and `mobile-menu-toggle`
|
2020-04-12 09:18:12 +00:00
|
|
|
if (mainNavDisplay !== 'none' ||
|
|
|
|
evt.target.id === 'menu-button' || evt.target.id === 'mobile-menu-toggle' ||
|
|
|
|
mobileToggle.checked === false) return
|
2020-04-04 05:53:32 +00:00
|
|
|
|
|
|
|
if (isClickedOutside) {
|
|
|
|
mobileToggle.checked = false
|
|
|
|
}
|
|
|
|
}, false)
|
|
|
|
|
2020-03-20 05:18:36 +00:00
|
|
|
// Web Share API
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
|
|
|
|
// Only available on supporting browsers and HTTPS
|
|
|
|
if (navigator.share && document.location.protocol === 'https:') {
|
2020-04-22 10:38:30 +00:00
|
|
|
const shareBtn = document.getElementById('share-button')
|
|
|
|
|
|
|
|
// Unhide share-button if supported
|
|
|
|
shareBtn.style.display = 'initial'
|
|
|
|
|
|
|
|
shareBtn.addEventListener('click', async () => {
|
2020-03-20 05:18:36 +00:00
|
|
|
const query = (selector) => {
|
|
|
|
return document.querySelector(selector)
|
|
|
|
}
|
2020-04-04 05:53:32 +00:00
|
|
|
|
2020-03-20 05:18:36 +00:00
|
|
|
const title = query('meta[property="og:title"]') ? query('meta[property="og:title"]').content : ''
|
|
|
|
const text = query('meta[property="og:description"]') ? query('meta[property="og:description"]').content : ''
|
|
|
|
const url = query('link[rel="canonical"]') ? query('link[rel="canonical"]').href : document.location.href
|
2020-04-04 05:53:32 +00:00
|
|
|
|
2020-03-20 05:18:36 +00:00
|
|
|
await navigator.share({ title, text, url })
|
|
|
|
}, false)
|
|
|
|
}
|
|
|
|
|
2020-03-06 08:47:37 +00:00
|
|
|
// Use duckduckgo's onion address when the site is accessed via .onion
|
|
|
|
if (document.location.hostname.endsWith('.onion')) {
|
|
|
|
const searchForms = document.querySelectorAll('form#searchForm, form#searchFormMob')
|
|
|
|
|
|
|
|
searchForms.forEach((form) => {
|
|
|
|
form.setAttribute('action', 'https://3g2upl4pq6kufc4m.onion/')
|
|
|
|
})
|
|
|
|
}
|
2021-02-23 07:48:56 +00:00
|
|
|
|
|
|
|
// Remove navigation link of current page
|
|
|
|
const navLink = document.querySelectorAll('a.main-nav-link, a.mobile-nav-link-a')
|
|
|
|
navLink.forEach((ele) => {
|
|
|
|
const eleHref = new URL(ele.href)
|
|
|
|
if (eleHref.pathname === document.location.pathname) {
|
|
|
|
const span = document.createElement('span')
|
|
|
|
span.className = ele.className
|
|
|
|
span.textContent = ele.textContent
|
|
|
|
ele.outerHTML = span.outerHTML
|
|
|
|
}
|
|
|
|
})
|