单页迭代生成器
这是一个可以通过输入页面URL及数量而快速生成单页迭代模板的工具。
现在被加了个点击复制按钮,并且不用再输入Wiki站点地址。
使用方式
1. 输入页面URL地址,即.wikidot.com后的内容。以Level C-2为例即为level-c-2。
2. 输入数量,即页面所需要的迭代数量。通常情况下为避免浏览器卡顿,不建议输入超过个位数的数量值,同时也不宜输入低于1的数量值。
3. 点击“生成”按钮即可生成单页迭代模板。
4. 点击“复制”按钮即可复制代码
注意!单页迭代中无法使用[[module listpages]]与[!-- 注释 --]。
关于单页迭代的详细使用方式可于单页迭代使用指导查看。
若你无法看到转换器,请前往沙盒站点访问备用链接。
<!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}%%\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>