// 更新內容
function updContent(text) {
const theText = $$('#theText')
theText.innerHTML = autohref(escapeHtml(text !== '' ? text : introTxt))
}/**
* 自動產生連結。
*
* @param {string} text 要處理的字串。
* @return {string} 處理好的字串。
*/
function autohref(text) {
httpPattern = /(http|https):\/\/.+/
toOutput = ''
for (t of text.split(' ')) {
if (t.match(httpPattern)) {
toOutput += `<a href='${t}'>${t}</a>` + ' '
} else {
toOutput += t + ' '
}
}
return toOutput
}http://www.example.com 拉拉拉<a href='http://www.example.com'>http://www.example.com</a> 拉拉拉// 更新內容
function updContent(text) {
const theText = $$('#theText')
theText.innerHTML = autohref(escapeHtml(text !== '' ? text : introTxt))
}