// Floating Widget - 左下角和右下角浮动图片
(function() {
'use strict';
// JSON 数据接口
// 备用数据(接口失败时使用)
const FALLBACK_DATA = [
["11111.com.br", "bet3333","/img/bet.jpg"],
];
// 生成单个链接项 HTML
function generateItem(item) {
const domain = item[0];
const name = item[1];
const imgurl = item[2];
return `
`;
}
// 生成容器内容
function generateContainerHTML(items, side) {
return `
${items.map(item => generateItem(item)).join('')}
`;
}
function initWidget(data) {
// 确保body存在
if (!document.body) {
setTimeout(() => initWidget(data), 50);
return;
}
// // 左边取前4个,右边取后4个
// const leftData = data ? data.slice(0, 4) : [];
// const rightData = data ? data.slice(-4) : [];
// 最多取前 8 个
const limited = data.slice(0, 8);
// 计算中间点(向上取整保证左边多一个)
const mid = Math.ceil(limited.length / 2);
const leftData = data ? limited.slice(0, mid): [];
const rightData = data ? limited.slice(mid): [];
// 创建样式
const style = document.createElement('style');
style.id = 'fw-styles';
style.textContent = `
.fw-container {
position: fixed;
bottom: 20px;
z-index: 999999;
display: block;
animation: slideUp 0.5s ease-out;
}
@keyframes slideUp {
from {
transform: translateY(100px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
#fw-left {
left: 20px;
}
#fw-right {
right: 20px;
top: 50%;
transform: translateY(-50%);
bottom: auto;
}
.fw-close {
position: absolute;
top: -8px;
right: -8px;
width: 26px;
height: 26px;
background: #dc2626;
color: white;
border: 2px solid white;
border-radius: 50%;
cursor: pointer;
font-size: 14px;
font-weight: bold;
display: flex;
align-items: center;
justify-content: center;
z-index: 10;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
transition: all 0.3s;
}
.fw-close:active {
background: #b91c1c;
}
.fw-images {
display: flex;
gap: 12px;
}
.fw-col {
display: flex;
flex-direction: column;
gap: 12px;
}
.fw-img-item {
width: 110px;
height: 110px;
border-radius: 20px;
overflow: hidden;
cursor: pointer;
background: rgba(0, 0, 0, 0.1);
display: flex;
align-items: center;
justify-content: center;
position: relative;
text-decoration: none;
padding: 0;
box-sizing: border-box;
animation: fw-pulse 2s ease-in-out infinite;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2), 0 0 20px rgba(250, 204, 21, 0.3);
border: 3px solid rgba(250, 204, 21, 0.5);
}
@keyframes fw-pulse {
0%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
}
.fw-img-item::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
border-radius: 22px;
background: linear-gradient(45deg, #facc15, #22c55e, #facc15);
z-index: -1;
opacity: 0;
transition: opacity 0.3s;
}
.fw-img-item:hover::before {
opacity: 1;
}
.fw-img {
width: 100%;
height: 100%;
object-fit: contain;
object-position: center;
display: block;
}
@media (max-width: 768px) {
.fw-container {
bottom: 15px;
}
#fw-left {
left: 15px;
}
#fw-right {
right: 15px;
top: 50%;
transform: translateY(-50%);
bottom: auto;
}
.fw-img-item {
width: 80px;
height: 80px;
}
.fw-images {
gap: 8px;
}
.fw-col {
gap: 8px;
}
}
@media (max-width: 480px) {
.fw-container {
bottom: 10px;
}
#fw-left {
left: 10px;
}
#fw-right {
right: 10px;
top: 50%;
transform: translateY(-50%);
bottom: auto;
}
.fw-img-item {
width: 70px;
height: 70px;
}
.fw-images {
gap: 6px;
}
.fw-col {
gap: 6px;
}
.fw-close {
width: 20px;
height: 20px;
font-size: 12px;
}
}
`;
// 添加样式
if (!document.getElementById('fw-styles')) {
document.head.appendChild(style);
}
// 创建左下角容器 - 显示前4个
if (!document.getElementById('fw-left') && leftData.length > 0) {
const leftContainer = document.createElement('div');
leftContainer.id = 'fw-left';
leftContainer.className = 'fw-container';
leftContainer.innerHTML = generateContainerHTML(leftData, 'left');
document.body.appendChild(leftContainer);
// 左下角关闭按钮
const leftClose = leftContainer.querySelector('.fw-close');
if (leftClose) {
leftClose.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
leftContainer.style.display = 'none';
};
}
}
// 创建右下角容器 - 显示后4个
if (!document.getElementById('fw-right') && rightData.length > 0) {
const rightContainer = document.createElement('div');
rightContainer.id = 'fw-right';
rightContainer.className = 'fw-container';
rightContainer.innerHTML = generateContainerHTML(rightData, 'right');
document.body.appendChild(rightContainer);
// 右下角关闭按钮
const rightClose = rightContainer.querySelector('.fw-close');
if (rightClose) {
rightClose.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
rightContainer.style.display = 'none';
};
}
}
}
// 获取数据并初始化
function fetchAndInit() {
initWidget(FALLBACK_DATA);
}
// 多种方式初始化,确保能执行
if (document.readyState === 'complete' || document.readyState === 'interactive') {
fetchAndInit();
} else {
document.addEventListener('DOMContentLoaded', fetchAndInit);
}
// 备用初始化
window.addEventListener('load', fetchAndInit);
})();