mirror of
https://github.com/pldubouilh/gossa.git
synced 2026-09-05 16:47:39 -04:00
+95
-106
@@ -6,6 +6,59 @@ function cancelDefault (e) {
|
|||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function warning (e) {
|
||||||
|
return 'Leaving will interrupt transfer\n?'
|
||||||
|
}
|
||||||
|
|
||||||
|
const barName = document.getElementById('dlBarName')
|
||||||
|
const barPc = document.getElementById('dlBarPc')
|
||||||
|
const barDiv = document.getElementById('progress')
|
||||||
|
const upGrid = document.getElementById('drop-grid')
|
||||||
|
const pics = document.getElementById('pics')
|
||||||
|
const picsHolder = document.getElementById('picsHolder')
|
||||||
|
const picsLabel = document.getElementById('picsLabel')
|
||||||
|
window.picsToggle = picsToggle
|
||||||
|
|
||||||
|
let allA
|
||||||
|
let imgsIndex
|
||||||
|
let allImgs
|
||||||
|
|
||||||
|
// Soft nav
|
||||||
|
function browseTo (href) {
|
||||||
|
window.fetch(href).then(r => r.text().then(t => {
|
||||||
|
const parsed = new window.DOMParser().parseFromString(t, 'text/html')
|
||||||
|
const table = parsed.querySelectorAll('table')[0].innerHTML
|
||||||
|
document.body.querySelectorAll('table')[0].innerHTML = table
|
||||||
|
|
||||||
|
const title = parsed.head.querySelectorAll('title')[0].innerText
|
||||||
|
// check if is current path - if so skip following
|
||||||
|
if (document.head.querySelectorAll('title')[0].innerText !== title) {
|
||||||
|
document.head.querySelectorAll('title')[0].innerText = title
|
||||||
|
document.body.querySelectorAll('h1')[0].innerText = '.' + title
|
||||||
|
window.history.pushState({}, '', window.encodeURI(title))
|
||||||
|
}
|
||||||
|
|
||||||
|
init()
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onClickLink = e => {
|
||||||
|
if (e.target.innerText.endsWith('/')) {
|
||||||
|
storeLastArrowSrc(e.target.href)
|
||||||
|
browseTo(e.target.href)
|
||||||
|
return false
|
||||||
|
} else if (picsOn(true, e.target.href)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
const refresh = () => browseTo(location.href)
|
||||||
|
const prevPage = () => browseTo(location.href + '../')
|
||||||
|
const getArrowSelected = () => document.querySelectorAll('i.arrow-selected')[0]
|
||||||
|
const getASelected = () => !getArrowSelected() ? false : getArrowSelected().parentElement.parentElement.querySelectorAll('a')[0]
|
||||||
|
window.onpopstate = prevPage
|
||||||
|
|
||||||
// RPC
|
// RPC
|
||||||
function rpcFs (call, args, cb) {
|
function rpcFs (call, args, cb) {
|
||||||
console.log('RPC', call, args)
|
console.log('RPC', call, args)
|
||||||
@@ -18,27 +71,17 @@ function rpcFs (call, args, cb) {
|
|||||||
|
|
||||||
const prependPath = (a) => a.startsWith('/') ? a : decodeURI(location.pathname) + a
|
const prependPath = (a) => a.startsWith('/') ? a : decodeURI(location.pathname) + a
|
||||||
|
|
||||||
// RPC Handlers
|
|
||||||
const mkdirCall = (path, cb) => rpcFs('mkdirp', [prependPath(path)], cb)
|
const mkdirCall = (path, cb) => rpcFs('mkdirp', [prependPath(path)], cb)
|
||||||
|
|
||||||
const mvCall = (path1, path2, cb) => rpcFs('mv', [path1, path2], cb)
|
const mvCall = (path1, path2, cb) => rpcFs('mv', [path1, path2], cb)
|
||||||
|
|
||||||
// Mkdir switch
|
// File upload
|
||||||
window.mkdirBtn = function () {
|
let totalDone = 0
|
||||||
const folder = window.prompt('New folder name', '')
|
let totalUploads = 0
|
||||||
|
let totalUploadsSize = 0
|
||||||
|
let totalUploadedSize = []
|
||||||
|
|
||||||
if (!folder) {
|
const checkDupes = test => allA.find(a => a.innerText.replace('/', '') === test)
|
||||||
return
|
|
||||||
} else if (checkDupes(folder)) {
|
|
||||||
return window.alert('Name already already exists')
|
|
||||||
}
|
|
||||||
|
|
||||||
mkdirCall(folder, refresh)
|
|
||||||
}
|
|
||||||
|
|
||||||
function warning (e) {
|
|
||||||
return 'Leaving will interrupt transfer\nAre you sure you want to leave?'
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldRefresh () {
|
function shouldRefresh () {
|
||||||
totalDone += 1
|
totalDone += 1
|
||||||
@@ -54,19 +97,6 @@ function shouldRefresh () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkDupes = test => allA.find(a => a.innerText.replace('/', '') === test)
|
|
||||||
|
|
||||||
const barName = document.getElementById('dlBarName')
|
|
||||||
|
|
||||||
const barPc = document.getElementById('dlBarPc')
|
|
||||||
|
|
||||||
const barDiv = document.getElementById('progress')
|
|
||||||
|
|
||||||
let totalDone = 0
|
|
||||||
let totalUploads = 0
|
|
||||||
let totalUploadsSize = 0
|
|
||||||
let totalUploadedSize = []
|
|
||||||
|
|
||||||
function updatePercent (ev) {
|
function updatePercent (ev) {
|
||||||
totalUploadedSize[ev.target.id] = ev.loaded
|
totalUploadedSize[ev.target.id] = ev.loaded
|
||||||
const ttlDone = totalUploadedSize.reduce((s, x) => s + x)
|
const ttlDone = totalUploadedSize.reduce((s, x) => s + x)
|
||||||
@@ -135,8 +165,6 @@ const setBackgroundLinks = t => { t.style.backgroundColor = 'rgba(123, 123, 123,
|
|||||||
|
|
||||||
const getLink = e => e.target.parentElement.querySelectorAll('a.list-links')[0]
|
const getLink = e => e.target.parentElement.querySelectorAll('a.list-links')[0]
|
||||||
|
|
||||||
const upGrid = document.getElementById('drop-grid')
|
|
||||||
|
|
||||||
document.ondragenter = (e) => {
|
document.ondragenter = (e) => {
|
||||||
if (isPicMode()) { return }
|
if (isPicMode()) { return }
|
||||||
cancelDefault(e)
|
cancelDefault(e)
|
||||||
@@ -186,13 +214,22 @@ document.ondrop = (e) => {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const getArrowSelected = () => document.querySelectorAll('i.arrow-selected')[0]
|
// Mkdir icon
|
||||||
|
window.mkdirBtn = function () {
|
||||||
|
const folder = window.prompt('New folder name', '')
|
||||||
|
|
||||||
function getASelected () {
|
if (!folder) {
|
||||||
const dest = getArrowSelected()
|
return
|
||||||
return !dest ? false : dest.parentElement.parentElement.querySelectorAll('a')[0]
|
} else if (checkDupes(folder)) {
|
||||||
|
return window.alert('Name already already exists')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mkdirCall(folder, refresh)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard Arrow
|
||||||
|
const storeLastArrowSrc = src => localStorage.setItem('last-selected' + location.href, src)
|
||||||
|
|
||||||
function scrollToArrow () {
|
function scrollToArrow () {
|
||||||
const pos = getArrowSelected().getBoundingClientRect()
|
const pos = getArrowSelected().getBoundingClientRect()
|
||||||
window.scrollTo(0, pos.y)
|
window.scrollTo(0, pos.y)
|
||||||
@@ -222,8 +259,6 @@ function restoreCursorPos () {
|
|||||||
scrollToArrow()
|
scrollToArrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
const storeLastArrowSrc = src => localStorage.setItem('last-selected' + location.href, src)
|
|
||||||
|
|
||||||
function moveArrow (down) {
|
function moveArrow (down) {
|
||||||
const all = Array.from(document.querySelectorAll('i.arrow-icon'))
|
const all = Array.from(document.querySelectorAll('i.arrow-icon'))
|
||||||
let i = all.findIndex(el => el.classList.contains('arrow-selected'))
|
let i = all.findIndex(el => el.classList.contains('arrow-selected'))
|
||||||
@@ -252,50 +287,11 @@ function moveArrow (down) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const refresh = () => browseTo(location.href)
|
// Pictures carousel
|
||||||
|
|
||||||
const prevPage = () => browseTo(location.href + '../')
|
|
||||||
|
|
||||||
window.onpopstate = prevPage
|
|
||||||
|
|
||||||
function browseTo (href) {
|
|
||||||
window.fetch(href).then(r => r.text().then(t => {
|
|
||||||
const parsed = new window.DOMParser().parseFromString(t, 'text/html')
|
|
||||||
const table = parsed.querySelectorAll('table')[0].innerHTML
|
|
||||||
document.body.querySelectorAll('table')[0].innerHTML = table
|
|
||||||
|
|
||||||
const title = parsed.head.querySelectorAll('title')[0].innerText
|
|
||||||
// check if is current path - if so skip following
|
|
||||||
if (document.head.querySelectorAll('title')[0].innerText !== title) {
|
|
||||||
document.head.querySelectorAll('title')[0].innerText = title
|
|
||||||
document.body.querySelectorAll('h1')[0].innerText = '.' + title
|
|
||||||
window.history.pushState({}, '', window.encodeURI(title))
|
|
||||||
}
|
|
||||||
|
|
||||||
init()
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
function cpPath () {
|
|
||||||
var t = document.createElement('textarea')
|
|
||||||
t.value = getASelected().href
|
|
||||||
document.body.appendChild(t)
|
|
||||||
t.select()
|
|
||||||
document.execCommand('copy')
|
|
||||||
document.body.removeChild(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
const pics = document.getElementById('pics')
|
|
||||||
const picsHolder = document.getElementById('picsHolder')
|
|
||||||
const picsLabel = document.getElementById('picsLabel')
|
|
||||||
|
|
||||||
const picTypes = ['.jpg', '.jpeg', '.png', '.gif']
|
const picTypes = ['.jpg', '.jpeg', '.png', '.gif']
|
||||||
const isPic = src => src && picTypes.find(type => src.toLocaleLowerCase().includes(type))
|
const isPic = src => src && picTypes.find(type => src.toLocaleLowerCase().includes(type))
|
||||||
|
|
||||||
const isPicMode = () => pics.style.display === 'flex'
|
const isPicMode = () => pics.style.display === 'flex'
|
||||||
|
window.picsNav = () => picsNav(true)
|
||||||
let imgsIndex
|
|
||||||
let allImgs
|
|
||||||
|
|
||||||
function setImage (src) {
|
function setImage (src) {
|
||||||
src = src || allImgs[imgsIndex]
|
src = src || allImgs[imgsIndex]
|
||||||
@@ -346,19 +342,8 @@ function picsNav (down) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
let allA
|
// Paste handler
|
||||||
let typedPath = ''
|
|
||||||
let typedToken = null
|
|
||||||
|
|
||||||
function setCursorToClosestTyped () {
|
|
||||||
const a = allA.find(el => el.innerText.toLocaleLowerCase().startsWith(typedPath))
|
|
||||||
if (!a) { return }
|
|
||||||
storeLastArrowSrc(a.href)
|
|
||||||
restoreCursorPos()
|
|
||||||
}
|
|
||||||
|
|
||||||
let cuts = []
|
let cuts = []
|
||||||
|
|
||||||
function onPaste () {
|
function onPaste () {
|
||||||
if (!cuts.length) { return refresh() }
|
if (!cuts.length) { return refresh() }
|
||||||
const root = cuts.pop()
|
const root = cuts.pop()
|
||||||
@@ -370,6 +355,25 @@ function onPaste () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Kb handler
|
// Kb handler
|
||||||
|
let typedPath = ''
|
||||||
|
let typedToken = null
|
||||||
|
|
||||||
|
function cpPath () {
|
||||||
|
var t = document.createElement('textarea')
|
||||||
|
t.value = getASelected().href
|
||||||
|
document.body.appendChild(t)
|
||||||
|
t.select()
|
||||||
|
document.execCommand('copy')
|
||||||
|
document.body.removeChild(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCursorToClosestTyped () {
|
||||||
|
const a = allA.find(el => el.innerText.toLocaleLowerCase().startsWith(typedPath))
|
||||||
|
if (!a) { return }
|
||||||
|
storeLastArrowSrc(a.href)
|
||||||
|
restoreCursorPos()
|
||||||
|
}
|
||||||
|
|
||||||
document.body.addEventListener('keydown', e => {
|
document.body.addEventListener('keydown', e => {
|
||||||
switch (e.code) {
|
switch (e.code) {
|
||||||
case 'Tab':
|
case 'Tab':
|
||||||
@@ -420,7 +424,7 @@ document.body.addEventListener('keydown', e => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any other key, for text search
|
// text search
|
||||||
if (e.code.includes('Key')) {
|
if (e.code.includes('Key')) {
|
||||||
typedPath += e.code.replace('Key', '').toLocaleLowerCase()
|
typedPath += e.code.replace('Key', '').toLocaleLowerCase()
|
||||||
window.clearTimeout(typedToken)
|
window.clearTimeout(typedToken)
|
||||||
@@ -429,17 +433,6 @@ document.body.addEventListener('keydown', e => {
|
|||||||
}
|
}
|
||||||
}, false)
|
}, false)
|
||||||
|
|
||||||
window.onClickLink = e => {
|
|
||||||
if (e.target.innerText.endsWith('/')) {
|
|
||||||
storeLastArrowSrc(e.target.href)
|
|
||||||
browseTo(e.target.href)
|
|
||||||
return false
|
|
||||||
} else if (picsOn(true, e.target.href)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
function init () {
|
function init () {
|
||||||
allA = Array.from(document.querySelectorAll('a.list-links'))
|
allA = Array.from(document.querySelectorAll('a.list-links'))
|
||||||
allImgs = allA.map(el => el.href).filter(isPic)
|
allImgs = allA.map(el => el.href).filter(isPic)
|
||||||
@@ -449,8 +442,4 @@ function init () {
|
|||||||
restoreCursorPos()
|
restoreCursorPos()
|
||||||
console.log('Browsed to ' + location.href)
|
console.log('Browsed to ' + location.href)
|
||||||
}
|
}
|
||||||
|
|
||||||
init()
|
init()
|
||||||
|
|
||||||
window.picsToggle = picsToggle
|
|
||||||
window.picsNav = () => picsNav(true)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user