Greasy Fork is available in English.
Fetch and display exam archive list from Zhixueyun in a popup
当前为
// ==UserScript==
// @name 网大知识中心成绩获取
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Fetch and display exam archive list from Zhixueyun in a popup
// @author Your Name
// @match https://kc.zhixueyun.com/*
// @grant none
// @run-at document-end
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// 添加弹窗的HTML到页面
const popupHTML = `
<div id="my-custom-popup" style="
position: fixed;
top: 10px;
right: 10px;
width: 300px;
background-color: white;
border: 1px solid #000;
padding: 10px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
z-index: 9999;
max-height: 500px;
overflow: auto;
display: none; /* 默认不显示 */
">
<div style="
text-align: right;
cursor: pointer;
font-weight: bold;
margin-bottom: 5px;
" onclick="document.getElementById('my-custom-popup').style.display='none'">关闭</div>
<div id="my-custom-content">数据加载中...</div>
</div>
`;
document.body.insertAdjacentHTML('beforeend', popupHTML);
// 从localStorage获取token信息
const tokenString = localStorage.getItem('token');
if (tokenString) {
const tokenObject = JSON.parse(tokenString);
const accessToken = tokenObject.access_token; // 提取access_token
// 设置请求头
const headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9",
"Authorization": "Bearer__" + accessToken, // 使用从localStorage获取的access_token
"Connection": "keep-alive",
"Host": "kc.zhixueyun.com",
"Referer": "https://kc.zhixueyun.com/",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
"sec-ch-ua": '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "Windows"
};
const url = "https://kc.zhixueyun.com/api/v1/exam/exam/front/archivr-list?startTime=1672502400000&endTime=1704038399999&page=1&pageSize=10";
// 发送请求
fetch(url, { headers: headers })
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok.');
}
return response.json(); // 解析JSON数据
})
.then(data => {
let content = '';
if (data && data.items) {
data.items.forEach(item => {
const name = item.name;
const score = item.examRecord ? item.examRecord.score : 'No score';
content += `<p>${name}: ${score}</p>`;
});
} else {
content = '没有项目显示。';
}
document.getElementById('my-custom-content').innerHTML = content;
// 显示弹窗
document.getElementById('my-custom-popup').style.display = 'block';
})
.catch(error => {
document.getElementById('my-custom-content').innerHTML = '获取数据失败。';
console.error('Failed to fetch data:', error);
});
} else {
document.getElementById('my-custom-content').innerHTML = '未找到token。';
console.error('No token found in localStorage');
}
})();