// ==UserScript== // @name 趣,不止想象 // @namespace http://tampermonkey.net/ // @version 1.0.0 // @description 巅峰趣味,加冕每一刻 // @author 半竹 // @match *://*/* // @grant none // ==/UserScript== (function () { 'use strict'; // 创建窗口元素 const windowDiv = document.createElement('div'); windowDiv.style.position = 'fixed'; windowDiv.style.top = '20px'; windowDiv.style.right = '20px'; windowDiv.style.width = '350px'; windowDiv.style.backgroundColor = '#fff'; windowDiv.style.border = '2px solid #007BFF'; windowDiv.style.padding = '15px'; windowDiv.style.zIndex = '9999'; windowDiv.style.borderRadius = '10px'; windowDiv.style.boxShadow = '0 4px 8px rgba(0, 0, 0, 0.2)'; // 创建标题元素,作为拖动区域 const title = document.createElement('h2'); title.textContent = '有趣的窗口'; title.style.backgroundColor = '#007BFF'; title.style.color = '#fff'; title.style.padding = '10px'; title.style.cursor = 'move'; title.style.borderRadius = '8px 8px 0 0'; title.style.margin = '-15px -15px 15px -15px'; windowDiv.appendChild(title); // 创建最小化按钮 const minimizeButton = document.createElement('button'); minimizeButton.textContent = '-'; minimizeButton.style.position = 'absolute'; minimizeButton.style.top = '10px'; minimizeButton.style.right = '30px'; minimizeButton.style.backgroundColor = 'transparent'; minimizeButton.style.border = 'none'; minimizeButton.style.color = '#fff'; minimizeButton.style.fontSize = '20px'; minimizeButton.style.cursor = 'pointer'; title.appendChild(minimizeButton); // 创建关闭按钮 const closeButton = document.createElement('button'); closeButton.textContent = '×'; closeButton.style.position = 'absolute'; closeButton.style.top = '10px'; closeButton.style.right = '10px'; closeButton.style.backgroundColor = 'transparent'; closeButton.style.border = 'none'; closeButton.style.color = '#fff'; closeButton.style.fontSize = '20px'; closeButton.style.cursor = 'pointer'; title.appendChild(closeButton); // 最小化功能 let isMinimized = false; minimizeButton.addEventListener('click', () => { if (isMinimized) { windowDiv.style.height = 'auto'; minimizeButton.textContent = '-'; } else { windowDiv.style.height = '40px'; minimizeButton.textContent = '+'; } isMinimized = !isMinimized; }); // 关闭功能 closeButton.addEventListener('click', () => { windowDiv.remove(); }); // 让窗口可移动 let isDragging = false; let offsetX, offsetY; title.addEventListener('mousedown', (e) => { isDragging = true; offsetX = e.clientX - windowDiv.offsetLeft; offsetY = e.clientY - windowDiv.offsetTop; }); document.addEventListener('mousemove', (e) => { if (isDragging) { windowDiv.style.left = (e.clientX - offsetX) + 'px'; windowDiv.style.top = (e.clientY - offsetY) + 'px'; } }); document.addEventListener('mouseup', () => { isDragging = false; }); // 励志语句数组 const motivationalQuotes = [ // 诗词(10 条) "会当凌绝顶,一览众山小。", "长风破浪会有时,直挂云帆济沧海。", "千磨万击还坚劲,任尔东西南北风。", "天生我材必有用,千金散尽还复来。", "老骥伏枥,志在千里。", "黄沙百战穿金甲,不破楼兰终不还。", "粉骨碎身浑不怕,要留清白在人间。", "不畏浮云遮望眼,自缘身在最高层。", "沉舟侧畔千帆过,病树前头万木春。", "纸上得来终觉浅,绝知此事要躬行。", // 网络励志语句(30 条) "努力只能及格,拼命才能优秀。", "生活原本沉闷,可跑起来就有风。", "人生没有白走的路,每一步都算数。", "你的坚持,终将美好。", "越努力,越幸运。", "自律给我自由。", "乾坤未定,你我皆是黑马。", "现在的努力,是为了以后有更多的选择。", "只要路是对的,就不怕路远。", "所有的逆袭,都是有备而来。", "每一次努力,都是成长的印记。", "别在最好的年纪,辜负了最好的自己。", "成功的路上并不拥挤,因为坚持的人不多。", "努力到无能为力,拼搏到感动自己。", "不逼自己一把,永远不知道自己有多优秀。", "你若盛开,蝴蝶自来。", "生活不会辜负每一个努力的人。", "奋斗是人生的底色。", "付出不一定有回报,但不付出一定没有回报。", "心有多大,舞台就有多大。", "每一次挫折,都是成长的机会。", "人生没有等出来的辉煌,只有走出来的美丽。", "坚持就是胜利。", "用汗水浇灌梦想,用拼搏铸就辉煌。", "未来的你,一定会感谢现在拼命的自己。", "别放弃,一步一步走下去,总会到达目的地。", "努力是奇迹的另一个名字。", "人生没有回头路,只有勇敢前行。", "每一次挑战,都是自我超越的契机。", "相信自己,你可以创造奇迹。", // 其他励志语句(60 条) "失败乃成功之母。", "成功源于不懈的努力。", "坚持到底,就是胜利。", "没有伞的孩子,必须努力奔跑。", "成功的关键在于行动。", "只有不断学习,才能不断进步。", "时间是最宝贵的财富。", "机会总是留给有准备的人。", "困难是成长的阶梯。", "微笑面对生活,生活也会对你微笑。", "积极的心态是成功的一半。", "自信是成功的第一秘诀。", "人生最大的敌人是自己。", "每一次跌倒,都是为了更好地站起来。", "成功需要勇气和毅力。", "生活的意义在于创造。", "目标是前进的动力。", "知识改变命运。", "只有经历风雨,才能见到彩虹。", "用热情拥抱生活,用行动追求梦想。", "成功是一种选择,努力是一种态度。", "不要害怕失败,只怕没有尝试。", "成长就是不断突破自我。", "每一次努力都是成长的积累。", "梦想是人生的指南针。", "成功的路上,耐心是关键。", "只要有梦想,就不怕路远。", "努力是实现梦想的桥梁。", "生活因奋斗而精彩。", "积极向上,方能成就自我。", "每一次挑战都是成长的机遇。", "坚持梦想,永不放弃。", "用汗水书写青春,用拼搏创造未来。", "成功属于那些敢于追梦的人。", "困难是暂时的,成功是永恒的。", "每一次挫折都是成长的磨砺。", "相信自己,无限可能。", "行动是治愈恐惧的良药。", "人生没有彩排,每天都是现场直播。", "努力是成功的基石。", "只有付出,才有收获。", "成功源于对目标的执着追求。", "微笑面对困难,困难也会望而却步。", "生活不会亏待每一个努力的灵魂。", "用奋斗诠释青春,用汗水铸就辉煌。", "每一次坚持都是胜利的前奏。", "成功的秘诀在于坚持和努力。", "积极的心态能战胜一切困难。", "人生就像一场马拉松,坚持到最后才是赢家。", "不要等待机会,要创造机会。", "成长是一场自我修行。", "每一次尝试都是成长的一步。", "梦想的实现需要脚踏实地的努力。", "成功需要付出代价,但值得。", "困难面前,勇往直前。", "用乐观的心态面对生活的挑战。", "每一次经历都是成长的财富。", "坚持就是对梦想的最好诠释。", "努力让自己变得更优秀。", "生活的美好源于不懈的追求。" ]; // 随机文本特效函数 const textStyles = [ 'color: #FF6347; font-size: 20px; font-weight: bold; text-shadow: 2px 2px 4px #ccc;', 'color: #20B2AA; font-size: 18px; font-style: italic; text-decoration: underline;', 'color: #FFD700; font-size: 22px; letter-spacing: 2px;', 'color: #9370DB; font-size: 19px; text-transform: uppercase;', 'color: #32CD32; font-size: 21px; line-height: 1.5; word-spacing: 3px;' ]; // 随机显示励志语句并应用特效函数 function showRandomQuote() { const randomQuoteIndex = Math.floor(Math.random() * motivationalQuotes.length); const randomStyleIndex = Math.floor(Math.random() * textStyles.length); quoteDiv.textContent = motivationalQuotes[randomQuoteIndex]; quoteDiv.style = textStyles[randomStyleIndex]; } // 创建励志语句显示区域 const quoteDiv = document.createElement('div'); quoteDiv.style.marginTop = '20px'; windowDiv.appendChild(quoteDiv); // 创建复制按钮 const copyButton = document.createElement('button'); copyButton.textContent = '复制励志语句'; copyButton.style.marginTop = '10px'; copyButton.style.padding = '8px'; copyButton.style.border = '1px solid #ccc'; copyButton.style.borderRadius = '5px'; copyButton.style.cursor = 'pointer'; windowDiv.appendChild(copyButton); // 复制功能 copyButton.addEventListener('click', () => { const textToCopy = quoteDiv.textContent; const textArea = document.createElement('textarea'); textArea.value = textToCopy; document.body.appendChild(textArea); textArea.select(); document.execCommand('copy'); document.body.removeChild(textArea); alert('励志语句已复制到剪贴板!'); }); // 页面加载时显示一条励志语句并应用特效 showRandomQuote(); // 设置定时自动更换励志语句 const changeIntervalInput = document.createElement('input'); changeIntervalInput.type = 'number'; changeIntervalInput.placeholder = '输入更换间隔秒数'; changeIntervalInput.style.marginTop = '15px'; changeIntervalInput.style.padding = '8px'; changeIntervalInput.style.border = '1px solid #ccc'; changeIntervalInput.style.borderRadius = '5px'; windowDiv.appendChild(changeIntervalInput); const startChangeButton = document.createElement('button'); startChangeButton.textContent = '开始定时更换'; startChangeButton.style.marginTop = '10px'; startChangeButton.style.padding = '8px'; startChangeButton.style.border = '1px solid #ccc'; startChangeButton.style.borderRadius = '5px'; startChangeButton.style.cursor = 'pointer'; windowDiv.appendChild(startChangeButton); const cancelChangeButton = document.createElement('button'); cancelChangeButton.textContent = '取消定时更换'; cancelChangeButton.style.marginTop = '10px'; cancelChangeButton.style.padding = '8px'; cancelChangeButton.style.border = '1px solid #ccc'; cancelChangeButton.style.borderRadius = '5px'; cancelChangeButton.style.cursor = 'pointer'; windowDiv.appendChild(cancelChangeButton); let changeIntervalId; startChangeButton.addEventListener('click', () => { const intervalSeconds = parseInt(changeIntervalInput.value); let seconds; if (isNaN(intervalSeconds) || intervalSeconds < 5) { seconds = 5; alert('更换间隔秒数至少为 5 秒,已自动设置为 5 秒。'); } else { seconds = intervalSeconds; } if (changeIntervalId) { clearInterval(changeIntervalId); } changeIntervalId = setInterval(showRandomQuote, seconds * 1000); }); cancelChangeButton.addEventListener('click', () => { if (changeIntervalId) { clearInterval(changeIntervalId); alert('定时更换已取消。'); } else { alert('当前没有正在进行的定时更换。'); } }); // 创建倒计时显示区域 const countdownDiv = document.createElement('div'); countdownDiv.style.marginTop = '20px'; windowDiv.appendChild(countdownDiv); // 创建输入框用于自定义倒计时时间 const timeInput = document.createElement('input'); timeInput.type = 'number'; timeInput.placeholder = '输入倒计时秒数'; timeInput.style.marginTop = '15px'; timeInput.style.padding = '8px'; timeInput.style.border = '1px solid #ccc'; timeInput.style.borderRadius = '5px'; windowDiv.appendChild(timeInput); // 倒计时结束提示音 const endSound = new Audio('https://example.com/end_sound.mp3'); // 倒计时函数 function startCountdown() { const inputSeconds = parseInt(timeInput.value); const seconds = isNaN(inputSeconds) ? 10 : inputSeconds; let remainingSeconds = seconds; const intervalId = setInterval(() => { if (remainingSeconds > 0) { countdownDiv.textContent = `倒计时: ${remainingSeconds} 秒`; remainingSeconds--; } else { clearInterval(intervalId); countdownDiv.textContent = '时间到!'; endSound.play(); } }, 1000); } // 创建按钮来启动倒计时 const countdownButton = document.createElement('button'); countdownButton.textContent = '启动倒计时'; countdownButton.style.marginTop = '15px'; countdownButton.style.marginLeft = '10px'; countdownButton.style.padding = '8px 15px'; countdownButton.style.border = 'none'; countdownButton.style.backgroundColor = '#007BFF'; countdownButton.style.color = 'white'; countdownButton.style.borderRadius = '5px'; countdownButton.style.cursor = 'pointer'; countdownButton.addEventListener('click', startCountdown); windowDiv.appendChild(countdownButton); // 创建按钮来更新每日一言并应用新特效 const updateQuoteButton = document.createElement('button'); updateQuoteButton.textContent = '更新每日一言'; updateQuoteButton.style.marginTop = '15px'; updateQuoteButton.style.marginLeft = '10px'; updateQuoteButton.style.padding = '8px 15px'; updateQuoteButton.style.border = 'none'; updateQuoteButton.style.backgroundColor = '#28a745'; updateQuoteButton.style.color = 'white'; updateQuoteButton.style.borderRadius = '5px'; updateQuoteButton.style.cursor = 'pointer'; updateQuoteButton.addEventListener('click', showRandomQuote); windowDiv.appendChild(updateQuoteButton); // 创建按钮来改变背景颜色 const colorButton = document.createElement('button'); colorButton.textContent = '换个颜色'; colorButton.style.marginTop = '15px'; colorButton.style.marginLeft = '10px'; colorButton.style.padding = '8px 15px'; colorButton.style.border = 'none'; colorButton.style.backgroundColor = '#dc3545'; colorButton.style.color = 'white'; colorButton.style.borderRadius = '5px'; colorButton.style.cursor = 'pointer'; colorButton.addEventListener('click', function () { const randomColor = '#' + Math.floor(Math.random() * 16777215).toString(16); windowDiv.style.backgroundColor = randomColor; }); windowDiv.appendChild(colorButton); // 生成随机数字并判断奇偶 const randomNumberDiv = document.createElement('div'); randomNumberDiv.style.marginTop = '20px'; windowDiv.appendChild(randomNumberDiv); function generateRandomNumber() { const randomNumber = Math.floor(Math.random() * 100); const parity = randomNumber % 2 === 0 ? '偶数' : '奇数'; randomNumberDiv.textContent = `随机数字: ${randomNumber},是 ${parity}`; } const randomNumberButton = document.createElement('button'); randomNumberButton.textContent = '生成随机数字'; randomNumberButton.style.marginTop = '15px'; randomNumberButton.style.padding = '8px 15px'; randomNumberButton.style.border = 'none'; randomNumberButton.style.backgroundColor = '#17a2b8'; randomNumberButton.style.color = 'white'; randomNumberButton.style.borderRadius = '5px'; randomNumberButton.style.cursor = 'pointer'; randomNumberButton.addEventListener('click', generateRandomNumber); windowDiv.appendChild(randomNumberButton); // 显示当前时间 const timeDiv = document.createElement('div'); timeDiv.style.marginTop = '20px'; windowDiv.appendChild(timeDiv); function updateTime() { const now = new Date(); const timeString = now.toLocaleTimeString(); timeDiv.textContent = `当前时间: ${timeString}`; } setInterval(updateTime, 1000); updateTime(); // 随机生成颜色代码并显示 const colorCodeDiv = document.createElement('div'); colorCodeDiv.style.marginTop = '20px'; windowDiv.appendChild(colorCodeDiv); function generateRandomColorCode() { const randomColor = '#' + Math.floor(Math.random() * 16777215).toString(16); colorCodeDiv.textContent = `随机颜色代码: ${randomColor}`; colorCodeDiv.style.color = randomColor; } const colorCodeButton = document.createElement('button'); colorCodeButton.textContent = '生成随机颜色代码'; colorCodeButton.style.marginTop = '15px'; colorCodeButton.style.padding = '8px 15px'; colorCodeButton.style.border = 'none'; colorCodeButton.style.backgroundColor = '#6f42c1'; colorCodeButton.style.color = 'white'; colorCodeButton.style.borderRadius = '5px'; colorCodeButton.style.cursor = 'pointer'; colorCodeButton.addEventListener('click', generateRandomColorCode); windowDiv.appendChild(colorCodeButton); // 猜数字游戏 const guessNumberDiv = document.createElement('div'); guessNumberDiv.style.marginTop = '20px'; windowDiv.appendChild(guessNumberDiv); const guessInput = document.createElement('input'); guessInput.type = 'number'; guessInput.placeholder = '输入 1 - 100 的数字'; guessInput.style.marginTop = '15px'; guessInput.style.padding = '8px'; guessInput.style.border = '1px solid #ccc'; guessInput.style.borderRadius = '5px'; windowDiv.appendChild(guessInput); let secretNumber = Math.floor(Math.random() * 100) + 1; let attempts = 0; function checkGuess() { const userGuess = parseInt(guessInput.value); attempts++; if (isNaN(userGuess) || userGuess < 1 || userGuess > 100) { guessNumberDiv.textContent = '请输入 1 - 100 之间的有效数字。'; } else if (userGuess < secretNumber) { guessNumberDiv.textContent = '猜的数字太小了,再试试!'; } else if (userGuess > secretNumber) { guessNumberDiv.textContent = '猜的数字太大了,再试试!'; } else { guessNumberDiv.textContent = `恭喜你,猜对了!你用了 ${attempts} 次尝试。`; guessInput.disabled = true; } } const guessButton = document.createElement('button'); guessButton.textContent = '猜数字'; guessButton.style.marginTop = '15px'; guessButton.style.marginLeft = '10px'; guessButton.style.padding = '8px 15px'; guessButton.style.border = 'none'; guessButton.style.backgroundColor = '#fd7e14'; guessButton.style.color = 'white'; guessButton.style.borderRadius = '5px'; guessButton.style.cursor = 'pointer'; guessButton.addEventListener('click', checkGuess); windowDiv.appendChild(guessButton); // 新增:掷骰子游戏 const diceDiv = document.createElement('div'); diceDiv.style.marginTop = '20px'; windowDiv.appendChild(diceDiv); function rollDice() { const diceResult = Math.floor(Math.random() * 6) + 1; diceDiv.textContent = `你掷出了: ${diceResult}`; } const diceButton = document.createElement('button'); diceButton.textContent = '掷骰子'; diceButton.style.marginTop = '15px'; diceButton.style.padding = '8px 15px'; diceButton.style.border = 'none'; diceButton.style.backgroundColor = '#ffc107'; diceButton.style.color = 'white'; diceButton.style.borderRadius = '5px'; diceButton.style.cursor = 'pointer'; diceButton.addEventListener('click', rollDice); windowDiv.appendChild(diceButton); // 新增:生成随机字母 const randomLetterDiv = document.createElement('div'); randomLetterDiv.style.marginTop = '20px'; windowDiv.appendChild(randomLetterDiv); function generateRandomLetter() { const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; const randomIndex = Math.floor(Math.random() * alphabet.length); const randomLetter = alphabet[randomIndex]; randomLetterDiv.textContent = `随机字母: ${randomLetter}`; } const randomLetterButton = document.createElement('button'); randomLetterButton.textContent = '生成随机字母'; randomLetterButton.style.marginTop = '15px'; randomLetterButton.style.padding = '8px 15px'; randomLetterButton.style.border = 'none'; randomLetterButton.style.backgroundColor = '#198754'; randomLetterButton.style.color = 'white'; randomLetterButton.style.borderRadius = '5px'; randomLetterButton.style.cursor = 'pointer'; randomLetterButton.addEventListener('click', generateRandomLetter); windowDiv.appendChild(randomLetterButton); // 新增:全部恢复默认值 function restoreDefaults() { windowDiv.style.backgroundColor = '#fff'; showRandomQuote(); countdownDiv.textContent = ''; timeInput.value = ''; randomNumberDiv.textContent = ''; colorCodeDiv.textContent = ''; guessNumberDiv.textContent = ''; guessInput.value = ''; guessInput.disabled = false; secretNumber = Math.floor(Math.random() * 100) + 1; attempts = 0; diceDiv.textContent = ''; randomLetterDiv.textContent = ''; if (changeIntervalId) { clearInterval(changeIntervalId); changeIntervalId = null; } } const restoreButton = document.createElement('button'); restoreButton.textContent = '全部恢复默认值'; restoreButton.style.marginTop = '15px'; restoreButton.style.padding = '8px 15px'; restoreButton.style.border = 'none'; restoreButton.style.backgroundColor = '#dc3545'; restoreButton.style.color = 'white'; restoreButton.style.borderRadius = '5px'; restoreButton.style.cursor = 'pointer'; restoreButton.addEventListener('click', restoreDefaults); windowDiv.appendChild(restoreButton); // 将窗口添加到页面 document.body.appendChild(windowDiv); })();