UCAS 小助

UCAS sep网站助手

目前為 2023-12-11 提交的版本,檢視 最新版本

// ==UserScript==
// @name         UCAS 小助
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  UCAS sep网站助手
// @author       3hex
// @match        https://jwxk.ucas.ac.cn/evaluate/evaluateCourse/*
// @match        https://jwxk.ucas.ac.cn/evaluate/evaluateTeacher/*
// @match        https://v.ucas.ac.cn/course/getplaytitle.do?menuCode=*
// @icon         https://www.cas.cn/zj/yk/201410/W020141017344514407759.jpg
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const currentUrl = window.location.href;
    const regex1 = /^https:\/\/jwxk\.ucas\.ac\.cn\/evaluate\/.*?/;
    const regex2 = /^https:\/\/v\.ucas\.ac\.cn\/course\/getplaytitle\.do\?menuCode=.*?/;
    console.log("hi");
    document.addEventListener("DOMContentLoaded", function() {
        var video = document.getElementById('my_video_1_html5_api');
        if (video) {
            video.addEventListener('loadeddata', function() {
                var duration = this.duration; // 视频的总时长(秒)
                console.log('视频时长:' + duration + '秒');
            });
        } else {
            console.error('无法找到视频元素。');
        }
    });
    console.log("hi");

    // sep自动填写评价
    if (regex1.test(currentUrl)) {
        console.log('自动评价');
        document.querySelectorAll('input[type="radio"].required[value="5"]').forEach((el) => el.checked = true);
        Array.from(document.querySelectorAll('textarea')).forEach(el => { el.value = ' 无'; el.removeAttribute('minlength'); });
        document.querySelector('.required.radio').checked = true;document.querySelector('.required.checkbox').checked = true;
    }
    else if (regex2.test(currentUrl)) {
        console.log('实景课堂');

        var courseListDiv = document.querySelector('.b-courselist.m-coursebox');
        if (courseListDiv) {
            var ulElements = courseListDiv.querySelectorAll('ul');
            var hrefArray = [];

            ulElements.forEach(function(ulElement) {
                var liElements = ulElement.querySelectorAll('li:not([class])');
                liElements.forEach(function(liElement) {
                    var linkElement = liElement.querySelector('a');
                    if (linkElement && linkElement.href) {
                        hrefArray.push(linkElement.href);

                        if(linkElement.href == currentUrl || linkElement.href+"#link_href" == currentUrl)
                        {
                            liElement.style.backgroundColor = "yellow";
                            liElement.style.color = "black";
                        }
                    }
                });
            });

            // 获取当前 URL 在数组中前一个和后一个 URL
            var currentIndex = hrefArray.indexOf(currentUrl);
            var previousUrl = currentIndex < hrefArray.length - 1 ? hrefArray[currentIndex + 1] : null;
            var nextUrl = currentIndex > 0 ? hrefArray[currentIndex - 1] : null;

        } else {
            console.log('Course list div not found.');
        }

        var div = document.querySelector('.bc-play');
        if (div) {
            // 创建第一个a标签
            var link1 = document.createElement('a');
            if(previousUrl == null)
            {
                link1.href = '#';
                link1.style.color = 'red';   // 修改文字颜色为红色
                link1.textContent = ':)';
                link1.addEventListener('click', function(event) {
                    event.preventDefault(); // 阻止默认行为
                });
            }else
            {
                link1.href = previousUrl;
                link1.textContent = '上一个';
            }
            link1.style.padding = '10px'; // 添加内边距,使边框与文字之间有一定距离

            // 创建第二个a标签
            var link2 = document.createElement('a');
            if(nextUrl == null)
            {
                link2.href = '#';
                link2.textContent = ':)';
                link2.style.color = 'red';   // 修改文字颜色为红色
                link2.addEventListener('click', function(event) {
                    event.preventDefault(); // 阻止默认行为
                });
            }else
            {
                link2.href = nextUrl;
                link2.textContent = '下一个';
            }
            link2.style.padding = '10px'; // 添加内边距,使边框与文字之间有一定距离

            var link3 = document.createElement('a');
            link3.textContent = '居中 '+ (hrefArray.length-currentIndex) + "/" + hrefArray.length;
            link3.href = '#link_href';
            link3.style.padding = '10px'; // 添加内边距,使边框与文字之间有一定距离

            var regex = /code=([^&]+)/;
            var match = regex.exec(currentUrl);
            if (match) {
                var codeValue = match[1];
                console.log("code的属性值为:" + codeValue);
                var link4 = document.createElement('a');
                link4.textContent = '返回简介';
                link4.href = 'https://v.ucas.ac.cn/course/CourseIndex.do?menuCode=2&courseid='+codeValue;
                link4.style.padding = '10px'; // 添加内边距,使边框与文字之间有一定距离
            } else {
                console.log("未找到匹配的code属性值。");
            }

            // 在div的右边添加a标签
            var container = document.createElement('div');
            container.style.display = 'flex';
            container.style.flexDirection = 'column';
            container.style.alignItems = 'flex-end';
            container.style.position = 'absolute';
            container.style.top = '70%';
            container.style.right = '18%';
            container.style.transform = 'translateY(-50%)';
            container.appendChild(link4);
            container.appendChild(link3);
            container.appendChild(link1);
            container.appendChild(link2);

            div.appendChild(container);
        }
    }

    window.scrollTo(0, 230);
    var titleDiv = document.querySelector('.bc-h');
    if(titleDiv)
    {
        var link_href = document.createElement('a');
        link_href.name = 'link_href';
        titleDiv.appendChild(link_href);
    }


})();