脚本功能
默认以悬浮窗的形式在页面右上角展示Genspark的积分使用量
脚本默认五分钟刷新一次,可以自己修改脚本刷新时间
因为是公司办公电脑的原因,截图有水印,就不给各位截图了
有热心佬友可以截图贴上来噢,谢谢了。
好用记得点赞哦
脚本内容
// ==UserScript==
// @name Genspark积分余量
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 在浮动窗口中显示Genspark积分余量信息
// @author LinuxDo 悟空
// @match https://www.genspark.ai/*
// @grant GM_xmlhttpRequest
// @connect www.genspark.ai
// ==/UserScript==
;(() => {
// 创建浮动窗口
const floatingWindow = document.createElement("div")
floatingWindow.id = "genspark-info-window"
floatingWindow.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background-color: #ffffff;
border: none;
border-radius: 10px;
padding: 12px;
z-index: 9999;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
width: 280px;
opacity: 0.2;
transition: all 0.3s ease;
cursor: move;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 14px;
`
// 创建浮动窗口的标题栏
const header = document.createElement("div")
header.style.cssText = `
padding: 8px 10px;
background-color: #f0f4f8;
border-radius: 6px;
margin-bottom: 12px;
font-weight: bold;
display: flex;
justify-content: space-between;
align-items: center;
color: #2c3e50;
`
header.textContent = "Genspark积分信息"
// 创建刷新按钮
const refreshButton = document.createElement("button")
refreshButton.textContent = "↻"
refreshButton.style.cssText = `
background: none;
border: none;
cursor: pointer;
font-size: 18px;
color: #3498db;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
transition: background-color 0.2s;
`
refreshButton.addEventListener("mouseover", () => {
refreshButton.style.backgroundColor = "#e8f4fc"
})
refreshButton.addEventListener("mouseout", () => {
refreshButton.style.backgroundColor = "transparent"
})
header.appendChild(refreshButton)
floatingWindow.appendChild(header)
// 创建内容容器
const content = document.createElement("div")
content.id = "genspark-info-content"
content.style.cssText = `
display: none;
line-height: 1.5;
color: #333;
`
floatingWindow.appendChild(content)
// 将浮动窗口添加到文档中
document.body.appendChild(floatingWindow)
// 使浮动窗口可拖动
let isDragging = false
let offsetX, offsetY
header.addEventListener("mousedown", (e) => {
isDragging = true
offsetX = e.clientX - floatingWindow.getBoundingClientRect().left
offsetY = e.clientY - floatingWindow.getBoundingClientRect().top
})
document.addEventListener("mousemove", (e) => {
if (isDragging) {
floatingWindow.style.left = e.clientX - offsetX + "px"
floatingWindow.style.top = e.clientY - offsetY + "px"
}
})
document.addEventListener("mouseup", () => {
isDragging = false
})
// 鼠标悬停时显示内容
floatingWindow.addEventListener("mouseenter", () => {
floatingWindow.style.opacity = "1"
floatingWindow.style.transform = "scale(1.02)"
content.style.display = "block"
})
floatingWindow.addEventListener("mouseleave", () => {
floatingWindow.style.opacity = "0.2"
floatingWindow.style.transform = "scale(1)"
content.style.display = "none"
})
// 获取账户信息的函数
function fetchAccountInfo() {
const now = new Date()
const endDate = new Date(now)
const startDate = new Date(now)
startDate.setMonth(startDate.getMonth() - 1)
const startDateStr = startDate.toISOString()
const endDateStr = endDate.toISOString()
const url = `https://www.genspark.ai/api/payment/get_credit_history?start_date=${startDateStr}&end_date=${endDateStr}`
GM_xmlhttpRequest({
method: "GET",
url: url,
headers: {
Accept: "*/*",
"Cache-Control": "no-cache",
},
onload: (response) => {
try {
const data = JSON.parse(response.responseText)
if (data.status === 0) {
updateContent(data.data)
} else {
content.innerHTML = '<div style="color: red;">错误: ' + data.message + "</div>"
}
} catch (error) {
content.innerHTML = '<div style="color: red;">解析响应时出错</div>'
console.error("解析响应时出错:", error)
}
},
onerror: (error) => {
content.innerHTML = '<div style="color: red;">获取数据时出错</div>'
console.error("获取数据时出错:", error)
},
})
}
// 更新内容的函数
function updateContent(data) {
// 格式化模型使用情况
let modelUsageHtml = ""
for (const model in data.model_usage) {
modelUsageHtml += `<div style="display: flex; justify-content: space-between; margin: 3px 0;">
<span style="color: #3498db;">${model}:</span>
<span style="font-weight: bold;">${data.model_usage[model]}</span>
</div>`
}
// 格式化查询时间段
const startTime = new Date(data.query_period.start_time).toLocaleString()
const endTime = new Date(data.query_period.end_time).toLocaleString()
content.innerHTML = `
<div style="margin-bottom: 12px; padding: 8px; background-color: #f8f9fa; border-radius: 6px;">
<strong style="color: #2c3e50;">当前余额:</strong> <span style="color: #27ae60; font-weight: bold;">${data.current_balance}</span>
</div>
<div style="margin-bottom: 12px; padding: 8px; background-color: #f8f9fa; border-radius: 6px;">
<strong style="color: #2c3e50;">套餐:</strong> <span style="text-transform: capitalize;">${data.plan}</span>
</div>
<div style="margin-bottom: 12px; padding: 8px; background-color: #f8f9fa; border-radius: 6px;">
<strong style="color: #2c3e50;">模型使用情况:</strong>
<div style="padding-left: 10px; margin-top: 5px;">${modelUsageHtml}</div>
</div>
<div style="padding: 8px; background-color: #f8f9fa; border-radius: 6px;">
<strong style="color: #2c3e50;">查询时间段:</strong>
<div style="padding-left: 10px; margin-top: 5px;">
<div><span style="color: #7f8c8d;">开始:</span> ${startTime}</div>
<div><span style="color: #7f8c8d;">结束:</span> ${endTime}</div>
</div>
</div>
`
}
// 初始获取
fetchAccountInfo()
// 点击刷新按钮时刷新
refreshButton.addEventListener("click", (e) => {
e.stopPropagation()
fetchAccountInfo()
})
// 每5分钟刷新一次
setInterval(fetchAccountInfo, 5 * 60 * 1000)
})()



