微件:RandomPlant:修订间差异
来自植物大战僵尸杂交版Wiki
更多操作
创建页面,内容为“<includeonly> <style> .random-plant-box { text-align: center; padding: 20px; background: #f5f5f5; border-radius: 12px; border: 1px solid #e0e0e0; margin: 15px 0; } .random-plant-btn { padding: 10px 30px; font-size: 16px; background: #4CAF50; color: #fff; border: none; border-radius: 8px; cursor: pointer; margin-bottom: 15px; } .random-plant-btn:hover { background: #45a049; } .random-plant-result { disp…” |
无编辑摘要 |
||
| 第50行: | 第50行: | ||
<script> | <script> | ||
(function() { | (function() { | ||
function pickRandom() { | |||
var names = []; | |||
$('.pvzhe-card-name').each(function() { | |||
function | var name = $(this).text().trim(); | ||
var | if (name) names.push(name); | ||
}); | |||
} | |||
if (names.length === 0) { | |||
if ( | $('#random-plant-result').html('<span style="color:#888;">当前页面无植物卡片</span>'); | ||
return; | return; | ||
} | } | ||
names = names.sort(function() { return Math.random() - 0.5; }); | |||
var picked = | var picked = names.slice(0, 5); | ||
var html = ''; | var html = ''; | ||
picked.forEach(function(name) { | picked.forEach(function(name) { | ||
html += '<a href="/w/' + encodeURIComponent(name) + '">' + name + '</a>'; | html += '<a href="/w/' + encodeURIComponent(name) + '">' + name + '</a>'; | ||
}); | }); | ||
$('#random-plant-result').html(html); | |||
} | } | ||
$(document).on('click', '#random-plant-btn', pickRandom); | |||
})(); | })(); | ||
</script> | </script> | ||
</includeonly> | </includeonly> | ||