<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>单页迭代生成器</title>
<style>
#container {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
#container > * {
margin: 5px;
}
.hw, .page-source {
background-color: #f4f4f4;
padding: 1em;
border: 1px dashed #DDD;
background-color: rgb(237,237,233);
font-family: 'Andale Mono', 'Courier New', Courier, monospace;
padding: 0 1em;
margin: 0.4em 0;
overflow: auto;
}
</style>
</head>
<body>
<div id="container">
<div>
wikidot.com/<input type="text" size="5" id="url" /><br>
数量:<input type="text" id="input" size="3" min="1" />
</div>
<button onclick="generateCode()">生成</button>
</div>
<pre class="hw" style="white-space: pre-wrap;"></pre>
<script>
let hw = '';
function generateCode() {
var url = document.getElementById("url").value;
const input = document.getElementById('input').value;
hw = '';
for (let i = 1; i <= input; i++) {
hw += `[[module ListPages ${i === 1 ? 'offset="@URL|0"' : `limit="@URL|0" urlAttrPrefix="page${i}"`} range="."]]\n%%content{${i + 1}}%%\n[[/module]]\n`;
}
hw += '[!--\n====\n';
for (let i = 1; i <= input; i++) {
if (i == input) {
hw += `内容${i}\n [/${url} 第1迭代]\n====\n`;
} else {
hw += `内容${i}\n [/${url}/offset/1/page${i + 1}_limit/1 第${i + 1}迭代]\n====\n`;
}
}
hw += '--]';
document.querySelector('.hw').innerText = hw;
if (document.getElementById('copyButton') === null) {
const copyButton = document.createElement('button');
copyButton.id = 'copyButton';
copyButton.textContent = '点击复制';
copyButton.onclick = copyHW;
document.body.insertBefore(copyButton, document.querySelector('.hw'));
}
}
function copyHW() {
if(execCopy(hw)){
}else {
alert('复制失败!');
}
}
function execCopy(string){
var temp = document.createElement('div');
temp.appendChild(document.createElement('pre')).textContent = string;
var s = temp.style;
s.position = 'fixed';
s.left = '-100%';
document.body.appendChild(temp);
document.getSelection().selectAllChildren(temp);
var result = document.execCommand('copy');
document.body.removeChild(temp);
return result;
}
</script>
</body>
</html>