Implemented Unflow for plaintext content

This commit is contained in:
Luxferre
2023-04-01 15:08:55 +03:00
parent 5ce5069a70
commit 28359eb889
4 changed files with 34 additions and 4 deletions
+9 -1
View File
@@ -99,6 +99,8 @@ addEventListener('DOMContentLoaded', function() {
return bmArray[index]
}
var activeContent={'prop': 'textContent', 'nowrap': '', 'wrap': ''} // placeholder to hold the wrapped and non-wrapped content
function loadURL(url, noNavUpdate) { // wrapper to openURL that actually updates all the UI and history
logoStatus.textContent = logoLoadingChar
statusBar.textContent = 'Loading ' + url
@@ -108,14 +110,18 @@ addEventListener('DOMContentLoaded', function() {
var updateHistory = !('updateAddr' in res && res.updateAddr === false), // true by default
updateContent = !(res.content === null) // true by default
if(updateContent) { // update the content zone
activeContent.nowrap = res.content
activeContent.wrap = res.contentWf || res.content
contentZone.innerHTML = ''
contentZone.textContent = ''
contentZone.dataset.wrap = 0 // reset line wrapping
if(res.contentType === 'text/plain') {
activeContent.prop = 'textContent'
contentZone.dataset.format='plain'
contentZone.textContent = res.content
contentZone.textContent = activeContent.nowrap
} else {
contentZone.dataset.format='native'
activeContent.prop='innerHTML'
contentZone.innerHTML = res.content
var contentLinks = contentZone.querySelectorAll('a'), l = contentLinks.length, i
for(i=0;i<l;i++) { // dynamically index all the links in the rendered content
@@ -203,6 +209,8 @@ addEventListener('DOMContentLoaded', function() {
break
case '6': // toggle line wrapping
contentZone.dataset.wrap = 1 - parseInt(contentZone.dataset.wrap)
if(activeContent.wrap != activeContent.nowrap) // only update contentZone if they differ
contentZone[activeContent.prop] = activeContent[parseInt(contentZone.dataset.wrap) ? 'wrap' : 'nowrap']
break
case 'Call': // refresh
loadURL(currentUrl, true)