Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>
<div class="container">
<img id="mainImage" src="images/heart.png" alt="爱心">
<h1 id="question">可以成为我的恋人吗?</h1>
<h1 id="question"><a id="egg">可以</a>成为我的恋人吗?</h1>
<div class="buttons">
<button id="yes">可以</button>
<button id="no">不要</button>
Expand All @@ -18,4 +18,4 @@ <h1 id="question">可以成为我的恋人吗?</h1>

<script src="script.js"></script>
</body>
</html>
</html>
21 changes: 17 additions & 4 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ let username = params.get("name");

// 限制用户名长度,避免页面样式崩坏
const maxLength = 20;
const safeUsername = username ? username.substring(0, maxLength) : "???";
const safeUsername = username ? username.substring(0, maxLength).replace(/[&<>"'`=/]/g, (match) => ({
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
'/': '&#x2F;',
'`': '&#x60;',
'=': '&#x3D;'
}[match])) : "???";

// 防止 `null` 变成 `"null"`
if (username) {
questionText.innerText = questionText.innerText + safeUsername;
questionText.innerHTML = questionText.innerHTML + safeUsername;
}
let eggButton = document.getElementById("egg");

let clickCount = 0; // 记录点击 No 的次数

Expand Down Expand Up @@ -61,7 +71,7 @@ const loveTest = `!!!喜欢你!! ( >᎑<)♡︎ᐝ ${
username ? `${safeUsername} ♡︎ᐝ(>᎑< )` : ""
}`;

yesButton.addEventListener("click", function () {
function ok() {
// 先创建基础 HTML 结构
document.body.innerHTML = `
<div class="yes-screen">
Expand All @@ -75,4 +85,7 @@ yesButton.addEventListener("click", function () {

// 禁止滚动,保持页面美观
document.body.style.overflow = "hidden";
});
}

yesButton.addEventListener("click", ok);
eggButton.addEventListener("click", ok);