[getServerLinks] added utils, links in task view

This commit is contained in:
romankko2 committed 2024-06-28 17:05:24 +02:00
1 parent f3d3aa916e
commit c74f875571
5 files changed
+110 -2

No files matched your search

@@ -0,0 +1,57 @@
export function getServerLinks(description) {
const os = detectOS()
// Create a temporary DOM element to manipulate the HTML content
const tempDiv = document.createElement('div')
tempDiv.innerHTML = description
const links = new Set()
const paragraphs = tempDiv.querySelectorAll('p')
paragraphs.forEach(p => {
const text = p.textContent.trim()
if (os === 'mac' && text.startsWith('smb://')) {
links.add(`<a href="${text}" target="_blank" rel="noopener noreferrer">${text}</a>`)
} else if (os === 'win' && text.startsWith('\\\\')) {
links.add(`<a href="file://${text.replace(/\\/g, '/')}" target="_blank" rel="noopener noreferrer">${text}</a>`)
} else if (os === 'mac' && text.startsWith('\\\\')) {
const smbLink = 'smb:' + text.replace(/\\/g, '/')
links.add(`<a href="${smbLink}" target="_blank" rel="noopener noreferrer">${smbLink}</a>`)
} else if (os === 'win' && text.startsWith('smb://')) {
const windowsLink = text.replace(/^smb:/, '').replace(/\//g, '\\')
links.add(`<a href="file://${windowsLink}" target="_blank" rel="noopener noreferrer">${windowsLink}</a>`)
}
const anchor = p.querySelector('a')
if (anchor) {
const href = anchor.getAttribute('href')
if (os === 'mac' && href.startsWith('smb://')) {
links.add(`<a href="${href}" target="_blank" rel="noopener noreferrer">${href}</a>`)
} else if (os === 'win' && href.startsWith('\\\\')) {
links.add(`<a href="file://${href.replace(/\\/g, '/')}" target="_blank" rel="noopener noreferrer">${href}</a>`)
} else if (os === 'mac' && href.startsWith('\\\\')) {
const smbLink = 'smb:' + href.replace(/\\/g, '/')
links.add(`<a href="${smbLink}" target="_blank" rel="noopener noreferrer">${smbLink}</a>`)
} else if (os === 'win' && href.startsWith('smb://')) {
const windowsLink = href.replace(/^smb:/, '').replace(/\//g, '\\')
links.add(`<a href="file://${windowsLink}" target="_blank" rel="noopener noreferrer">${windowsLink}</a>`)
}
}
})
return Array.from(links).join('<br>')
}
export function detectOS() {
const platform = window.navigator.platform
const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']
if (macosPlatforms.indexOf(platform) !== -1) {
return 'mac'
} else if (windowsPlatforms.indexOf(platform) !== -1) {
return 'win'
}
return 'win'
}