用户:RedDragon/Test1:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第2行: | 第2行: | ||
<html> | <html> | ||
<div id="user- | <div id="user-profile"> | ||
<p></p> | <p></p> | ||
</div> | </div> | ||
<script> | <script> | ||
document.addEventListener('DOMContentLoaded', function() { | document.addEventListener('DOMContentLoaded', function () { | ||
var profilePageUrl = '/index.php/User_profile:RedDragon' | |||
var container = document.getElementById('user-profile') | |||
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 contentArea = doc.getElementById('mw-content-text') | |||
if (!contentArea) { | |||
container.style.display = 'none' | |||
return | |||
} | |||
var contentClone = contentArea.cloneNode(true) | |||
container.innerHTML = '' | |||
container.appendChild(contentClone) | |||
var baseUrl = window.location.protocol + '//' + window.location.host | |||
var links = container.querySelectorAll('a[href^="/"]') | |||
for (var i = 0; i < links.length; i++) { | |||
var link = links[i] | |||
if (link.getAttribute('href').startsWith('/')) { | |||
link.href = baseUrl + link.getAttribute('href') | |||
} | |||
} | } | ||
var images = container.querySelectorAll('img[src^="/"]') | |||
for (var j = 0; j < images.length; j++) { | |||
var img = images[j] | |||
if (img.getAttribute('src').startsWith('/')) { | |||
img.src = baseUrl + img.getAttribute('src') | |||
} | |||
} | } | ||
}) | }) | ||
.catch(function (error) { | |||
console.error('获取时出错:', error) | |||
container.style.display = 'none' | |||
}) | |||
}) | |||
}) | |||
</script> | </script> | ||
</html> | </html> | ||