Greasy Fork is available in English.
在你的浏览器上添加文学社所有女生的Q版形象
当前为
// ==UserScript==
// @name 文学社在看着你👀
// @namespace https://world.xiaomawang.com/w/person/project/all/3267489
// @version 1.0
// @description 在你的浏览器上添加文学社所有女生的Q版形象
// @author 茶铭
// @match *://*/*
// @icon https://ddlc.moe/images/favicon.ico
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
const imageUrls = [
"https://ddlc.moe/images/sticker_s.png",
"https://ddlc.moe/images/sticker_y.png",
"https://ddlc.moe/images/sticker_m.png",
"https://ddlc.moe/images/sticker_n.png"
];
const images = [];
const imagePositions = [];
function createImage(url, x) {
const img = document.createElement('img');
img.src = url;
img.style.position = 'fixed';
img.style.bottom = '0';
img.style.left = `${x}px`;
img.style.zIndex = '9999';
document.body.appendChild(img);
return img;
}
function jumpAnimation(img) {
const jumpHeight = 70;
const jumpDuration = Math.floor(Math.random() * 70) + 240; // 随机跳跃持续时间
img.animate([
{ transform: 'translateY(0)', },
{ transform: `translateY(-${jumpHeight}px)`, },
{ transform: 'translateY(0)', }
], {
duration: jumpDuration,
easing: 'ease-in-out',
iterations: 1
});
}
function checkOverlap(x) {
for (let i = 0; i < imagePositions.length; i++) {
const position = imagePositions[i];
if (Math.abs(x - position) <= 100) { // 根据图片宽度调整重叠阈值
return true;
}
}
return false;
}
function generateRandomX() {
let x = Math.floor(Math.random() * (window.innerWidth - 100)); // 根据图片宽度调整
while (checkOverlap(x)) {
x = Math.floor(Math.random() * (window.innerWidth - 100));
}
return x;
}
function startJumpAnimation() {
const randomIndex = Math.floor(Math.random() * images.length);
jumpAnimation(images[randomIndex]);
const randomInterval = Math.floor(Math.random() * 3000) + 3000; // 3~6 秒的间隔
setTimeout(startJumpAnimation, randomInterval);
}
function toggleImagesVisibility() {
images.forEach(img => {
img.style.display = img.style.display === 'none' ? 'block' : 'none';
});
}
window.addEventListener('load', () => {
imageUrls.forEach((url, index) => {
const x = generateRandomX();
const img = createImage(url, x);
images.push(img);
imagePositions.push(x);
});
startJumpAnimation();
document.addEventListener('keydown', event => {
if (event.key === 'n' || event.key === 'N') {
toggleImagesVisibility();
}
});
});
})();