用户:RedDragon/Test1:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第1行: | 第1行: | ||
<randomuserswithavatars/> | <randomuserswithavatars/> | ||
{ | <html> | ||
{{ | <div id="user-page"> | ||
<p></p> | |||
</div> | |||
<script> | |||
document.addEventListener('DOMContentLoaded', function () { | |||
var profilePageUrl = '/wiki/User_profile:RedDragon' | |||
var container = document.getElementById('user-page') | |||
fetch(profilePageUrl) | |||
.then(function (response) { | |||
if (!response.ok) { | |||
throw new Error('网络响应异常 状态码:' + response.status) | |||
} | |||
return response.text() | |||
}) | |||
.then(function (htmlString) { | |||
var parser = new DOMParser() | |||
var doc = parser.parseFromString(htmlString, 'text/html') | |||
var leftContent = doc.getElementById('user-page-left') | |||
var rightContent = doc.getElementById('user-page-right') | |||
if (!leftContent || !rightContent) { | |||
container.style.display = 'none' | |||
return | |||
} | |||
container.innerHTML = '' | |||
container.appendChild(leftContent.cloneNode(true)) | |||
container.appendChild(rightContent.cloneNode(true)) | |||
var baseUrl = window.location.protocol + '//' + window.location.host | |||
var links = container.querySelectorAll('a[href^="/"]') | |||
links.forEach(function (link) { | |||
if (link.getAttribute('href').startsWith('/')) { | |||
link.href = baseUrl + link.getAttribute('href') | |||
} | |||
}) | |||
var images = container.querySelectorAll('img[src^="/"]') | |||
images.forEach(function (img) { | |||
if (img.getAttribute('src').startsWith('/')) { | |||
img.src = baseUrl + img.getAttribute('src') | |||
} | |||
}) | |||
}) | |||
.catch(function (error) { | |||
console.error('获取时出错:', error) | |||
container.style.display = 'none' | |||
}) | |||
}) | |||
</script> | |||
</html> | |||