用户:RedDragon/Test1:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第7行: | 第7行: | ||
<script> | <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 stylesheets = doc.querySelectorAll('link[rel="stylesheet"]') | |||
var head = document.getElementsByTagName('head')[0] | |||
stylesheets.forEach(function(sheet) { | |||
var href = sheet.href | |||
var existing = document.querySelector('link[href="' + href + '"]') | |||
if (!existing && href) { | |||
var newSheet = sheet.cloneNode(true) | |||
if (newSheet.href.startsWith('/')) { | |||
newSheet.href = window.location.protocol + '//' + window.location.host + newSheet.href | |||
} | |||
head.appendChild(newSheet) | |||
} | } | ||
}) | }) | ||
var contentArea = doc.getElementById('mw-content-text') | |||
var leftContent = doc.getElementById('user-page-left') | |||
var rightContent = doc.getElementById('user-page-right') | |||
if (!contentArea || !leftContent || !rightContent) { | |||
container.style.display = 'none' | |||
return | |||
} | |||
container.innerHTML = '' | |||
var contentClone = contentArea.cloneNode(true) | |||
var printfooter = contentClone.querySelector('.printfooter') | |||
if (printfooter) printfooter.remove() | |||
container.appendChild(contentClone) | |||
var baseUrl = window.location.protocol + '//' + window.location.host | |||
var links = container.querySelectorAll('a[href^="/"]') | |||
if ( | 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> | </script> | ||
</html> | </html> | ||