用户:RedDragon/Test1:修订间差异
来自Rizline中文维基
更多操作
小 |
小 |
||
| 第2行: | 第2行: | ||
<html> | <html> | ||
<div id="user- | <div id="user-page"> | ||
<p></p> | <p></p> | ||
</div> | </div> | ||
| 第8行: | 第8行: | ||
<script> | <script> | ||
document.addEventListener('DOMContentLoaded', function () { | document.addEventListener('DOMContentLoaded', function () { | ||
var profilePageUrl = '/ | var profilePageUrl = '/wiki/User_profile:RedDragon' | ||
var container = document.getElementById('user- | var container = document.getElementById('user-page') | ||
fetch(profilePageUrl) | fetch(profilePageUrl) | ||
| 第22行: | 第22行: | ||
var doc = parser.parseFromString(htmlString, 'text/html') | var doc = parser.parseFromString(htmlString, 'text/html') | ||
var | var leftContent = doc.getElementById('user-page-left') | ||
var rightContent = doc.getElementById('user-page-right') | |||
if (! | if (!leftContent || !rightContent) { | ||
container.style.display = 'none' | container.style.display = 'none' | ||
return | return | ||
} | } | ||
container.innerHTML = '' | container.innerHTML = '' | ||
container.appendChild( | |||
var wrapper = document.createElement('div') | |||
wrapper.className = 'clearfix' | |||
wrapper.style.cssText = 'display: inline-block; width: 100%;' | |||
var leftClone = leftContent.cloneNode(true) | |||
leftClone.style.cssText = 'width: 35%; float: left;' | |||
wrapper.appendChild(leftClone) | |||
var rightClone = rightContent.cloneNode(true) | |||
rightClone.style.cssText = 'float: right; width: 60%;' | |||
wrapper.appendChild(rightClone) | |||
container.appendChild(wrapper) | |||
var baseUrl = window.location.protocol + '//' + window.location.host | var baseUrl = window.location.protocol + '//' + window.location.host | ||
var links = container.querySelectorAll('a[href^="/"]') | var links = container.querySelectorAll('a[href^="/"]') | ||
links.forEach(function (link) { | |||
if (link.getAttribute('href').startsWith('/')) { | if (link.getAttribute('href').startsWith('/')) { | ||
link.href = baseUrl + link.getAttribute('href') | link.href = baseUrl + link.getAttribute('href') | ||
} | } | ||
} | }) | ||
var images = container.querySelectorAll('img[src^="/"]') | var images = container.querySelectorAll('img[src^="/"]') | ||
images.forEach(function (img) { | |||
if (img.getAttribute('src').startsWith('/')) { | if (img.getAttribute('src').startsWith('/')) { | ||
img.src = baseUrl + img.getAttribute('src') | img.src = baseUrl + img.getAttribute('src') | ||
} | } | ||
} | }) | ||
}) | }) | ||
.catch(function (error) { | .catch(function (error) { | ||