<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>猫名</title>
<!-- 使用BootCDN加载Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css">
<style>
body {
font-family: '宋体', sans-serif;
background: linear-gradient(135deg, #ececec, #f5f5f5);
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
padding: 20px;
}
.navbar {
background-color: #fff;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border-radius: 12px;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 12px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
margin-top: 20px;
}
h1 {
color: #004085;
font-weight: bold;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}
.btn-primary {
background-color: #007bff;
border: none;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border-radius: 12px;
}
.btn-primary:hover {
background-color: #0056b3;
}
.custom-switch {
margin-bottom: 10px;
}
.custom-switch .custom-control-label {
color: #004085;
}
</style>
</head>
<body>
<header class="mb-5">
<nav class="navbar navbar-expand-lg navbar-light">
<a class="navbar-brand" href="./">猫名</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="../zh-cn/">返回首页</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
语言
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="../zh-cn/">中文(中国大陆)</a>
<a class="dropdown-item" href="../zh-tw/">中文(台灣)</a>
<a class="dropdown-item" href="../en/">English</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="https://gitlab.com/Qinshihuang233/warriors-name">项目地址</a>
</li>
<li class="nav-item">
<a class="nav-link" href="./about-cn/">关于</a>
</li>
</ul>
</div>
</nav>
</header>
<main role="main" class="container">
<h1 class="mb-4 text-center" id="displayName"></h1>
<div class="text-center">
<button class="btn btn-primary" type="button" onclick="generateName()">下一个</button>
</div>
<hr class="my-4" />
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="includeUnderage" onclick="changeIncludeUnderage()">
<label class="custom-control-label" for="includeUnderage">允许幼崽和学徒名</label>
</div>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="ignoreWeighting" onclick="changeIgnoreWeighting()">
<label class="custom-control-label" for="ignoreWeighting">忽略词缀比重</label>
</div>
</main>
<!-- 使用BootCDN加载jQuery和Bootstrap JS -->
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.4.1/js/bootstrap.min.js"></script>
<!-- 异步加载zh-cn.js -->
<script async src="./data/zh-cn.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
// 确保zh-cn.js加载完成后再执行
function init() {
const basePrefixes = data.prefixes;
const baseSuffixes = data.suffixes;
const totalApprentices = data.apprentices;
const totalKits = data.kits;
const unweightedPrefixes = [...new Set(basePrefixes)];
const unweightedSuffixes = [...new Set(baseSuffixes)];
let prefixes = basePrefixes;
let suffixes = baseSuffixes;
let includeUnderageCheckbox = document.getElementById("includeUnderage");
let ignoreWeightingCheckbox = document.getElementById("ignoreWeighting");
function changeIncludeUnderage() {
ignoreWeightingCheckbox.disabled = !includeUnderageCheckbox.checked;
}
function changeIgnoreWeighting() {
includeUnderageCheckbox.disabled = ignoreWeightingCheckbox.checked;
prefixes = ignoreWeightingCheckbox.checked ? unweightedPrefixes : basePrefixes;
suffixes = ignoreWeightingCheckbox.checked ? unweightedSuffixes : baseSuffixes;
}
function generateName() {
let prefix = prefixes[Math.floor(Math.random() * prefixes.length)];
let suffix;
let kit = false;
let randomIndex;
if (includeUnderageCheckbox.checked) {
randomIndex = Math.floor(Math.random() * (suffixes.length + totalApprentices + totalKits));
if (randomIndex < suffixes.length) {
suffix = suffixes[randomIndex];
} else if (randomIndex < suffixes.length + totalApprentices) {
suffix = "爪";
} else {
kit = true;
}
} else {
suffix = suffixes[Math.floor(Math.random() * suffixes.length)];
}
const name = kit ? "小" + prefix : prefix + suffix;
document.getElementById("displayName").innerHTML = name;
}
includeUnderageCheckbox.addEventListener('click', changeIncludeUnderage);
ignoreWeightingCheckbox.addEventListener('click', changeIgnoreWeighting);
document.querySelector('.btn-primary').addEventListener('click', generateName);
}
// 检查zh-cn.js是否已加载
if (typeof data !== 'undefined') {
init();
} else {
// 如果未加载,等待加载完成
window.addEventListener('load', init);
}
});
</script>
</body>
</html>