document.addEventListener('DOMContentLoaded', function () {
loading()
var hold, external, timeout, ac, last, darklight = document.getElementById('darkcss').getAttribute('href')
document.getElementById('instance').addEventListener('keydown', function (event) {
if (event.key && !event.ctrlKey && !event.altKey && !event.shiftKey) {
if ((event.key.length === 1 && /[a-z0-9.\-*:]/i.test(event.key)) || (event.key === 'Backspace' && event.target.value !== '')) {
last = event.target.value
} else {
event.preventDefault()
event.stopPropagation()
}
} else {
event.preventDefault()
event.stopPropagation()
}
})
document.getElementById('instance').addEventListener('keyup', function (event) {
if (event.key && !event.ctrlKey && !event.altKey && !event.shiftKey) {
if ((event.key.length === 1 && /[a-z0-9.\-*:]/i.test(event.key)) || (event.key === 'Backspace' && event.target.value !== '')) {
keypress(event.target.value)
} else {
event.preventDefault()
event.stopPropagation()
}
} else {
event.preventDefault()
event.stopPropagation()
}
})
var modal = document.getElementById('modal'),
closemodal = document.getElementById('closemodal'),
modalcontent = document.querySelector('.modal-content')
document.getElementById('reverse').addEventListener('click', function (event) {
var content = document.getElementById('instance').value
if (content && content.length > 0) {
loading()
fetch('/api/block_count/' + content).then(async function (result) {
var res = await result.json()
if (res && res.block_count >= 0) {
document.getElementById('blockcount').innerText = res.block_count
document.getElementById('blockinstance').innerText = 'ing ' + content
document.getElementById('blocktook').innerText = res.took
var list = document.getElementById('blocklist'),
download = document.getElementById('download')
download.removeAttribute('href')
download.removeAttribute('download')
download.style.display = 'none'
while (list.hasChildNodes()) {
list.removeChild(list.firstChild)
}
res.instances.map(function (instance, index) {
var li = document.createElement('li'),
text = document.createTextNode((index + 1) + '. '),
link = '' + instance.instance + '',
text2 = document.createTextNode(instance.comment ? ' - ' + instance.comment : '')
li.appendChild(text)
li.insertAdjacentHTML('beforeend', link)
li.appendChild(text2)
blocklist.appendChild(li)
})
listinstance(content, new AbortController())
modalcontent.style.animationName = 'animatetop'
modal.style.display = 'block'
var locationsearch = !new URLSearchParams(window.location.search).has('reverse') ? window.location.search ? window.location.search + '&reverse' : '?reverse' : window.location.search
history.pushState({}, null, '/' + locationsearch + '#' + content)
if (new URLSearchParams(window.location.search).has('matrix')) {
var walker = document.createTreeWalker(list, NodeFilter.SHOW_TEXT)
while (walker.nextNode()) {
if (walker.currentNode.textContent.length > 1) {
new Messenger(walker.currentNode)
}
}
}
document.getElementById('loader-content').style.display = 'none'
}
})
}
})
document.body.addEventListener('click', function (event) {
if (event.target == modal) {
modalcontent.style.animationName = 'animatebottom'
}
})
closemodal.addEventListener('click', function (event) {
modalcontent.style.animationName = 'animatebottom'
})
modalcontent.addEventListener('animationend', function (event) {
if (event.animationName === 'animatebottom') {
modal.style.display = 'none'
}
})
document.getElementById('title').addEventListener('click', function (event) {
document.getElementById('instance').value = ''
if (new URLSearchParams(window.location.search).has('matrix')) {
window.location.href = '/?matrix'
} else {
window.location.href = '/'
}
event.preventDefault()
event.stopPropagation()
})
document.getElementById('capture').addEventListener('click', function (event) {
html2canvas(document.querySelector('.modal-body')).then(function (canvas) {
var a = document.createElement('a')
a.download = 'fediblock-' + Date.now() + '.png'
a.href = canvas.toDataURL({ type: 'image/png' })
a.type = 'image/png'
a.target = '_blank'
a.dispatchEvent(new MouseEvent('click'))
})
})
document.getElementById('download_index').addEventListener('click', function (event) {
loading()
ac = new AbortController()
fetch('/api/download_index', { signal: ac.signal }).then(async function (result) {
var res = await result.blob(),
a = document.createElement('a')
a.download = 'fediblock-index.json.gz'
a.href = URL.createObjectURL(res)
a.type = 'application/gzip'
a.target = '_blank'
a.dispatchEvent(new MouseEvent('click'))
document.getElementById('loader-content').style.display = 'none'
}).catch(function (err) {
console.error(err)
document.getElementById('loader-content').style.display = 'none'
})
event.preventDefault()
event.stopPropagation()
})
document.getElementById('darklight').addEventListener('click', function (event) {
if (event.target.innerText === '☼') {
document.getElementById('darkcss').setAttribute('href', '')
event.target.innerText = '☽'
} else {
document.getElementById('darkcss').setAttribute('href', darklight)
event.target.innerText = '☼'
}
})
function keypress(content) {
loading()
if (timeout) {
clearTimeout(timeout)
}
if (ac && ac.signal) {
ac.abort()
}
ac = new AbortController()
if (content.length === 0) {
hold = true
ranking()
} else if (content.length > 0 && !hold) {
hold = true
listinstance(content, ac)
} else if (content.length > 0 && hold) {
timeout = setTimeout(function () {
listinstance(content, ac)
}, 300)
}
}
function listinstance(content, ac) {
loading()
var list = document.getElementById('instancelist')
fetch('/api/list/' + content, { signal: ac.signal }).then(async function (result) {
var res = await result.json()
if (res && Array.isArray(res.instances) && Array.isArray(res.suggests)) {
while (list.hasChildNodes()) {
list.removeChild(list.firstChild)
}
res.instances.map(function (r) {
var li = document.createElement('li')
li.innerHTML = r.domain + (r.blocks ? ' - ' + r.blocks + ' blocks' : '')
+ (r.nodeinfo ? ' ⓘ' : '')
+ (r.api.title ? '
' + r.api.title + ' - ' + r.api.uri + '
'
+ (r.last ? 'Last update: ' + (new Date(r.last)).toLocaleString() + '
' : '')
+ (r.api.email ? 'Email: ' + r.api.email + '
' : '')
+ 'Registration: ' + (r.api.registrations ? 'open' : 'closed') + ' - Version: ' + r.api.version + '
'
+ (r.api.stats ? 'Users: ' + r.api.stats.user_count + ' - Statuses: ' + r.api.stats.status_count + ' - Domains: ' + r.api.stats.domain_count + '
' : '')
+ (r.api.description ? 'Description: ' + r.api.description + '
' : '')
+ (r.api.thumbnail ? '
' : '') : '')
li.setAttribute('data-domain', r.domain)
li.addEventListener('click', function (event) {
if (event.target.matches('a')) {
return true
}
loading()
var blocklist = document.getElementById('blocklist'),
download = document.getElementById('download'),
domain = event.target.getAttribute('data-domain')
while (blocklist.hasChildNodes()) {
blocklist.removeChild(blocklist.firstChild)
}
fetch('/api/detail/' + domain).then(async function (result) {
var res = await result.json()
if (res.blocks && Array.isArray(res.blocks) && res.blocks.length > 0) {
var csv = '#domain,#severity,#reject_media,#reject_reports,#public_comment,#obfuscate\n'
res.blocks.map(function (r, i) {
var liblock = document.createElement('li'),
text = document.createTextNode((i + 1) + '. '),
link = '' + r.domain + '',
textSeverity = document.createTextNode(r.severity ? ' - ' + r.severity : ''),
textComment = document.createTextNode(r.comment ? ' - ' + r.comment : '')
liblock.appendChild(text)
liblock.insertAdjacentHTML('beforeend', link)
liblock.appendChild(textSeverity)
liblock.appendChild(textComment)
blocklist.appendChild(liblock)
csv += !r.domain.match(/\*/) ? r.domain + ',' + (r.severity ? r.severity : '') + ',False,False,' + (r.comment ? '"' + r.comment + '"' : '') + ',False\n' : ''
})
modalcontent.style.animationName = 'animatetop'
modal.style.display = 'block'
document.getElementById('blockcount').innerText = res.blocks.length
document.getElementById('blockinstance').innerHTML = 'ed by ' + (res.api ? ''
+ res.instance + '' : res.instance) + (res.nodeinfo ? ' ⓘ' : '')
+ '
Last update: ' + (new Date(res.last)).toLocaleString()
document.getElementById('blocktook').innerText = res.took
if (csv.split('\n').length > 2) {
download.href = window.URL.createObjectURL(new Blob([csv], { type: 'text/csv' }))
download.download = 'fediblock-' + res.instance + '.csv'
download.style.display = 'inherit'
} else {
download.removeAttribute('href')
download.removeAttribute('download')
download.style.display = 'none'
}
if (new URLSearchParams(window.location.search).has('matrix')) {
var walker = document.createTreeWalker(blocklist, NodeFilter.SHOW_TEXT)
while (walker.nextNode()) {
if (walker.currentNode.textContent.length > 1) {
new Messenger(walker.currentNode)
}
}
}
} else {
var a = document.createElement('a')
a.href = '/api/detail_api/' + domain
a.title = 'API info for ' + domain
a.target = '_blank'
a.dispatchEvent(new MouseEvent('click'))
}
document.getElementById('loader-content').style.display = 'none'
})
window.location.hash = domain
document.getElementById('loader-content').style.display = 'none'
})
list.appendChild(li)
})
var placeholder = document.getElementById('placeholder')
if (res.suggests.length > 0) {
placeholder.innerHTML = res.suggests.map(function (instance) {
return '' + instance + ''
}).join(', ')
} else {
placeholder.innerText = ''
}
if (external) {
document.getElementById('instancelist').childNodes.forEach(function (node) {
if (node.textContent.split(' ')[0].trim() === content) {
node.dispatchEvent(new MouseEvent('click'))
}
})
external = false
}
if (new URLSearchParams(window.location.search).has('matrix')) {
var walker = document.createTreeWalker(list, NodeFilter.SHOW_TEXT)
while (walker.nextNode()) {
if (walker.currentNode.textContent.length > 1) {
new Messenger(walker.currentNode)
}
}
}
}
document.getElementById('loader-content').style.display = 'none'
hold = false
}).catch(function (err) {
// console.error(err)
document.getElementById('loader-content').style.display = 'none'
hold = false
})
}
function ranking() {
loading()
var list = document.getElementById('instancelist'),
placeholder = document.getElementById('placeholder')
fetch('/api/ranking').then(async function (result) {
var res = await result.json()
if (Array.isArray(res) && res.length > 0) {
while (list.hasChildNodes()) {
list.removeChild(list.firstChild)
}
var li = document.createElement('li'),
strong = document.createElement('strong'),
text = document.createTextNode('Top 100')
strong.appendChild(text)
li.appendChild(strong)
list.appendChild(li)
res.map(function (r, i) {
var li = document.createElement('li'),
text = document.createTextNode(`${i + 1} - ${r.domain} - ${r.count} blocks`)
li.addEventListener('click', function (event) {
var instance = document.getElementById('instance'),
text = event.target.innerText.split(' - ')[1].trim()
instance.value = text
document.getElementById('reverse').click()
})
li.appendChild(text)
list.appendChild(li)
})
}
if (new URLSearchParams(window.location.search).has('matrix')) {
var walker = document.createTreeWalker(list, NodeFilter.SHOW_TEXT)
while (walker.nextNode()) {
if (walker.currentNode.textContent.length > 1) {
new Messenger(walker.currentNode)
}
}
}
placeholder.innerText = ''
hold = false
document.getElementById('loader-content').style.display = 'none'
}).catch(function (err) {
console.error(err)
hold = false
document.getElementById('loader-content').style.display = 'none'
})
}
function suggest(urlitem) {
var instance = document.getElementById('instance')
window.location.hash = urlitem
instance.value = urlitem
listinstance(urlitem, new AbortController())
}
function loading() {
var loader = document.getElementById('load'),
loaders = ['loader-pong', 'loader-pacman', 'loader-abyss', 'loader-jump', 'loader-loading', 'loader-avenger', 'loader-mario']
if (loader.classList.value) {
loader.classList.remove(loader.classList.value)
}
loader.classList.add(loaders[Math.floor(Math.random() * loaders.length)])
document.getElementById('loader-content').style.display = 'initial'
}
window.suggest = suggest
fetch('/api/count').then(async function (result) {
var res = await result.json()
if (res && res.count) {
fetch('/api/stats').then(async function (statsresult) {
var statsres = await statsresult.json()
if (statsres) {
document.getElementById('count').innerHTML = res.count + '