diff --git a/README.md b/README.md index 5137dd2..30d6487 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,10 @@ # tempermonkey_scripts +这个仓库放了一下我写的油猴脚本小工具 不定时更新 有问题请发邮件联系我 +matthew.mcfarland@dartmouth.edu + +## 计算武大综测F2的小工具 -## Getting started -To make it easy for you to get started with GitLab, here's a list of recommended next steps. -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.com/game-loader/tempermonkey_scripts.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.com/game-loader/tempermonkey_scripts/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/whuF2caculate.js b/whuF2caculate.js index 1b95738..dfa27c1 100644 --- a/whuF2caculate.js +++ b/whuF2caculate.js @@ -1,7 +1,7 @@ // ==UserScript== // @name 武大综测F2年度计算小工具 // @namespace whu -// @version 1.0 +// @version 1.1 // @author game-loader // @description 计算武大综测F2部分 // @homepage https://github.com/game-loader @@ -41,7 +41,7 @@ // 创建计算按钮 var calculateButton = document.createElement('button'); calculateButton.textContent = '计算综测F2'; - calculateButton.style.backgroundColor = '#8ae68a'; + calculateButton.style.backgroundColor = '#5cb3cc'; calculateButton.style.color = '#ffffff'; calculateButton.style.border = 'none'; calculateButton.style.borderRadius = '5px'; @@ -49,6 +49,18 @@ calculateButton.style.boxShadow = '0px 2px 4px rgba(0, 0, 0, 0.4)'; container.appendChild(calculateButton); + // Create the query elective courses button + var queryButton = document.createElement('button'); + queryButton.textContent = '查询选修课'; + queryButton.style.backgroundColor = '#5cb3cc'; + queryButton.style.color = '#ffffff'; + queryButton.style.border = 'none'; + queryButton.style.borderRadius = '5px'; + queryButton.style.padding = '8px 16px'; + queryButton.style.boxShadow = '0px 2px 4px rgba(0, 0, 0, 0.4)'; + queryButton.style.marginLeft = '20px'; // Add space between the buttons + container.appendChild(queryButton); + // 将小窗口添加到页面中 document.body.appendChild(container); @@ -57,78 +69,125 @@ container.style.height = '200px'; container.style.overflow = 'auto'; - // 绑定按钮点击事件 - calculateButton.addEventListener('click', function() { - // 获取gnmkdmKey的值 - var gnmkdmKey = document.getElementById('gnmkdmKey').value; + // 获取gnmkdmKey的值 + var gnmkdmKey = document.getElementById('gnmkdmKey').value; // 构造请求URL和postData - var url = 'https://jwgl.whu.edu.cn/cjcx/cjcx_cxXsgrcj.html'; - var params = 'doType=query&gnmkdm=' + encodeURIComponent(gnmkdmKey); - var postData = 'xnm=' + yearSelect.value + '&xqm=&kcbj=&_search=false&nd=' + Date.now() + '&queryModel.showCount=15&queryModel.currentPage=1&queryModel.sortName=&queryModel.sortOrder=asc&time=0'; + var url = 'https://jwgl.whu.edu.cn/cjcx/cjcx_cxXsgrcj.html'; + var params = 'doType=query&gnmkdm=' + encodeURIComponent(gnmkdmKey); + // 最终请求URL - var finalUrl = url + '?' + params; + var finalUrl = url + '?' + params; + // Bind click event to the query button + 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'; + // Perform the same POST request as the calculate button + // console.log(postData); + 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); + + // Only consider items where kcxzmc includes "选修" + var electiveItems = items.filter((item) => { + 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); + } + }); +}); + + + // 绑定按钮点击事件 + 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); - var items = responseData.items; + 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); - // 创建变量用于存储必修成绩、选修成绩和必修学分 -var requiredScore = 0; -var electiveScore = 0; -var requiredCredits = 0; + // 创建变量用于存储必修成绩、选修成绩和必修学分 + var requiredScore = 0; + var electiveScore = 0; + var requiredCredits = 0; -// 遍历数组中的各项 -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); + // Get the selected elective courses + var selectedElectives = Array.from(container.querySelectorAll('input[type="checkbox"]:checked')).map(input => input.value); + // Iterate through each item in the items array + 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; - requiredCredits += xf; - } else if (kcxzmc.includes("选修")) { - electiveScore += bfzcj * xf; - } -} + if (kcxzmc.includes("必修")) { + requiredScore += bfzcj * xf; + requiredCredits += xf; + } 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; + } + } + } -// 在窗口中显示成绩 -var requiredGrade = requiredScore / requiredCredits; -var electiveGrade = electiveScore * 0.002; -var totalGrade = requiredGrade + electiveGrade; + // 计算必修课平均成绩和选修课成绩 + var requiredGrade = requiredScore / requiredCredits; + var electiveGrade = electiveScore * 0.002; -// 创建显示结果的元素 -var resultElement = document.createElement('div'); -resultElement.style.marginTop = '10px'; - -// 创建必修课成绩显示行 -var requiredGradeElement = document.createElement('div'); -requiredGradeElement.textContent = "必修课:" + requiredGrade.toFixed(2); -resultElement.appendChild(requiredGradeElement); - -// 创建选修课成绩显示行 -var electiveGradeElement = document.createElement('div'); -electiveGradeElement.textContent = "选修课:" + electiveGrade.toFixed(2); -resultElement.appendChild(electiveGradeElement); - -// 创建F2成绩显示行 -var totalGradeElement = document.createElement('div'); -totalGradeElement.textContent = "F2:" + totalGrade.toFixed(2); -resultElement.appendChild(totalGradeElement); - -// 在按钮下方显示结果 -container.appendChild(resultElement); - } -}); - }); -})(); + // 在窗口中显示结果 + var resultElement = document.createElement('div'); + resultElement.style.marginTop = '10px'; + resultElement.textContent = "必修课: " + requiredGrade.toFixed(3) + ",选修课: " + electiveGrade.toFixed(3)+",总成绩:"+(requiredGrade+electiveGrade).toFixed(3); + container.appendChild(resultElement); +}})})})();