// ==UserScript== // @license MIT // @name AIGC春联 // @namespace http://tampermonkey.net/ // @version 2024-01-27 // @description A AIGC couplet // @author Sincenir // @match *://*/* // @icon https://www.google.com/s2/favicons?sz=64&domain=undefined. // @grant GM_addStyle // @require https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js // @downloadURL https://update.greasyfork.icu/scripts/485698/AIGC%E6%98%A5%E8%81%94.user.js // @updateURL https://update.greasyfork.icu/scripts/485698/AIGC%E6%98%A5%E8%81%94.meta.js // ==/UserScript== (function () { "use strict"; GM_addStyle(`@keyframes horizontal-expand { 0% { transform: scaleX(0) translateX(-50%); } 100% { transform: scaleX(1) translateX(-50%); } } @keyframes vertical-expand { 0% { transform: scaleY(0) translateY(-50%); } 100% { transform: scaleY(1) translateY(-50%); } } @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } @keyframes hide { 0% { opacity: 1; } 30% { opacity: 0; } 100% { opacity: 0; } } .couplet-container { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; pointer-events: none; font-family: "楷体", "宋体", "Microsoft YaHei", sans-serif; font-size: 32px; font-weight: 700; color: #fec401; z-index: 1000000000; } .top { position: absolute; top: 5%; left: 50%; transform: translateX(-50%); transform-origin: left; width: 200px; height: auto; padding: 16px 24px; background-color: #ca3a2a; text-align: center; overflow: hidden; white-space: nowrap; animation: horizontal-expand 1s ease-in-out; box-shadow: 0 0 0 6px #ff664d; border-radius: 8px; } .top::before { content: ""; position: absolute; top: 10px; left: 16px; right: 16px; bottom: 10px; border: 4px solid #f3dab8; border-radius: 8px; } .couplet-all { position: absolute; top: 50%; transform: translateY(-50%); width: auto; height: auto; padding: 32px 24px; background-color: #ca3a2a; writing-mode: vertical-rl; text-align: center; overflow: hidden; white-space: nowrap; animation: vertical-expand 1s ease-in-out; box-shadow: 0 0 0 6px #ff664d; border-radius: 8px; } .couplet-all::before { content: ""; position: absolute; top: 16px; left: 10px; right: 10px; bottom: 16px; border: 4px solid #f3dab8; border-radius: 8px; } .couplet-up { transform-origin: top; right: 5%; } .couplet-down { transform-origin: top; left: 5%; } .couplet-fu { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; animation: spin 1s ease; } .hide { animation: hide 3s ease-in-out; }`); const showTime = 10000; const coupletList = [ { up: "龙飞凤舞春盈四海", down: "岁稔年丰福满九州", top: "四海同春", }, { up: "龙骧盛世财源广进", down: "岁稔新春福运亨通", top: "盛世财源", }, { up: "龙舞云天开新运财如泉涌", down: "春回大地展宏图福满人间", top: "龙运亨通", }, { up: "龙年百福临喜气祥和户户", down: "春风万里送欢歌笑语声声", top: "迎春接福", }, { up: "龙腾盛世展宏图业兴财旺", down: "春满神州添锦绣福寿安康", top: "大展鸿图", }, { up: "龙年百福临喜气祥和户户", down: "春风万里送欢歌笑语声声", top: "迎春接福", }, { up: "龙征万里", down: "福满乾坤", top: "万里乾坤福", }, ]; function createCoupletContainer() { const container = document.createElement("div"); container.className = "couplet-container"; return container; } function createTop(str) { const topEl = document.createElement("div"); topEl.innerHTML = str; topEl.className = "top"; return topEl; } function createUp(str) { const upEl = document.createElement("div"); upEl.className = "couplet-all couplet-up"; upEl.innerHTML = str; return upEl; } function createDown(str) { const down = document.createElement("div"); down.className = "couplet-all couplet-down"; down.innerHTML = str; return down; } function createFu() { const fu = document.createElement("div"); fu.className = "couplet-fu"; fu.innerHTML = ''; return fu; } const coupletContainer = createCoupletContainer(); function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; } const c = coupletList[getRandomInt(0, coupletList.length - 1)]; const top = createTop(c.top); const up = createUp(c.up); const down = createDown(c.down); const fu = createFu(); coupletContainer.append(top); coupletContainer.append(up); coupletContainer.append(down); coupletContainer.append(fu); document.body.append(coupletContainer); setTimeout(() => { document.querySelector(".couplet-container").className = "couplet-container hide"; setTimeout(() => { document.querySelector(".couplet-container").remove(); }, 1000); }, showTime); document.addEventListener("keydown", (e) => { if (e.key !== "Escape") return; document.querySelector(".couplet-container").className = "couplet-container hide"; setTimeout(() => { document.querySelector(".couplet-container").remove(); }, 1000); }); })();