Greasy Fork is available in English.

YuketangHelper.hwlist.js

用于exam的整理与渲染

Detta skript bör inte installeras direkt. Det är ett bibliotek för andra skript att inkludera med meta-direktivet // @require https://update.greasyfork.org/scripts/521022/1504839/YuketangHelperhwlistjs.js

  1. chrome.runtime.sendMessage({ action: "fetchExam" }, (response) => {
  2. if (response.data) {
  3. const activities = response.data;
  4. const now = Date.now();
  5. const validActivities = activities.filter(activity => activity.deadline > now);
  6. validActivities.sort((a, b) => a.deadline - b.deadline);
  7. for (const activity of validActivities) {
  8. document.body.appendChild(renderActivity(activity));
  9. }
  10. } else {
  11. console.error('Failed to fetch data:', response.error);
  12. }
  13. });
  14.  
  15. function renderActivity(activity) {
  16. // link
  17. let link = `https://www.yuketang.cn/v2/web/exam/${activity.classroom_id}/${activity.courseware_id}`;
  18. if (activity.type === 4) {
  19. link = `https://www.yuketang.cn/v2/web/studentQuiz/${activity.courseware_id}/1`;
  20. }
  21. const linkBox = document.createElement('a');
  22. linkBox.href = link;
  23. linkBox.className = 'custom-link';
  24. linkBox.target = '_blank';
  25.  
  26. // 创建外层容器
  27. const contentBox = document.createElement('div');
  28. contentBox.className = 'content-box';
  29.  
  30. // 创建活动部分
  31. const section = document.createElement('section');
  32. section.className = 'activity__wrap el-tooltip';
  33. section.tabIndex = 0;
  34.  
  35. const activityInfo = document.createElement('div');
  36. activityInfo.className = 'activity-info';
  37.  
  38. // 创建标题部分
  39. const infoWrapper = document.createElement('div');
  40. const title = document.createElement('h2');
  41. title.textContent = activity.title + ' - ' + activity.course_name + '(' + activity.teacher_name + ')';
  42.  
  43. // 创建副标题部分
  44. const subInfo = document.createElement('div');
  45. subInfo.className = 'sub-info';
  46. const totalScore = `<span class="gray">满分:${activity.total_score}分</span>`;
  47. const problemCount = `<span class="gray beforeBorder">共${activity.problem_count}题</span>`;
  48. let limit = '';
  49. if (activity.limit) {
  50. limit = `<span class="gray beforeBorder">限时:${activity.limit / 60}分钟</span>`;
  51. }
  52. const deadline = `<span class="beforeBorder gray">截止时间:${formatDeadline(activity.deadline)}</span>`;
  53. subInfo.innerHTML = `${totalScore} ${problemCount} ${limit} ${deadline}`;
  54.  
  55. infoWrapper.appendChild(title);
  56. infoWrapper.appendChild(subInfo);
  57. activityInfo.appendChild(infoWrapper);
  58. section.appendChild(activityInfo);
  59. contentBox.appendChild(section);
  60.  
  61. linkBox.appendChild(contentBox);
  62. return linkBox;
  63. }
  64.  
  65. // 格式化截止时间
  66. function formatDeadline(deadlineTimestamp) {
  67. const date = new Date(deadlineTimestamp);
  68. const options = { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', weekday: 'short' };
  69. return date.toLocaleDateString('zh-CN', options).replace(/\//g, '/');
  70. }