add choose fixed number
This commit is contained in:
parent
fb6e908382
commit
643840b120
352
whuF2caculate.js
352
whuF2caculate.js
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name 武大综测F2年度计算小工具
|
// @name 武大综测F2年度计算小工具
|
||||||
// @namespace whu
|
// @namespace whu
|
||||||
// @version 1.1
|
// @version 1.2
|
||||||
// @author game-loader
|
// @author game-loader
|
||||||
// @description 计算武大综测F2部分
|
// @description 计算武大综测F2部分
|
||||||
// @homepage https://github.com/game-loader
|
// @homepage https://github.com/game-loader
|
||||||
@ -9,187 +9,221 @@
|
|||||||
// @grant GM_xmlhttpRequest
|
// @grant GM_xmlhttpRequest
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
(function() {
|
(function () {
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
// 创建小窗口
|
// 创建小窗口
|
||||||
var container = document.createElement('div');
|
var container = document.createElement("div");
|
||||||
container.style.position = 'fixed';
|
container.style.position = "fixed";
|
||||||
container.style.top = '50%';
|
container.style.top = "50%";
|
||||||
container.style.right = '20%';
|
container.style.right = "20%";
|
||||||
container.style.transform = 'translate(50%, -50%)';
|
container.style.transform = "translate(50%, -50%)";
|
||||||
container.style.backgroundColor = '#ffffff';
|
container.style.backgroundColor = "#ffffff";
|
||||||
container.style.padding = '20px';
|
container.style.padding = "20px";
|
||||||
container.style.border = '1px solid #000000';
|
container.style.border = "1px solid #000000";
|
||||||
container.style.zIndex = '1000';
|
container.style.zIndex = "1000";
|
||||||
|
|
||||||
// 创建年份下拉框
|
// 创建年份下拉框
|
||||||
var yearSelect = document.createElement('select');
|
var yearSelect = document.createElement("select");
|
||||||
yearSelect.innerHTML = `
|
yearSelect.innerHTML = `
|
||||||
<option value="2021">2021</option>
|
<option value="2021">2021</option>
|
||||||
<option value="2022">2022</option>
|
<option value="2022">2022</option>
|
||||||
<option value="2023">2023</option>
|
<option value="2023">2023</option>
|
||||||
<option value="2024">2024</option>
|
<option value="2024">2024</option>
|
||||||
`;
|
`;
|
||||||
container.appendChild(yearSelect);
|
container.appendChild(yearSelect);
|
||||||
|
|
||||||
// 添加距离
|
// 添加距离
|
||||||
var spacer = document.createElement('div');
|
var spacer = document.createElement("div");
|
||||||
spacer.style.height = '10px';
|
spacer.style.height = "10px";
|
||||||
container.appendChild(spacer);
|
container.appendChild(spacer);
|
||||||
|
|
||||||
// 创建计算按钮
|
// 创建计算按钮
|
||||||
var calculateButton = document.createElement('button');
|
var calculateButton = document.createElement("button");
|
||||||
calculateButton.textContent = '计算综测F2';
|
calculateButton.textContent = "计算综测F2";
|
||||||
calculateButton.style.backgroundColor = '#5cb3cc';
|
calculateButton.style.backgroundColor = "#5cb3cc";
|
||||||
calculateButton.style.color = '#ffffff';
|
calculateButton.style.color = "#ffffff";
|
||||||
calculateButton.style.border = 'none';
|
calculateButton.style.border = "none";
|
||||||
calculateButton.style.borderRadius = '5px';
|
calculateButton.style.borderRadius = "5px";
|
||||||
calculateButton.style.padding = '8px 16px';
|
calculateButton.style.padding = "8px 16px";
|
||||||
calculateButton.style.boxShadow = '0px 2px 4px rgba(0, 0, 0, 0.4)';
|
calculateButton.style.boxShadow = "0px 2px 4px rgba(0, 0, 0, 0.4)";
|
||||||
container.appendChild(calculateButton);
|
container.appendChild(calculateButton);
|
||||||
|
|
||||||
// Create the query elective courses button
|
// Create the query elective courses button
|
||||||
var queryButton = document.createElement('button');
|
var queryButton = document.createElement("button");
|
||||||
queryButton.textContent = '查询选修课';
|
queryButton.textContent = "查询选修课";
|
||||||
queryButton.style.backgroundColor = '#5cb3cc';
|
queryButton.style.backgroundColor = "#5cb3cc";
|
||||||
queryButton.style.color = '#ffffff';
|
queryButton.style.color = "#ffffff";
|
||||||
queryButton.style.border = 'none';
|
queryButton.style.border = "none";
|
||||||
queryButton.style.borderRadius = '5px';
|
queryButton.style.borderRadius = "5px";
|
||||||
queryButton.style.padding = '8px 16px';
|
queryButton.style.padding = "8px 16px";
|
||||||
queryButton.style.boxShadow = '0px 2px 4px rgba(0, 0, 0, 0.4)';
|
queryButton.style.boxShadow = "0px 2px 4px rgba(0, 0, 0, 0.4)";
|
||||||
queryButton.style.marginLeft = '20px'; // Add space between the buttons
|
queryButton.style.marginLeft = "20px"; // Add space between the buttons
|
||||||
container.appendChild(queryButton);
|
container.appendChild(queryButton);
|
||||||
|
// 创建位数选择下拉框
|
||||||
|
var decimalSelect = document.createElement("select");
|
||||||
|
decimalSelect.innerHTML = `
|
||||||
|
<option value="2">2</option>
|
||||||
|
<option value="3">3</option>
|
||||||
|
<option value="4">4</option>
|
||||||
|
<option value="5">5</option>
|
||||||
|
`;
|
||||||
|
container.appendChild(decimalSelect);
|
||||||
|
|
||||||
// 将小窗口添加到页面中
|
// 添加提示文本
|
||||||
document.body.appendChild(container);
|
var decimalLabel = document.createElement("p");
|
||||||
|
decimalLabel.textContent = "选择保留的小数位数:";
|
||||||
|
container.insertBefore(decimalLabel, decimalSelect);
|
||||||
|
|
||||||
// 设置小窗口样式
|
// 将小窗口添加到页面中
|
||||||
container.style.width = '300px';
|
document.body.appendChild(container);
|
||||||
container.style.height = '200px';
|
|
||||||
container.style.overflow = 'auto';
|
|
||||||
|
|
||||||
// 获取gnmkdmKey的值
|
// 设置小窗口样式
|
||||||
var gnmkdmKey = document.getElementById('gnmkdmKey').value;
|
container.style.width = "300px";
|
||||||
|
container.style.height = "200px";
|
||||||
|
container.style.overflow = "auto";
|
||||||
|
|
||||||
// 构造请求URL和postData
|
// 获取gnmkdmKey的值
|
||||||
var url = 'https://jwgl.whu.edu.cn/cjcx/cjcx_cxXsgrcj.html';
|
var gnmkdmKey = document.getElementById("gnmkdmKey").value;
|
||||||
var params = 'doType=query&gnmkdm=' + encodeURIComponent(gnmkdmKey);
|
|
||||||
|
|
||||||
|
// 构造请求URL和postData
|
||||||
|
var url = "https://jwgl.whu.edu.cn/cjcx/cjcx_cxXsgrcj.html";
|
||||||
|
var params = "doType=query&gnmkdm=" + encodeURIComponent(gnmkdmKey);
|
||||||
|
|
||||||
// 最终请求URL
|
// 最终请求URL
|
||||||
var finalUrl = url + '?' + params;
|
var finalUrl = url + "?" + params;
|
||||||
|
|
||||||
// Bind click event to the query button
|
// Bind click event to the query button
|
||||||
queryButton.addEventListener('click', function() {
|
queryButton.addEventListener("click", function () {
|
||||||
var postData = 'xnm=' + yearSelect.value + '&xqm=&kcbj=&_search=false&nd=' + Date.now() + '&queryModel.showCount=50&queryModel.currentPage=1&queryModel.sortName=&queryModel.sortOrder=asc&time=0';
|
var postData =
|
||||||
// Perform the same POST request as the calculate button
|
"xnm=" +
|
||||||
// console.log(postData);
|
yearSelect.value +
|
||||||
GM_xmlhttpRequest({
|
"&xqm=&kcbj=&_search=false&nd=" +
|
||||||
method: 'POST',
|
Date.now() +
|
||||||
url: finalUrl,
|
"&queryModel.showCount=50&queryModel.currentPage=1&queryModel.sortName=&queryModel.sortOrder=asc&time=0";
|
||||||
headers: {
|
// Perform the same POST request as the calculate button
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
// console.log(postData);
|
||||||
},
|
GM_xmlhttpRequest({
|
||||||
data: postData,
|
method: "POST",
|
||||||
onload: function(response) {
|
url: finalUrl,
|
||||||
var responseData = JSON.parse(response.responseText);
|
headers: {
|
||||||
let items = responseData.items;
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
// console.log(items);
|
},
|
||||||
|
data: postData,
|
||||||
|
onload: function (response) {
|
||||||
|
var responseData = JSON.parse(response.responseText);
|
||||||
|
let items = responseData.items;
|
||||||
|
// console.log(items);
|
||||||
|
|
||||||
// Only consider items where kcxzmc includes "选修"
|
// Only consider items where kcxzmc includes "选修"
|
||||||
var electiveItems = items.filter((item) => {
|
var electiveItems = items.filter((item) => {
|
||||||
// console.log('item:', items[item]);
|
// console.log('item:', items[item]);
|
||||||
// console.log('kcxzmc:', items[item] && items[item].kcxzmc);
|
// console.log('kcxzmc:', items[item] && items[item].kcxzmc);
|
||||||
return item && items[item].kcxzmc && items[item].kcxzmc.includes("选修");
|
return (
|
||||||
});
|
item && items[item].kcxzmc && items[item].kcxzmc.includes("选修")
|
||||||
|
);
|
||||||
// Display these items in a list with checkboxes
|
|
||||||
var electiveList = document.createElement('ul');
|
|
||||||
electiveList.style.listStyleType = 'none';
|
|
||||||
electiveList.style.border = '1px solid black'; // Add border to the list
|
|
||||||
electiveList.style.padding = '10px'; // Add some padding
|
|
||||||
electiveList.style.marginTop = '20px'; // Add margin at the top
|
|
||||||
|
|
||||||
electiveItems.forEach(item => {
|
|
||||||
var listItem = document.createElement('li');
|
|
||||||
listItem.style.marginTop = '5px';
|
|
||||||
listItem.style.display = 'flex'; // Use flex layout
|
|
||||||
listItem.style.alignItems = 'center'; // Center-align items vertically
|
|
||||||
|
|
||||||
var checkbox = document.createElement('input');
|
|
||||||
checkbox.type = 'checkbox';
|
|
||||||
checkbox.value = item.kcmc;
|
|
||||||
checkbox.style.marginRight = '10px'; // Add some space between the checkbox and the label
|
|
||||||
listItem.appendChild(checkbox);
|
|
||||||
|
|
||||||
var label = document.createElement('label');
|
|
||||||
label.textContent = item.kcmc;
|
|
||||||
listItem.appendChild(label);
|
|
||||||
|
|
||||||
electiveList.appendChild(listItem);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add the list to the container
|
|
||||||
container.appendChild(electiveList);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Display these items in a list with checkboxes
|
||||||
|
var electiveList = document.createElement("ul");
|
||||||
|
electiveList.style.listStyleType = "none";
|
||||||
|
electiveList.style.border = "1px solid black"; // Add border to the list
|
||||||
|
electiveList.style.padding = "10px"; // Add some padding
|
||||||
|
electiveList.style.marginTop = "20px"; // Add margin at the top
|
||||||
|
|
||||||
|
electiveItems.forEach((item) => {
|
||||||
|
var listItem = document.createElement("li");
|
||||||
|
listItem.style.marginTop = "5px";
|
||||||
|
listItem.style.display = "flex"; // Use flex layout
|
||||||
|
listItem.style.alignItems = "center"; // Center-align items vertically
|
||||||
|
|
||||||
|
var checkbox = document.createElement("input");
|
||||||
|
checkbox.type = "checkbox";
|
||||||
|
checkbox.value = item.kcmc;
|
||||||
|
checkbox.style.marginRight = "10px"; // Add some space between the checkbox and the label
|
||||||
|
listItem.appendChild(checkbox);
|
||||||
|
|
||||||
|
var label = document.createElement("label");
|
||||||
|
label.textContent = item.kcmc;
|
||||||
|
listItem.appendChild(label);
|
||||||
|
|
||||||
|
electiveList.appendChild(listItem);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add the list to the container
|
||||||
|
container.appendChild(electiveList);
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 绑定按钮点击事件
|
||||||
|
calculateButton.addEventListener("click", function () {
|
||||||
|
let postData =
|
||||||
|
"xnm=" +
|
||||||
|
yearSelect.value +
|
||||||
|
"&xqm=&kcbj=&_search=false&nd=" +
|
||||||
|
Date.now() +
|
||||||
|
"&queryModel.showCount=70&queryModel.currentPage=1&queryModel.sortName=&queryModel.sortOrder=asc&time=0";
|
||||||
|
// 发送POST请求
|
||||||
|
GM_xmlhttpRequest({
|
||||||
|
method: "POST",
|
||||||
|
url: finalUrl,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
},
|
||||||
|
data: postData,
|
||||||
|
onload: function (response) {
|
||||||
|
var responseData = JSON.parse(response.responseText);
|
||||||
|
let items = responseData.items;
|
||||||
|
// console.log(items);
|
||||||
|
|
||||||
// 绑定按钮点击事件
|
// 创建变量用于存储必修成绩、选修成绩和必修学分
|
||||||
calculateButton.addEventListener('click', function() {
|
var requiredScore = 0;
|
||||||
|
var electiveScore = 0;
|
||||||
|
var requiredCredits = 0;
|
||||||
|
|
||||||
let postData = 'xnm=' + yearSelect.value + '&xqm=&kcbj=&_search=false&nd=' + Date.now() + '&queryModel.showCount=70&queryModel.currentPage=1&queryModel.sortName=&queryModel.sortOrder=asc&time=0';
|
// Get the selected elective courses
|
||||||
// 发送POST请求
|
var selectedElectives = Array.from(
|
||||||
GM_xmlhttpRequest({
|
container.querySelectorAll('input[type="checkbox"]:checked'),
|
||||||
method: 'POST',
|
).map((input) => input.value);
|
||||||
url: finalUrl,
|
// Iterate through each item in the items array
|
||||||
headers: {
|
for (var i = 0; i < items.length; i++) {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
var item = items[i];
|
||||||
},
|
var kcxzmc = item.kcxzmc;
|
||||||
data: postData,
|
var bfzcj = parseFloat(item.bfzcj);
|
||||||
onload: function(response) {
|
var xf = parseFloat(item.xf);
|
||||||
var responseData = JSON.parse(response.responseText);
|
|
||||||
let items = responseData.items;
|
|
||||||
// console.log(items);
|
|
||||||
|
|
||||||
// 创建变量用于存储必修成绩、选修成绩和必修学分
|
if (kcxzmc.includes("必修")) {
|
||||||
var requiredScore = 0;
|
requiredScore += bfzcj * xf;
|
||||||
var electiveScore = 0;
|
requiredCredits += xf;
|
||||||
var requiredCredits = 0;
|
} else if (kcxzmc.includes("选修")) {
|
||||||
|
if (selectedElectives.includes(item.kcmc)) {
|
||||||
|
// Treat the selected elective courses as required courses
|
||||||
|
requiredScore += bfzcj * xf;
|
||||||
|
requiredCredits += xf;
|
||||||
|
} else {
|
||||||
|
// Only consider the non-selected elective courses for the elective score
|
||||||
|
electiveScore += bfzcj * xf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the selected elective courses
|
// 计算必修课平均成绩和选修课成绩
|
||||||
var selectedElectives = Array.from(container.querySelectorAll('input[type="checkbox"]:checked')).map(input => input.value);
|
var requiredGrade = requiredScore / requiredCredits;
|
||||||
// Iterate through each item in the items array
|
var electiveGrade = electiveScore * 0.002;
|
||||||
for (var i = 0; i < items.length; i++) {
|
|
||||||
var item = items[i];
|
|
||||||
var kcxzmc = item.kcxzmc;
|
|
||||||
var bfzcj = parseFloat(item.bfzcj);
|
|
||||||
var xf = parseFloat(item.xf);
|
|
||||||
|
|
||||||
if (kcxzmc.includes("必修")) {
|
// 在窗口中显示结果
|
||||||
requiredScore += bfzcj * xf;
|
var resultElement = document.createElement("div");
|
||||||
requiredCredits += xf;
|
resultElement.style.marginTop = "10px";
|
||||||
} else if (kcxzmc.includes("选修")) {
|
resultElement.textContent =
|
||||||
if (selectedElectives.includes(item.kcmc)) {
|
"必修课: " +
|
||||||
// Treat the selected elective courses as required courses
|
requiredGrade.toFixed(decimalSelect.value) +
|
||||||
requiredScore += bfzcj * xf;
|
",选修课: " +
|
||||||
requiredCredits += xf;
|
electiveGrade.toFixed(decimalSelect.value) +
|
||||||
} else {
|
",总成绩:" +
|
||||||
// Only consider the non-selected elective courses for the elective score
|
(requiredGrade + electiveGrade).toFixed(decimalSelect.value);
|
||||||
electiveScore += bfzcj * xf;
|
container.appendChild(resultElement);
|
||||||
}
|
},
|
||||||
}
|
});
|
||||||
}
|
});
|
||||||
|
})();
|
||||||
// 计算必修课平均成绩和选修课成绩
|
|
||||||
var requiredGrade = requiredScore / requiredCredits;
|
|
||||||
var electiveGrade = electiveScore * 0.002;
|
|
||||||
|
|
||||||
// 在窗口中显示结果
|
|
||||||
var resultElement = document.createElement('div');
|
|
||||||
resultElement.style.marginTop = '10px';
|
|
||||||
resultElement.textContent = "必修课: " + requiredGrade.toFixed(3) + ",选修课: " + electiveGrade.toFixed(3)+",总成绩:"+(requiredGrade+electiveGrade).toFixed(3);
|
|
||||||
container.appendChild(resultElement);
|
|
||||||
}})})})();
|
|
||||||
|
Loading…
Reference in New Issue
Block a user