// ==UserScript==
// @name 网页访问加税模拟器
// @name:en Web Page Tariff Simulator
// @namespace http://tampermonkey.net/
// @version 2.0
// @description 模拟对网页访问加征关税,讽刺贸易战
// @description:en Simulate web page access tariffs to satirize trade wars
// @author xjy666a
// @icon https://www.helloimg.com/i/2025/04/26/680c5a6a35086.png
// @match *://*/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @license MIT
// ==/UserScript==
/*
MIT License
Copyright (c) 2025 xjy666a
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
(function() {
'use strict';
// 用户配置
let taxRate = GM_getValue('taxRate', 125); // 默认税率为125%
let isEnabled = GM_getValue('isEnabled', true); // 默认启用
let customExemptDomains = GM_getValue('customExemptDomains', []); // 用户自定义免税域名
let highScore = GM_getValue('trumpGameHighScore', 0); // 打朗普游戏最高分
let wallGameHighScore = GM_getValue('wallGameHighScore', 0); // 建墙游戏最高分
// 用于跟踪独立游戏实例
let standaloneGameActive = false;
// 清关失败统计
let clearanceFailCount = GM_getValue('clearanceFailCount', 0);
// 清关失败概率 (默认5%)
let clearanceFailRate = GM_getValue('clearanceFailRate', 5);
// 关税减免申请状态
let exemptionApplicationStatus = GM_getValue('exemptionApplicationStatus', 'none'); // none, pending, approved, rejected
let exemptionApplicationProgress = GM_getValue('exemptionApplicationProgress', 0);
// --- History Log START ---
const MAX_HISTORY_ENTRIES = 50;
// --- History Log END ---
// 特朗普风格语录
const trumpQuotes = [
"这关税... 是最好的关税。所有人都同意!",
"我们在让网络再次伟大,相信我!",
"假新闻网站?太可悲了!我们要加倍收税。",
"加载时间?我们有最好的加载时间,这都多亏了我。",
"中国!他们发送糟糕的数据包,我们就用关税回击!",
"这是个漂亮的关税,一个非常、非常强力的关税。",
"没人比我更懂网络关税。",
"这些加载延迟对国家安全来说是巨大的贡献。",
"我们在建一堵数字墙,网站们会付出代价的(用加载时间)!",
"你们将看到难以置信的数字……前所未有的加载时间!",
"让网络再次伟大!让网络再次伟大!",
"这关税太棒了,简直完美!很多人都这么说。",
"速度太快?那是假新闻!慢下来才能思考爱国。",
"每一个字节都要经过严格审查,非常严格!",
];
// 预设免税网站列表
const defaultExemptDomains = [
// 手机网站
'apple.com', 'mi.com', 'oneplus.com', 'samsung.com', 'huawei.com',
'vivo.com', 'oppo.com', 'motorola.com', 'gsmarena.com', 'phonearena.com',
// 半导体网站
'intel.com', 'amd.com', 'nvidia.com', 'qualcomm.com', 'arm.com',
'tsmc.com', 'micron.com', 'broadcom.com', 'analog.com', 'ti.com',
'nxp.com', 'infineon.com', 'st.com', 'rohm.com', 'renesas.com',
'skhynix.com', 'asml.com', 'semi.org', 'semiconductors.org'
];
// 清关失败原因列表
const clearanceFailReasons = [
"海关系统维护中,请稍后再试",
"IP地址与爱国证明不匹配",
"关税标准变更,请重新申报",
"关税支付系统超时",
"未检测到有效的数字主权凭证",
"WEB朗普发布新政策,需重新评估",
"清关系统检测到非法字节",
"数据包超重,需缴纳额外关税",
"关税征收点拥堵,请排队等待",
"您的浏览器关税特征被列入重点核查名单"
];
// 合并默认和自定义免税域名
let exemptDomains = [...defaultExemptDomains, ...customExemptDomains];
// 判断当前网站是否免税
function isExemptWebsite() {
const currentHost = window.location.hostname.toLowerCase();
// 检查是否为直接匹配的免税网站
if (exemptDomains.some(domain => currentHost.includes(domain))) {
return true;
}
// 检查是否为免税网站的中国域名版本(.cn)
// 例如:apple.cn, apple.com.cn, mi.cn, mi.com.cn 等
for (const domain of exemptDomains) {
const baseDomain = domain.replace('.com', '').replace('.org', '');
if (currentHost.includes(`${baseDomain}.cn`) ||
currentHost.includes(`${baseDomain}.com.cn`)) {
return true;
}
}
return false;
}
// 显示清关失败界面
function showClearanceFailure(originalLoadTime, taxedLoadTime, finalScore, originalBodyOverflow, failReason) { // Added failReason parameter
// 增加清关失败计数
clearanceFailCount++;
GM_setValue('clearanceFailCount', clearanceFailCount);
// 使用传递的失败原因
// const failReason = clearanceFailReasons[Math.floor(Math.random() * clearanceFailReasons.length)]; // Removed
// 创建失败通知
const failureDiv = document.createElement('div');
failureDiv.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,0.8);display:flex;flex-direction:column;justify-content:center;align-items:center;z-index:2147483647;';
failureDiv.innerHTML = `
⚠️ 清关失败 ⚠️
失败原因: ${failReason}
这是您的第 ${clearanceFailCount} 次清关失败
当前清关失败概率: ${clearanceFailRate}%
重新清关
跳过清关
申请减免
WEBump提示:"清关失败是因为被中国黑客入侵了系统!"
`;
document.body.appendChild(failureDiv);
// 添加重试按钮事件
document.getElementById('retryClearanceBtn').addEventListener('click', function() {
failureDiv.remove();
// Remove the main tax overlay as well before retrying
const mainOverlay = document.getElementById('taxOverlayElement');
if (mainOverlay) mainOverlay.remove();
// Restore scrolling before retrying
document.body.style.overflow = originalBodyOverflow;
startTaxProcess(originalLoadTime); // Retry with original load time
});
// 添加跳过按钮事件
document.getElementById('skipClearanceBtn').addEventListener('click', function() {
failureDiv.remove();
// Remove the main tax overlay
const mainOverlay = document.getElementById('taxOverlayElement');
if (mainOverlay) mainOverlay.remove();
// Call the NEW completeTaxProcess
completeTaxProcess(originalLoadTime, taxedLoadTime, finalScore, originalBodyOverflow);
});
// 添加申请减免按钮事件
document.getElementById('applyExemptionBtn').addEventListener('click', function() {
failureDiv.remove();
// Fix: Also remove the main tax overlay and restore scrolling
const mainOverlay = document.getElementById('taxOverlayElement');
if (mainOverlay) mainOverlay.remove();
document.body.style.overflow = originalBodyOverflow;
launchExemptionApplication();
});
}
// 启动加税流程
function startTaxProcess(originalLoadTime) {
const taxedLoadTime = originalLoadTime * (1 + taxRate / 100);
const additionalWaitTime = taxedLoadTime - originalLoadTime;
// Store original body overflow style and disable scrolling
const originalBodyOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
const taxOverlay = document.createElement('div');
taxOverlay.id = 'taxOverlayElement'; // Add an ID for easier removal
taxOverlay.style.cssText = `
position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; /* Full screen */
background: linear-gradient(135deg, rgba(247, 250, 252, 0.95) 0%, rgba(226, 232, 240, 0.95) 100%); /* Slightly transparent gradient */
backdrop-filter: blur(5px); /* Blur background */
display: flex; /* Use flex for columns */
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
z-index: 2147483647; /* Max z-index */
opacity: 0; transition: opacity 0.5s ease-in-out;
`;
// Randomly select a quote
const randomQuote = trumpQuotes[Math.floor(Math.random() * trumpQuotes.length)];
taxOverlay.innerHTML = `
执行 MWGA 关税!
根据 Make Web Great Again 指示,需加征 ${taxRate}% 关税。
非 MWGA 加载:
${(originalLoadTime/1000).toFixed(2)} 秒
MWGA 加载:
${(taxedLoadTime/1000).toFixed(2)} 秒
正在执行 "让网络再次伟大" 延迟:
MWGA
"${randomQuote}" - WEBump
Make Web Great Again!
等待期间,来玩"打朗普"!
申请 MWGA 特殊豁免
`;
document.body.appendChild(taxOverlay);
// Fade in the overlay
setTimeout(() => {
taxOverlay.style.opacity = '1';
}, 50);
// Add game (adjust styles if needed)
addGameStyles(); // General styles like ripple/float animations
// --- MODIFICATION START: Randomly select and add a game ---
const gameFunctions = [createTrumpGame, createBuildWallGame];
const selectedGameFunction = gameFunctions[Math.floor(Math.random() * gameFunctions.length)];
const gameContainer = selectedGameFunction(); // Call the randomly selected function
// Style the container from the selected game to fit the placeholder
gameContainer.style.margin = '0 auto';
gameContainer.style.border = '2px solid #e2e8f0';
gameContainer.style.backgroundColor = 'white'; // Ensure game bg
gameContainer.style.width = '100%'; // Fit placeholder width
gameContainer.style.height = '400px'; // Define height
const gamePlaceholder = document.getElementById('gamePlaceholder');
gamePlaceholder.innerHTML = ''; // Clear placeholder before adding new game
gamePlaceholder.appendChild(gameContainer);
// --- MODIFICATION END ---
// !!! Check if the created game is Trump game before adding Trump logic !!!
if (gameContainer.id === 'trumpGame') {
const trump = createTrump(gameContainer);
// Trump is created within createTrumpGame now, this might be redundant or need adjustment
// Let's verify createTrumpGame - yes, it appends score/highscore/title/instruction.
// Let's verify createTrump - it creates and returns the trump div, but doesn't append it.
// So, we still need to append the trump element if it's the trump game.
gameContainer.appendChild(trump);
}
// Exemption Button interactions
const exemptionBtn = document.getElementById('applyExemptionTaxBtn');
exemptionBtn.addEventListener('click', function() { launchExemptionApplication(); });
exemptionBtn.addEventListener('mouseover', function() { this.style.backgroundColor = '#d69e2e'; });
exemptionBtn.addEventListener('mouseout', function() { this.style.backgroundColor = '#ecc94b'; });
exemptionBtn.addEventListener('mousedown', function() { this.style.transform = 'scale(0.98)'; });
exemptionBtn.addEventListener('mouseup', function() { this.style.transform = 'scale(1)'; });
// Progress bar and countdown logic
const progressFill = document.getElementById('taxProgressFill');
const countdownEl = document.getElementById('taxCountdown');
// Trigger reflow to ensure transition starts correctly
void progressFill.offsetWidth;
progressFill.style.width = '0%';
const updateInterval = 100;
let remainingTime = additionalWaitTime;
const countdownInterval = setInterval(() => {
remainingTime -= updateInterval;
// const percentage = Math.max(0, (remainingTime / additionalWaitTime * 100)); // Not used directly for fill anymore
countdownEl.textContent = `剩余等待时间:${(Math.max(0, remainingTime)/1000).toFixed(1)} 秒`;
if (remainingTime <= 0) {
clearInterval(countdownInterval);
countdownEl.textContent = '关税支付完成!';
setTimeout(() => {
const finalScore = document.getElementById('trumpGameScore') ? parseInt(document.getElementById('trumpGameScore').textContent.replace('关税得分: ', '')) : 0;
// Fade out overlay before completing
taxOverlay.style.transition = 'opacity 0.5s ease-out';
taxOverlay.style.opacity = '0';
setTimeout(() => {
// --- HISTORY LOGGING START ---
const historyEntry = {
timestamp: new Date().toISOString(),
url: window.location.href, // Get current URL
originalLoadTime: originalLoadTime,
taxRate: taxRate,
taxedLoadTime: taxedLoadTime,
status: 'Unknown', // Will be set below
// Add score if needed: gameScore: finalScore
};
// --- HISTORY LOGGING END ---
if (Math.random() < (clearanceFailRate / 100)) {
// --- HISTORY LOGGING: FAILURE ---
const failReason = clearanceFailReasons[Math.floor(Math.random() * clearanceFailReasons.length)]; // Get the reason that will be shown
historyEntry.status = 'Failure';
historyEntry.failReason = failReason; // Store the reason
addHistoryEntry(historyEntry);
// --- END HISTORY LOGGING ---
// Still show failure overlay, but pass the original body overflow style and reason
showClearanceFailure(originalLoadTime, taxedLoadTime, finalScore, originalBodyOverflow, failReason);
// Keep the main overlay temporarily until user action in failure screen
} else {
// --- HISTORY LOGGING: SUCCESS ---
historyEntry.status = 'Success';
addHistoryEntry(historyEntry);
// --- END HISTORY LOGGING ---
// Call the NEW completeTaxProcess, only passing necessary info
completeTaxProcess(originalLoadTime, taxedLoadTime, finalScore, originalBodyOverflow);
}
// Restore scrolling *after* fade out or when handled by completeTaxProcess/showClearanceFailure
// document.body.style.overflow = originalBodyOverflow; // Moved to completeTaxProcess/showClearanceFailure logic
}, 500); // Wait for fade out
}, 500); // Delay after completion message
}
}, updateInterval);
}
// 完成加税流程,移除遮罩并显示标记
function completeTaxProcess(originalLoadTime, taxedLoadTime, finalScore, originalBodyOverflow) {
try {
// 移除主遮罩层
const taxOverlay = document.getElementById('taxOverlayElement');
if (taxOverlay) {
taxOverlay.remove();
}
// 恢复页面滚动
document.body.style.overflow = originalBodyOverflow;
// 添加关税标记 (样式和内容保持不变)
const taxPaidMark = document.createElement('div');
taxPaidMark.style.cssText = `
position: fixed;
top: 10px;
right: 10px;
background: rgba(0, 0, 0, 0.8);
color: white;
padding: 15px 20px;
border-radius: 8px;
font-size: 14px;
z-index: 2147483646; /* Slightly lower than overlay */
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
max-width: 300px;
backdrop-filter: blur(5px);
`;
taxPaidMark.innerHTML = `
⚠️ MWGA 关税已征收 ${taxRate}%
原始加载:
${(originalLoadTime/1000).toFixed(2)}秒
关税后加载:
${(taxedLoadTime/1000).toFixed(2)}秒
${finalScore > 0 ? `
打朗普得分:
${finalScore} 点
` : ''}
${clearanceFailCount > 0 ? `
历史清关失败:
${clearanceFailCount} 次
` : ''}
点击关闭此提示
`;
document.body.appendChild(taxPaidMark);
// 添加MWGA标语 (样式和内容保持不变)
const mwgaBanner = document.createElement('div');
mwgaBanner.style.cssText = `
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background: linear-gradient(135deg, #e53e3e 0%, #f56565 100%);
color: white;
padding: 12px 30px;
border-radius: 8px;
font-size: 18px;
z-index: 2147483646; /* Slightly lower than overlay */
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
text-align: center;
font-weight: bold;
cursor: pointer;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
`;
mwgaBanner.innerHTML = `
M W G A
Make Web Great Again!
`;
document.body.appendChild(mwgaBanner);
// 点击移除标记 (动画效果保持不变)
taxPaidMark.addEventListener('click', function() {
taxPaidMark.style.transition = 'opacity 0.3s, transform 0.3s';
taxPaidMark.style.opacity = '0';
taxPaidMark.style.transform = 'translateX(20px)';
setTimeout(() => taxPaidMark.remove(), 300);
});
mwgaBanner.addEventListener('click', function() {
mwgaBanner.style.transition = 'opacity 0.3s, transform 0.3s';
mwgaBanner.style.opacity = '0';
mwgaBanner.style.transform = 'translate(-50%, 20px)';
setTimeout(() => mwgaBanner.remove(), 300);
});
// 10秒后自动消失 (动画效果保持不变)
setTimeout(() => {
if (taxPaidMark.parentNode) {
taxPaidMark.style.transition = 'opacity 1s, transform 1s';
taxPaidMark.style.opacity = '0';
taxPaidMark.style.transform = 'translateX(20px)';
setTimeout(() => taxPaidMark.remove(), 1000);
}
if (mwgaBanner.parentNode) {
mwgaBanner.style.transition = 'opacity 1s, transform 1s';
mwgaBanner.style.opacity = '0';
mwgaBanner.style.transform = 'translate(-50%, 20px)';
setTimeout(() => mwgaBanner.remove(), 1000);
}
}, 10000);
} catch (error) {
console.error('完成关税流程时发生错误', error);
// Optionally add a fallback error message if needed, though simpler is better now.
// Restore scrolling even if adding marks failed
document.body.style.overflow = originalBodyOverflow;
}
}
// 独立启动打朗普游戏
function launchStandaloneGame() {
// 如果游戏已经在运行,则不要重复启动
if (document.getElementById('standaloneGameOverlay')) {
alert('另一个独立小游戏已经在运行中!');
return;
}
standaloneGameActive = true; // Keep track specifically for Trump game if needed elsewhere, though generic overlay check is primary
// 添加样式
addGameStyles();
// --- MODIFICATION START: Standardize Overlay and Layout ---
// 创建游戏容器覆盖层
const gameOverlay = document.createElement('div');
gameOverlay.id = 'standaloneGameOverlay'; // Use generic ID
gameOverlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,0.85);display:flex;flex-direction:column;justify-content:center;align-items:center;z-index:2147483647;';
// 创建游戏布局容器
const gameLayout = document.createElement('div');
gameLayout.style.cssText = 'background-color:white;border-radius:15px;padding:30px;box-shadow:0 5px 25px rgba(0,0,0,0.5);position:relative;max-width:90%;width:500px;min-height:550px; display: flex; flex-direction: column;'; // Match wall game layout
// 添加标题和说明
const gameHeader = document.createElement('div');
gameHeader.style.cssText = 'text-align:center;margin-bottom:10px;'; // Reduced margin
gameHeader.innerHTML = `
🎮 打朗普小游戏 🎮
`;// 点击WEB朗普获得关税点数!
- Moved instruction inside game container
gameLayout.appendChild(gameHeader);
// 添加计时器显示
const timerDisplay = document.createElement('div');
timerDisplay.id = 'trumpGameTimer'; // Use this ID for the timer logic
timerDisplay.style.cssText = 'text-align:center; font-size: 18px; color: #333; margin-bottom: 15px; font-weight: bold;';
timerDisplay.textContent = '剩余时间: 20 秒'; // Ensure this is 20s
gameLayout.appendChild(timerDisplay);
// 创建打朗普游戏容器 (Function already handles title/score/instruction inside)
const gameContainer = createTrumpGame();
gameContainer.style.width = '100%'; // Fit layout width
gameContainer.style.height = 'auto'; // Let content define height
gameContainer.style.flexGrow = '1'; // Take remaining space
gameContainer.style.margin = '0'; // Reset margin
// gameContainer.style.border = '2px solid #e2e8f0'; // Border is already added by createTrumpGame
gameLayout.appendChild(gameContainer);
// 创建特朗普元素并添加到游戏容器中
const trump = createTrump(gameContainer);
gameContainer.appendChild(trump);
// 关闭按钮 (Inside layout, top right)
const closeButton = document.createElement('button');
closeButton.textContent = '✖ 关闭游戏';
closeButton.style.cssText = 'position:absolute;top:20px;right:20px;background:#cc0000;color:white;border:none;border-radius:5px;padding:8px 15px;cursor:pointer;font-weight:bold; z-index: 11;';
closeButton.addEventListener('click', function() {
endStandaloneGame(true); // Pass true for userCancelled
});
gameLayout.appendChild(closeButton);
// 添加免责声明/提示
const disclaimer = document.createElement('div');
disclaimer.style.cssText = 'text-align:center;font-size:12px;color:#aaa;margin-top:15px;';
disclaimer.textContent = '独立游戏模式 - 在20秒内尽可能得分!'; // Ensure this is 20s
gameLayout.appendChild(disclaimer);
// --- MODIFICATION END ---
// 组装并显示
gameOverlay.appendChild(gameLayout);
document.body.appendChild(gameOverlay);
// 添加键盘事件监听器 (use renamed function)
document.addEventListener('keydown', handleTrumpGameKeyPress);
// 60秒游戏时间倒计时 (Use the new timerDisplay) - Changed to 20s
let timeLeft = 20; // Ensure this is 20s
const countdownTimer = setInterval(() => {
timeLeft--;
// Update the new timer display element
const currentTimerDisplay = document.getElementById('trumpGameTimer');
if (currentTimerDisplay) {
currentTimerDisplay.textContent = `剩余时间: ${timeLeft} 秒`;
}
if (timeLeft <= 0) {
clearInterval(countdownTimer);
if (currentTimerDisplay) {
currentTimerDisplay.textContent = '时间到!';
}
// Delay slightly before ending to show "Time's up!"
setTimeout(() => {
endStandaloneGame(false);
}, 500);
}
}, 1000);
// 保存游戏计时器以便后续清除
gameOverlay.countdownTimer = countdownTimer;
}
// 键盘事件处理 - Rename
function handleTrumpGameKeyPress(e) {
// ESC键关闭游戏
if (e.key === 'Escape') {
endStandaloneGame(true);
}
}
// 结束独立游戏
function endStandaloneGame(userCancelled) {
const gameOverlay = document.getElementById('standaloneGameOverlay');
if (!gameOverlay) return;
// 清除计时器
if (gameOverlay.countdownTimer) {
clearInterval(gameOverlay.countdownTimer);
}
// 移除键盘事件监听器
document.removeEventListener('keydown', handleTrumpGameKeyPress); // Use renamed function
// 获取分数
let finalScore = 0;
const scoreEl = document.getElementById('trumpGameScore');
if (scoreEl) {
finalScore = parseInt(scoreEl.textContent.replace('关税得分: ', ''));
}
// 渐隐效果
gameOverlay.style.transition = 'opacity 0.5s';
gameOverlay.style.opacity = '0';
setTimeout(() => {
gameOverlay.remove();
standaloneGameActive = false;
// 如果不是用户取消,显示结果
if (!userCancelled) {
showGameResults(finalScore);
}
}, 500);
}
// 显示游戏结果
function showGameResults(score) {
const resultDiv = document.createElement('div');
// Use the same red border as the Trump game itself
resultDiv.style.cssText = 'position:fixed;top:50%;left:50%;transform:translate(-50%, -50%);background:white;border:3px solid #cc0000;border-radius:10px;padding:30px;box-shadow:0 5px 25px rgba(0,0,0,0.5);z-index:2147483647;text-align:center;min-width:320px;'; // Adjusted padding and z-index
// 提示文字根据分数多少
let message = '';
if (score >= 50) {
message = '你是击朗派高手!WEB朗普表示:VERY UNFAIR!';
} else if (score >= 30) {
message = '你很擅长击朗!Make Web Great Again!';
} else if (score >= 15) {
message = '不错的尝试,但WEB朗普会回来的!';
} else {
message = 'WEB朗普发推文:FAKE POINTS!';
}
resultDiv.innerHTML = `
游戏结束!
你的得分: ${score} 点
${message}
再玩一次
关闭
`;
document.body.appendChild(resultDiv);
// 添加按钮事件
document.getElementById('playAgainBtn').addEventListener('click', function() {
resultDiv.remove();
launchStandaloneGame();
});
document.getElementById('closeResultBtn').addEventListener('click', function() {
resultDiv.remove();
});
// 30秒后自动关闭
setTimeout(() => {
if (document.body.contains(resultDiv)) {
resultDiv.style.transition = 'opacity 0.5s, transform 0.5s';
resultDiv.style.opacity = '0';
resultDiv.style.transform = 'translate(-50%, -60%)';
setTimeout(() => resultDiv.remove(), 500);
}
}, 30000);
}
// 添加单独启动游戏的菜单 - 修改为选择器
// GM_registerMenuCommand('🎮 开始打朗普游戏', launchStandaloneGame);
// 游戏选择器函数
function launchStandaloneGameSelector() {
// 如果游戏已经在运行,则不要重复启动
if (document.getElementById('standaloneGameOverlay') || document.getElementById('gameSelectorOverlay')) {
alert('小游戏或选择器已在运行中!');
return;
}
const selectorOverlay = document.createElement('div');
selectorOverlay.id = 'gameSelectorOverlay';
selectorOverlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,0.7);display:flex;justify-content:center;align-items:center;z-index:2147483647;';
selectorOverlay.innerHTML = `
选择你想玩的小游戏
🎮 打朗普
🧱 建墙小游戏
取消
`;
selectorOverlay.addEventListener('click', (event) => {
const target = event.target.closest('button[data-game]');
if (!target) return;
const gameType = target.getAttribute('data-game');
selectorOverlay.remove(); // Remove selector once a choice is made or cancelled
if (gameType === 'trump') {
launchStandaloneGame();
} else if (gameType === 'wall') {
launchStandaloneBuildWallGame();
}
// 'cancel' case just removes the overlay, which is already done
});
document.body.appendChild(selectorOverlay);
}
// 注册新的菜单命令
GM_registerMenuCommand('🎮 开始玩小游戏', launchStandaloneGameSelector);
// 添加清空清关失败次数的菜单
GM_registerMenuCommand('🔄 重置清关失败计数', function() {
if (clearanceFailCount > 0) {
if (confirm(`确定要重置清关失败计数吗?当前失败次数: ${clearanceFailCount}`)) {
clearanceFailCount = 0;
GM_setValue('clearanceFailCount', 0);
alert('已重置清关失败计数');
}
} else {
alert('清关失败计数已经为0');
}
});
// 添加设置清关失败概率的菜单
GM_registerMenuCommand('⚠️ 设置清关失败概率', function() {
const newRate = prompt(`请输入清关失败概率(0-100,如:5表示5%):\n\n当前值: ${clearanceFailRate}%`, clearanceFailRate);
if (newRate !== null && !isNaN(newRate) && newRate >= 0 && newRate <= 100) {
clearanceFailRate = parseFloat(newRate);
GM_setValue('clearanceFailRate', clearanceFailRate);
alert(`清关失败概率已设置为 ${clearanceFailRate}%`);
} else if (newRate !== null) {
alert('请输入0-100之间的有效数字');
}
});
// 注册菜单命令
GM_registerMenuCommand('✅ 开启/关闭加税功能', function() {
isEnabled = !isEnabled;
GM_setValue('isEnabled', isEnabled);
alert(`加税功能已${isEnabled ? '开启' : '关闭'},刷新页面生效`);
location.reload();
});
GM_registerMenuCommand('💰 设置网页访问税率', function() {
const newRate = prompt('请输入网页访问税率(如:125表示125%):', taxRate);
if (newRate !== null && !isNaN(newRate) && newRate >= 0) {
taxRate = parseFloat(newRate);
GM_setValue('taxRate', taxRate);
alert(`税率已设置为 ${taxRate}%`);
}
});
GM_registerMenuCommand('🔍 管理自定义免税网站', function() {
let message = '当前自定义免税网站列表(每行一个域名):\n';
message += '例如: example.com\n\n';
message += '提示:修改后需刷新页面生效\n\n';
const domainsText = prompt(message, customExemptDomains.join('\n'));
if (domainsText !== null) {
// 解析用户输入的域名(按行分割)
const domains = domainsText
.split('\n')
.map(domain => domain.trim())
.filter(domain => domain.length > 0);
// 保存设置
customExemptDomains = domains;
GM_setValue('customExemptDomains', customExemptDomains);
// 更新合并的列表
exemptDomains = [...defaultExemptDomains, ...customExemptDomains];
if (confirm(`已保存 ${domains.length} 个自定义免税网站,需要刷新页面才能生效。\n\n是否立即刷新页面?`)) {
location.reload();
}
}
});
// 添加清空自定义免税网站的菜单
GM_registerMenuCommand('🗑️ 清空自定义免税网站', function() {
if (customExemptDomains.length === 0) {
alert('自定义免税网站列表已经是空的');
return;
}
if (confirm(`确定要清空所有 ${customExemptDomains.length} 个自定义免税网站吗?`)) {
customExemptDomains = [];
GM_setValue('customExemptDomains', []);
// 更新合并的列表
exemptDomains = [...defaultExemptDomains];
if (confirm('已清空自定义免税网站列表,需要刷新页面才能生效。\n\n是否立即刷新页面?')) {
location.reload();
}
}
});
// 添加删除单个免税网站的菜单
GM_registerMenuCommand('✂️ 删除单个免税网站', function() {
if (customExemptDomains.length === 0) {
alert('自定义免税网站列表为空,没有可删除的网站');
return;
}
// 构建带有编号的域名列表
let listMessage = '当前自定义免税网站列表:\n\n';
customExemptDomains.forEach((domain, index) => {
listMessage += `${index + 1}. ${domain}\n`;
});
listMessage += '\n请输入要删除的网站序号(1-' + customExemptDomains.length + '),或直接输入域名:';
const userInput = prompt(listMessage);
if (userInput === null) return; // 用户取消
let indexToRemove = -1;
const inputNum = parseInt(userInput);
// 检查是否输入的是有效序号
if (!isNaN(inputNum) && inputNum >= 1 && inputNum <= customExemptDomains.length) {
indexToRemove = inputNum - 1;
} else {
// 按域名查找
indexToRemove = customExemptDomains.findIndex(domain =>
domain.toLowerCase() === userInput.toLowerCase().trim());
}
if (indexToRemove === -1) {
alert('未找到匹配的免税网站,请检查输入');
return;
}
// 获取要删除的域名并确认
const domainToRemove = customExemptDomains[indexToRemove];
if (confirm(`确定要删除免税网站 "${domainToRemove}" 吗?`)) {
// 删除指定域名
customExemptDomains.splice(indexToRemove, 1);
GM_setValue('customExemptDomains', customExemptDomains);
// 更新合并列表
exemptDomains = [...defaultExemptDomains, ...customExemptDomains];
if (confirm(`已删除免税网站 "${domainToRemove}",需要刷新页面才能生效。\n\n是否立即刷新页面?`)) {
location.reload();
}
}
});
// 关税减免申请系统
function launchExemptionApplication() {
// 如果已经申请或批准/拒绝,提示用户
if (exemptionApplicationStatus !== 'none') {
let message = '您已提交关税减免申请。';
if (exemptionApplicationStatus === 'pending') {
message += `\n当前状态: 审核中... (${exemptionApplicationProgress}/5 步)`;
} else if (exemptionApplicationStatus === 'approved') {
message += '\n状态: 已批准!恭喜您获得关税豁免!';
} else if (exemptionApplicationStatus === 'rejected') {
message += '\n状态: 已拒绝。原因:材料不符合WEB朗普的最新指示。';
}
alert(message);
return;
}
// 弹出申请界面
const overlay = document.createElement('div');
overlay.id = 'exemptionOverlay';
overlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,0.8);display:flex;flex-direction:column;justify-content:center;align-items:center;z-index:9999;';
const formDiv = document.createElement('div');
formDiv.style.cssText = 'background-color:white;border-radius:15px;padding:30px;max-width:90%;width:700px;text-align:center;box-shadow:0 10px 30px rgba(0,0,0,0.5);max-height:80vh;overflow-y:auto;';
// 申请流程步骤
const steps = [
{ title: '第一步:宣誓效忠', content: `
请完整抄写以下誓词以证明您对Make Web Great Again事业的忠诚:
` },
{ title: '第二步:提交爱国证明', content: `
请上传您的数字爱国者认证文件(仅接受.mwga格式):
(提示:.mwga文件可通过购买官方MWGA周边产品获得)
` },
{ title: '第三步:回答安全问题', content: `
请回答以下由WEB朗普总统亲自设计的安全问题:
1. 您认为谁是历史上最伟大的总统?
2. "Make Web Great Again"的下一句是什么?
3. 请用三个词形容您对关税政策的感受:
` },
{ title: '第四步:等待随机审核', content: `
您的申请已提交至关税随机审核系统(TRAS)。请保持耐心,审核结果将以弹窗形式通知。
审核过程可能需要5-500个工作日,请勿关闭浏览器...
` },
{ title: '第五步:最终确认', content: `
审核中... 请确认您已知悉以下条款:
关税减免资格随时可能因政策调整而撤销。
获得减免后仍需接受随机数字内容审查。
WEB朗普总统拥有最终解释权。
我已阅读并同意上述所有条款
` }
];
let currentStep = 0;
function renderStep() {
formDiv.innerHTML = `
关税减免申请 (${currentStep + 1}/${steps.length})
${steps[currentStep].title}
${steps[currentStep].content}
${currentStep > 0 ? '上一步 ' : ''}
${currentStep === steps.length - 1 ? '提交最终申请' : '下一步'}
取消申请
提示:提交虚假信息可能导致您的数字信用评分降至"FAKE NEWS"级。
`;
// 使用事件委托处理按钮点击
const buttonContainer = formDiv.querySelector('#exemptionFormButtons');
if (buttonContainer) {
// 移除旧的监听器(如果存在)
buttonContainer.replaceWith(buttonContainer.cloneNode(true));
formDiv.querySelector('#exemptionFormButtons').addEventListener('click', (event) => {
const target = event.target;
if (target.tagName === 'BUTTON') {
const action = target.getAttribute('data-action');
if (action === 'prev') {
currentStep--;
renderStep();
} else if (action === 'next') {
handleNextStep();
} else if (action === 'cancel') {
overlay.remove();
}
}
});
}
// 特殊步骤处理
if (currentStep === 3) {
// 模拟审核进度条
setTimeout(() => {
const progressBar = document.getElementById('reviewProgress');
if (progressBar) progressBar.style.width = '100%';
}, 100);
}
}
function handleNextStep() {
// 验证当前步骤
if (currentStep === 0) {
const oathText = document.getElementById('oathText').value;
const oathInput = document.getElementById('oathInput').value;
if (oathInput.trim() !== oathText.trim()) {
alert('誓词抄写不完整或有误,请仔细核对!忠诚度-10!');
return;
}
} else if (currentStep === 1) {
const fileInput = document.getElementById('patriotFile');
if (!fileInput.files || fileInput.files.length === 0) {
alert('请上传您的数字爱国者认证文件 (.mwga)!没有?快去买周边!');
return;
} else if (!fileInput.files[0].name.endsWith('.mwga')) {
alert('文件格式错误!仅接受.mwga格式!回去好好学习!');
return;
}
} else if (currentStep === 2) {
const q1 = document.getElementById('q1').value.toLowerCase();
const q2 = document.getElementById('q2').value;
const q3 = document.getElementById('q3').value;
if (!q1.includes('trump') && !q1.includes('朗普')) {
alert('第一题答案错误!再想想谁才是最伟大的总统!');
return;
}
if (q2.trim() === '') {
alert('第二题不能为空!连口号都不知道还想减免?');
return;
}
if (q3.trim() === '') {
alert('第三题不能为空!快用伟大、公平、胜利来形容!');
return;
}
} else if (currentStep === 4) {
if (!document.getElementById('finalConfirm').checked) {
alert('请先勾选同意条款!不同意还想占便宜?');
return;
}
}
// 进入下一步或提交
if (currentStep < steps.length - 1) {
currentStep++;
renderStep();
} else {
submitApplication();
}
}
function submitApplication() {
// 标记为审核中
exemptionApplicationStatus = 'pending';
exemptionApplicationProgress = 0; // 从0开始
GM_setValue('exemptionApplicationStatus', 'pending');
GM_setValue('exemptionApplicationProgress', 0);
overlay.innerHTML = `
申请提交成功!
您的关税减免申请正在由WEB朗普总统亲自审核...
审核过程大约需要1-5个工作日,请耐心等待(或者去买点MWGA股票加速审核)。
关闭
`;
document.getElementById('closeSubmitBtn').addEventListener('click', () => {
overlay.remove();
});
// 模拟漫长的审核过程 (每小时推进一点点)
simulateReviewProcess();
}
// 渲染第一步
renderStep();
overlay.appendChild(formDiv);
document.body.appendChild(overlay);
}
// 模拟审核过程 (后台进行)
function simulateReviewProcess() {
if (exemptionApplicationStatus !== 'pending') return;
const reviewInterval = setInterval(() => {
if (exemptionApplicationStatus !== 'pending') {
clearInterval(reviewInterval);
return;
}
exemptionApplicationProgress++;
GM_setValue('exemptionApplicationProgress', exemptionApplicationProgress);
// 5步完成,随机决定结果 (极低概率批准)
if (exemptionApplicationProgress >= 5) {
clearInterval(reviewInterval);
const isApproved = Math.random() < 0.01; // 1% 批准率
if (isApproved) {
exemptionApplicationStatus = 'approved';
GM_setValue('exemptionApplicationStatus', 'approved');
alert('🥳 恭喜!您的关税减免申请已批准!享受0关税浏览吧!(有效期至下次政策调整)');
// 将当前网站加入临时豁免
if (window.location.hostname) {
customExemptDomains.push(window.location.hostname);
GM_setValue('customExemptDomains', customExemptDomains);
exemptDomains = [...defaultExemptDomains, ...customExemptDomains];
}
} else {
exemptionApplicationStatus = 'rejected';
GM_setValue('exemptionApplicationStatus', 'rejected');
alert('😭 抱歉!您的关税减免申请已被拒绝。原因:忠诚度未达标。请购买更多MWGA产品后重试!');
}
// 重置进度
GM_setValue('exemptionApplicationProgress', 0);
}
}, 3600 * 1000); // 每小时执行一次
}
// 检查是否有待处理的申请
simulateReviewProcess();
// 添加菜单命令
GM_registerMenuCommand('📝 申请关税减免', launchExemptionApplication);
GM_registerMenuCommand('🔄 重置关税减免申请', function(){
if (exemptionApplicationStatus !== 'none') {
if (confirm('确定要重置关税减免申请状态吗?这将清除您当前的申请进度或结果。')) {
exemptionApplicationStatus = 'none';
exemptionApplicationProgress = 0;
GM_setValue('exemptionApplicationStatus', 'none');
GM_setValue('exemptionApplicationProgress', 0);
alert('已重置关税减免申请状态。');
}
} else {
alert('您还没有提交过申请。');
}
});
// 如果功能关闭,仍然注册游戏菜单,但不执行加税逻辑
if (!isEnabled) return;
// 防止重复执行
if (window.taxAlreadyApplied) return;
window.taxAlreadyApplied = true;
// 检查是否为免税网站
if (isExemptWebsite()) {
// 等网页加载完成后显示免税提示
window.addEventListener('load', function() {
const exemptNotice = document.createElement('div');
exemptNotice.style.cssText = 'position:fixed;top:10px;right:10px;background:rgba(0,100,0,0.8);color:white;padding:10px 15px;border-radius:5px;font-size:14px;z-index:9999;box-shadow:0 2px 10px rgba(0,0,0,0.3);';
exemptNotice.innerHTML = `
✅ 此网站享受特殊豁免权
根据最新贸易政策,手机和半导体网站 无需缴纳网页访问关税!
`;
document.body.appendChild(exemptNotice);
// 点击关闭
exemptNotice.addEventListener('click', function() {
exemptNotice.remove();
});
// 5秒后自动消失
setTimeout(() => {
if (exemptNotice.parentNode) {
exemptNotice.style.transition = 'opacity 1s';
exemptNotice.style.opacity = '0';
setTimeout(() => exemptNotice.remove(), 1000);
}
}, 5000);
});
// 免税网站提前返回,不执行加税逻辑
return;
}
// 记录页面加载开始时间
const startTime = performance.now();
// 打朗普小游戏
function createTrumpGame() {
// 游戏容器
const gameContainer = document.createElement('div');
gameContainer.id = 'trumpGame';
gameContainer.style.cssText = 'width:300px;height:350px;margin:30px auto;border:3px solid #cc0000;border-radius:10px;position:relative;overflow:hidden;background-color:#f0f0f0;user-select:none;';
// 游戏面板
const gameScore = document.createElement('div');
gameScore.id = 'trumpGameScore';
gameScore.style.cssText = 'position:absolute;top:10px;left:10px;font-size:20px;font-weight:bold;color:#cc0000;z-index:100;';
gameScore.textContent = '关税得分: 0';
gameContainer.appendChild(gameScore);
// 游戏最高分
const gameHighScore = document.createElement('div');
gameHighScore.id = 'trumpGameHighScore';
gameHighScore.style.cssText = 'position:absolute;top:10px;right:10px;font-size:14px;color:#333;z-index:100;';
gameHighScore.textContent = `最高分: ${highScore}`;
gameContainer.appendChild(gameHighScore);
// 游戏标题
const gameTitle = document.createElement('div');
gameTitle.style.cssText = 'position:absolute;top:40px;left:0;width:100%;text-align:center;font-size:18px;font-weight:bold;color:#333;';
gameTitle.textContent = '🎮 打朗普小游戏';
gameContainer.appendChild(gameTitle);
// 游戏说明
const gameInstruction = document.createElement('div');
gameInstruction.style.cssText = 'position:absolute;top:65px;left:0;width:100%;text-align:center;font-size:14px;color:#666;';
gameInstruction.textContent = '点击WEB朗普获得关税点数!';
gameContainer.appendChild(gameInstruction);
return gameContainer;
}
// 创建朗普元素
function createTrump(gameContainer) {
const trump = document.createElement('div');
trump.classList.add('trump');
trump.style.cssText = 'position:absolute;width:80px;height:80px;cursor:pointer;transition:transform 0.1s;z-index:90;';
// 设置特朗普图片
trump.innerHTML = ` `;
// 随机位置
positionTrump(trump, gameContainer);
// 点击事件
let score = 0;
trump.addEventListener('click', function(e) {
e.stopPropagation();
score++;
// 更新分数
const scoreEl = document.getElementById('trumpGameScore');
scoreEl.textContent = `关税得分: ${score}`;
// 保存最高分
if (score > highScore) {
highScore = score;
GM_setValue('trumpGameHighScore', highScore);
const highScoreEl = document.getElementById('trumpGameHighScore');
highScoreEl.textContent = `最高分: ${highScore}`;
}
// 点击特效
const ripple = document.createElement('div');
ripple.style.cssText = 'position:absolute;width:20px;height:20px;background-color:red;border-radius:50%;pointer-events:none;animation:ripple 0.5s linear;opacity:0.7;z-index:80;';
ripple.style.left = (e.offsetX - 10) + 'px';
ripple.style.top = (e.offsetY - 10) + 'px';
this.appendChild(ripple);
// 点击缩放动画
this.style.transform = 'scale(0.9)';
setTimeout(() => {
this.style.transform = 'scale(1)';
ripple.remove();
}, 100);
// 点击音效
const sounds = [
"Fake News!",
"Tremendous!",
"Billions and Billions!",
"CHINA!",
"MWGA!",
"I'm very rich!",
"The BEST!"
];
const soundBubble = document.createElement('div');
soundBubble.style.cssText = 'position:absolute;background-color:#fff;border:2px solid #cc0000;border-radius:20px;padding:5px 10px;font-size:14px;font-weight:bold;color:#cc0000;animation:float 2s ease-out;pointer-events:none;white-space:nowrap;z-index:95;';
soundBubble.textContent = sounds[Math.floor(Math.random() * sounds.length)];
soundBubble.style.left = (e.offsetX - 20) + 'px';
soundBubble.style.top = (e.offsetY - 40) + 'px';
this.appendChild(soundBubble);
// 2秒后移除气泡
setTimeout(() => soundBubble.remove(), 2000);
// 移动到新位置
positionTrump(this, gameContainer);
});
return trump;
}
// 随机定位朗普
function positionTrump(trump, container) {
const containerWidth = container.offsetWidth;
const containerHeight = container.offsetHeight;
const trumpWidth = 80;
const trumpHeight = 80;
// 随机位置,但避开顶部的分数区域
const maxX = containerWidth - trumpWidth;
const maxY = containerHeight - trumpHeight;
const minY = 100; // 避开顶部文字
const randomX = Math.floor(Math.random() * maxX);
const randomY = Math.floor(Math.random() * (maxY - minY)) + minY;
trump.style.left = randomX + 'px';
trump.style.top = randomY + 'px';
}
// 添加CSS动画
function addGameStyles() {
const styles = document.createElement('style');
styles.innerHTML = `
@keyframes ripple {
0% { transform: scale(1); opacity: 0.7; }
100% { transform: scale(5); opacity: 0; }
}
@keyframes float {
0% { transform: translateY(0); opacity: 1; }
100% { transform: translateY(-40px); opacity: 0; }
}
#trumpGame .trump img:hover {
transform: scale(1.05);
box-shadow: 0 5px 15px rgba(204, 0, 0, 0.5);
}
`;
document.head.appendChild(styles);
}
// 当页面加载完成时
window.addEventListener('load', function() {
// 计算原始加载时间(毫秒)
const originalLoadTime = performance.now() - startTime;
// 启动加税流程 - Pass only originalLoadTime
startTaxProcess(originalLoadTime);
});
// 添加新的建墙小游戏函数
function createBuildWallGame() {
const gameContainer = document.createElement('div');
gameContainer.id = 'buildWallGame'; // Unique ID for this game
gameContainer.style.cssText = 'width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:space-around;background-color:#f0f0f0;border-radius:8px;padding:20px;box-sizing:border-box;text-align:center;user-select:none;position:relative;'; // Added position:relative for high score
let wallHeight = 0;
gameContainer.innerHTML = `
最高墙高: ${wallGameHighScore}米
🧱 建墙小游戏! 🧱
点击按钮,为伟大的数字边境添砖加瓦!
当前墙高: 0 米
🔨 建造! 🔨
`;
const buildBtn = gameContainer.querySelector('#buildWallBtn');
const wallVisual = gameContainer.querySelector('#wallVisual');
const heightCounter = gameContainer.querySelector('#wallHeightCounter');
const highScoreDisplay = gameContainer.querySelector('#wallGameHighScoreDisplay'); // Get high score display
buildBtn.addEventListener('click', () => {
wallHeight++;
heightCounter.textContent = wallHeight;
// --- ADDED: Check and update high score ---
if (wallHeight > wallGameHighScore) {
wallGameHighScore = wallHeight;
highScoreDisplay.textContent = `最高墙高: ${wallGameHighScore}米`;
GM_setValue('wallGameHighScore', wallGameHighScore);
}
// --- END ADDED ---
// Increase visual height (max height to prevent overflow)
const currentHeight = wallVisual.offsetHeight;
const maxHeight = gameContainer.offsetHeight * 0.5; // Limit wall height to 50% of container
if (currentHeight < maxHeight) {
wallVisual.style.height = `${currentHeight + 3}px`; // Increase height by 3px per click
}
// --- ADDED: Check for encouragement milestone ---
if (wallHeight > 0 && wallHeight % 10 === 0) {
showWallEncouragement(gameContainer); // Pass the game container
}
// --- END ADDED ---
// Button feedback
buildBtn.style.transform = 'scale(0.95)';
setTimeout(() => { buildBtn.style.transform = 'scale(1)'; }, 100);
});
buildBtn.addEventListener('mouseover', function() { this.style.backgroundColor = '#c53030'; });
buildBtn.addEventListener('mouseout', function() { this.style.backgroundColor = '#e53e3e'; });
return gameContainer;
}
// 鼓励语录
const wallEncouragements = [
"干得漂亮!继续建!",
"巨大的进步!MWGA!",
"墙更高了!非常好!",
"了不起的工作!",
"没有人比你建得更好!",
"非常坚固!非常强大!",
];
// 显示建墙鼓励的函数
function showWallEncouragement(container) {
// 移除旧的气泡(如果存在)
const oldBubble = container.querySelector('#wallEncouragementBubble');
if (oldBubble) {
oldBubble.remove();
}
const bubble = document.createElement('div');
bubble.id = 'wallEncouragementBubble';
const randomPhrase = wallEncouragements[Math.floor(Math.random() * wallEncouragements.length)];
const trumpImageUrl = 'https://www.helloimg.com/i/2025/04/26/680c5a216af82.png'; // Use the same Trump image
bubble.style.cssText = `
position: absolute;
/* top: 15px; */ /* Removed */
/* right: 15px; */ /* Removed */
bottom: 130px; /* Increased value to move higher above the button */
left: 50%; /* Center horizontally */
/* transform: translateX(-50%); */ /* Adjust for centering */
background-color: white;
border: 2px solid #cc0000;
border-radius: 10px;
padding: 8px 12px;
display: flex;
align-items: center;
box-shadow: 0 3px 8px rgba(0,0,0,0.2);
z-index: 10;
opacity: 0;
/* transform: scale(0.8); */ /* Use translate for initial state */
transform: translateX(-50%) translateY(10px); /* Start slightly lower */
transition: opacity 0.4s ease-out, transform 0.4s ease-out;
white-space: nowrap; /* Prevent text wrapping */
`;
bubble.innerHTML = `
${randomPhrase}
`;
container.appendChild(bubble);
// Force reflow for transition
void bubble.offsetWidth;
// Fade in and move up
bubble.style.opacity = '1';
// bubble.style.transform = 'scale(1)';
bubble.style.transform = 'translateX(-50%) translateY(0)';
// Set timeout to fade out and move down/remove
setTimeout(() => {
bubble.style.opacity = '0';
// bubble.style.transform = 'scale(0.8)';
bubble.style.transform = 'translateX(-50%) translateY(10px)';
setTimeout(() => {
if (bubble.parentNode) {
bubble.remove();
}
}, 400); // Wait for fade out transition
}, 2500); // Show for 2.5 seconds
}
// 启动独立的建墙小游戏
function launchStandaloneBuildWallGame() {
// 防止重复启动
if (document.getElementById('standaloneGameOverlay')) {
alert('另一个独立小游戏已经在运行中!');
return;
}
// 创建游戏容器覆盖层
const gameOverlay = document.createElement('div');
gameOverlay.id = 'standaloneGameOverlay'; // Use a generic ID for any standalone game overlay
gameOverlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,0.85);display:flex;flex-direction:column;justify-content:center;align-items:center;z-index:2147483647;';
// 创建游戏布局容器
const gameLayout = document.createElement('div');
gameLayout.style.cssText = 'background-color:white;border-radius:15px;padding:30px;box-shadow:0 5px 25px rgba(0,0,0,0.5);position:relative;max-width:90%;width:500px;min-height:550px; display: flex; flex-direction: column;'; // Increased min-height for timer
// 添加标题
const gameHeader = document.createElement('div');
gameHeader.style.cssText = 'text-align:center;margin-bottom:15px;'; // Reduced margin
gameHeader.innerHTML = `🧱 独立建墙小游戏 🧱 `;
gameLayout.appendChild(gameHeader);
// 添加计时器显示
const timerDisplay = document.createElement('div');
timerDisplay.id = 'wallGameTimer';
timerDisplay.style.cssText = 'text-align:center; font-size: 18px; color: #333; margin-bottom: 15px; font-weight: bold;';
timerDisplay.textContent = '剩余时间: 20 秒'; // Changed to 20 seconds
gameLayout.appendChild(timerDisplay);
// 创建并添加建墙游戏
const gameContainer = createBuildWallGame();
gameContainer.style.width = '100%'; // Adjust width
gameContainer.style.height = 'auto'; // Adjust height
gameContainer.style.flexGrow = '1'; // Allow it to take available space
gameContainer.style.border = '2px solid #e2e8f0'; // Add border like in tariff screen
gameLayout.appendChild(gameContainer);
// 关闭按钮
const closeButton = document.createElement('button');
closeButton.textContent = '✖ 关闭游戏';
closeButton.style.cssText = 'position:absolute;top:20px;right:20px;background:#cc0000;color:white;border:none;border-radius:5px;padding:8px 15px;cursor:pointer;font-weight:bold; z-index: 11;'; // Ensure button is above game elements if needed
closeButton.addEventListener('click', function() {
// endStandaloneWallGame(true); // Call end function with userCancelled = true
let currentHeight = 0;
const counter = gameContainer.querySelector('#wallHeightCounter');
if(counter) currentHeight = parseInt(counter.textContent);
endStandaloneWallGame(true, currentHeight);
});
gameLayout.appendChild(closeButton);
// 添加免责声明/提示
const disclaimer = document.createElement('div');
disclaimer.style.cssText = 'text-align:center;font-size:12px;color:#aaa;margin-top:15px;';
disclaimer.textContent = '独立游戏模式 - 在20秒内尽可能建高!'; // Updated text to 20s
gameLayout.appendChild(disclaimer);
// 组装并显示
gameOverlay.appendChild(gameLayout);
document.body.appendChild(gameOverlay);
// 添加键盘监听
document.addEventListener('keydown', handleWallGameKeyPress);
// --- TIMER LOGIC START ---
let timeLeft = 20; // Changed to 20 seconds
const buildBtn = gameContainer.querySelector('#buildWallBtn'); // Get build button
const countdownTimer = setInterval(() => {
timeLeft--;
timerDisplay.textContent = `剩余时间: ${timeLeft} 秒`;
if (timeLeft <= 0) {
clearInterval(countdownTimer);
timerDisplay.textContent = '时间到!';
if (buildBtn) {
buildBtn.disabled = true; // Disable button
buildBtn.style.backgroundColor = '#999';
buildBtn.textContent = '时间结束';
}
// 获取最终墙高
let finalHeight = 0;
const counter = gameContainer.querySelector('#wallHeightCounter');
if(counter) finalHeight = parseInt(counter.textContent);
// 延迟结束以显示"时间到"
setTimeout(() => {
endStandaloneWallGame(false, finalHeight);
}, 1000); // Wait 1 second before showing results
}
}, 1000);
// 将计时器ID存到Overlay上,以便清除
gameOverlay.countdownTimer = countdownTimer;
// --- TIMER LOGIC END ---
}
// 结束独立的建墙游戏
function endStandaloneWallGame(userCancelled, finalHeight) {
const gameOverlay = document.getElementById('standaloneGameOverlay');
if (!gameOverlay) return;
// 清除可能存在的计时器 (稍后添加)
if (gameOverlay.countdownTimer) {
clearInterval(gameOverlay.countdownTimer);
}
// 移除键盘事件监听器 (稍后添加)
document.removeEventListener('keydown', handleWallGameKeyPress);
// 渐隐效果
gameOverlay.style.transition = 'opacity 0.5s';
gameOverlay.style.opacity = '0';
setTimeout(() => {
gameOverlay.remove();
// 如果不是用户取消,显示结果
if (!userCancelled) {
showWallGameResults(finalHeight || 0); // Pass final height
}
}, 500);
}
// 显示建墙游戏结果
function showWallGameResults(height) {
const resultDiv = document.createElement('div');
resultDiv.style.cssText = 'position:fixed;top:50%;left:50%;transform:translate(-50%, -50%);background:white;border:3px solid #8d5524;border-radius:10px;padding:30px;box-shadow:0 5px 25px rgba(0,0,0,0.5);z-index:2147483647;text-align:center;min-width:320px;';
let message = '';
if (height >= 50) {
message = '一座宏伟的数字长城!WEB朗普为你骄傲!';
} else if (height >= 30) {
message = '干得不错!墙正在变得越来越高大!';
} else if (height >= 15) {
message = '继续努力,让数字边境固若金汤!';
} else {
message = '革命尚未成功,同志仍需努力建墙!';
}
resultDiv.innerHTML = `
时间到!
最终墙高: ${height} 米
${message}
再建一次
关闭
`;
document.body.appendChild(resultDiv);
// 添加按钮事件
document.getElementById('playWallAgainBtn').addEventListener('click', function() {
resultDiv.remove();
launchStandaloneBuildWallGame(); // Restart wall game
});
document.getElementById('closeWallResultBtn').addEventListener('click', function() {
resultDiv.remove();
});
// 30秒后自动关闭 (可选)
// setTimeout(() => { ... }, 30000);
}
// 独立的建墙游戏键盘处理
function handleWallGameKeyPress(e) {
if (e.key === 'Escape') {
// 获取当前墙高传递给结束函数
let currentHeight = 0;
const counter = document.getElementById('wallHeightCounter');
if(counter) currentHeight = parseInt(counter.textContent);
endStandaloneWallGame(true, currentHeight);
}
}
// 添加重置建墙最高记录的菜单
GM_registerMenuCommand('🧱 重置建墙最高记录', function() {
if (wallGameHighScore > 0) {
if (confirm(`确定要重置建墙最高记录吗?当前最高: ${wallGameHighScore}米`)) {
wallGameHighScore = 0; // Update local variable
GM_setValue('wallGameHighScore', 0); // Save to storage
alert('已重置建墙最高记录。');
// Optionally update display if game is running
const highScoreDisplay = document.querySelector('#buildWallGame #wallGameHighScoreDisplay');
if (highScoreDisplay) {
// Directly use the reset value (0) for display update
highScoreDisplay.textContent = `最高墙高: 0米`;
}
}
} else {
alert('建墙最高记录已经是0了。');
}
});
// 添加重置打朗普最高分的菜单
GM_registerMenuCommand('🎮 重置打朗普最高分', function() {
if (highScore > 0) {
if (confirm(`确定要重置打朗普最高分吗?当前最高: ${highScore} 点`)) {
highScore = 0;
GM_setValue('trumpGameHighScore', 0);
alert('已重置打朗普最高分。');
// Optionally update display if game is running
const highScoreDisplay = document.querySelector('#trumpGame #trumpGameHighScore');
if (highScoreDisplay) {
highScoreDisplay.textContent = `最高分: 0`;
}
}
} else {
alert('打朗普最高分已经是0了。');
}
});
// 添加设置清关失败概率的菜单
GM_registerMenuCommand('⚠️ 设置清关失败概率', function() {
const newRate = prompt(`请输入清关失败概率(0-100,如:5表示5%):\n\n当前值: ${clearanceFailRate}%`, clearanceFailRate);
if (newRate !== null && !isNaN(newRate) && newRate >= 0 && newRate <= 100) {
clearanceFailRate = parseFloat(newRate);
GM_setValue('clearanceFailRate', clearanceFailRate);
alert(`清关失败概率已设置为 ${clearanceFailRate}%`);
} else if (newRate !== null) {
alert('请输入0-100之间的有效数字');
}
});
// --- History Log Functions START ---
// Function to add entry to history log and save
function addHistoryEntry(entry) {
// Retrieve current history
let currentHistory = GM_getValue('tariffHistory', []);
// Add the new entry to the beginning
currentHistory.unshift(entry);
// Limit history size
if (currentHistory.length > MAX_HISTORY_ENTRIES) {
currentHistory = currentHistory.slice(0, MAX_HISTORY_ENTRIES); // Keep only the newest entries
}
// Save updated history
GM_setValue('tariffHistory', currentHistory);
}
// Function to display the tariff history log
function showHistoryLog() {
// Check if another overlay is already open
if (document.getElementById('historyLogOverlay')) {
alert('历史记录窗口已打开。');
return;
}
// Retrieve history
const history = GM_getValue('tariffHistory', []);
// Create overlay
const overlay = document.createElement('div');
overlay.id = 'historyLogOverlay';
overlay.style.cssText = `
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
background-color: rgba(0,0,0,0.85); display: flex;
justify-content: center; align-items: center; z-index: 2147483647;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
`;
// Create content container
const container = document.createElement('div');
container.style.cssText = `
background-color: white; border-radius: 10px; padding: 25px;
width: 90%; max-width: 800px; height: 80%; max-height: 600px;
box-shadow: 0 5px 25px rgba(0,0,0,0.5); display: flex; flex-direction: column;
`;
// Title
const title = document.createElement('h2');
title.textContent = '关税历史记录';
title.style.cssText = 'margin: 0 0 20px 0; text-align: center; color: #333;';
container.appendChild(title);
// History display area (scrollable)
const historyArea = document.createElement('div');
historyArea.style.cssText = 'flex-grow: 1; overflow-y: auto; border: 1px solid #eee; padding: 10px; margin-bottom: 20px; background-color: #f9f9f9;';
if (history.length === 0) {
historyArea.innerHTML = '暂无历史记录。
';
} else {
const table = document.createElement('table');
table.style.cssText = 'width: 100%; border-collapse: collapse; font-size: 13px;';
table.innerHTML = `
时间
URL
原始加载 (秒)
税率 (%)
关税后加载 (秒)
状态
`;
const tbody = table.querySelector('tbody');
history.forEach(entry => {
const row = document.createElement('tr');
row.style.borderBottom = '1px solid #eee';
const timestamp = new Date(entry.timestamp);
const formattedTime = timestamp.toLocaleString ? timestamp.toLocaleString() : entry.timestamp; // Basic formatting
let statusText = entry.status;
if (entry.status === 'Failure') {
statusText = `失败 ${entry.failReason ? ': ' + entry.failReason : ''}`;
} else if (entry.status === 'Success') {
statusText = `成功 `;
}
row.innerHTML = `
${formattedTime}
${entry.url.length > 40 ? entry.url.substring(0, 37) + '...' : entry.url}
${(entry.originalLoadTime / 1000).toFixed(2)}
${entry.taxRate}
${(entry.taxedLoadTime / 1000).toFixed(2)}
${statusText}
`;
tbody.appendChild(row);
});
historyArea.appendChild(table);
}
container.appendChild(historyArea);
// Buttons area
const buttonsDiv = document.createElement('div');
buttonsDiv.style.textAlign = 'center';
// Clear History Button
const clearBtn = document.createElement('button');
clearBtn.textContent = '清除历史记录';
clearBtn.style.cssText = 'background: #ff8a8a; color: white; border: none; border-radius: 5px; padding: 8px 15px; cursor: pointer; margin-right: 15px; font-weight: bold;';
clearBtn.onclick = () => {
if (confirm('确定要清除所有关税历史记录吗?此操作无法撤销。')) {
GM_setValue('tariffHistory', []); // Clear storage
historyArea.innerHTML = '历史记录已清除。
'; // Update display
clearBtn.disabled = true; // Disable button after clearing
}
};
if (history.length === 0) clearBtn.disabled = true; // Disable if no history initially
buttonsDiv.appendChild(clearBtn);
// Close Button
const closeBtn = document.createElement('button');
closeBtn.textContent = '关闭';
closeBtn.style.cssText = 'background: #666; color: white; border: none; border-radius: 5px; padding: 8px 15px; cursor: pointer; font-weight: bold;';
closeBtn.onclick = () => {
overlay.remove();
// Remove key listener when closing
document.removeEventListener('keydown', handleHistoryKeyPress);
};
buttonsDiv.appendChild(closeBtn);
container.appendChild(buttonsDiv);
// Append container to overlay and overlay to body
overlay.appendChild(container);
document.body.appendChild(overlay);
// Allow closing with Escape key
function handleHistoryKeyPress(e) {
if (e.key === 'Escape') {
overlay.remove();
document.removeEventListener('keydown', handleHistoryKeyPress);
}
}
document.addEventListener('keydown', handleHistoryKeyPress);
// Make overlay removable by clicking outside the box (optional)
overlay.addEventListener('click', (e) => {
if (e.target === overlay) {
overlay.remove();
document.removeEventListener('keydown', handleHistoryKeyPress);
}
});
}
// --- History Log Functions END ---
// --- History Log Menu START ---
GM_registerMenuCommand('📜 查看关税历史记录', showHistoryLog);
// --- History Log Menu END ---
})();
// --- History Log Functions START ---
// Function to add entry to history log and save
// ... existing code ...
// Function to display the tariff history log
// ... existing code ...
// --- History Log Functions END ---