Greasy Fork

🧰蓝墨云工具箱 Mosoteach Toolkit

让蓝墨云更加强大、易用!Make Mosoteach more powerfull & user-friendly !

当前为 2019-06-24 提交的版本,查看 最新版本

// ==UserScript==
// @name         🧰蓝墨云工具箱 Mosoteach Toolkit
// @namespace    http://github.com/ellean/
// @version      0.1
// @description  让蓝墨云更加强大、易用!Make Mosoteach more powerfull & user-friendly !
// @author       Younntone
// @match        https://www.mosoteach.cn/web/index.php?c=interaction_quiz&m=person_quiz_result&clazz_course_id=*&order_item=group
// @match        https://www.mosoteach.cn/web/index.php?c=interaction&m=index&clazz_course_id=*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  /**
   * * 通用方法
   * 用于截取 url 中所需要的参数
   * @param name 参数名
   * @param url
   * */

  function getQueryString(name, url) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = url.match(reg);
    if (r != null) {
      return unescape(r[2]);
    }
    return null;
  }

  // 获取 当前页面
  let location = getQueryString('m', window.location.search);

  // 判断 当前页面
  if (location === 'index') {
    /**
     * *---------------------------------------*
     * * 为 已结束 的 测试活动 添加直接查看分析的按钮 *
     * *---------------------------------------*
     */

    // 获取 课程 id
    let clazzCourseId = getQueryString(
      'clazz_course_id',
      window.location.search,
    );

    // 获取 活动节点集合
    let activities = $('.interaction-row');

    // 判断 每个活动节点是否为测试
    for (let index = 0; index < activities.length; index++) {
      const activity = activities[index];
      const activityType = activity.getAttribute('data-type');
      const quizStatus = activity.children[1].children[0].children[0].className;
      // 如果 是测试并且已经结束
      if (activityType === 'QUIZ' && quizStatus === 'interaction-status end') {
        // 添加 直接打开分析页面的按钮
        let urlWithId = activity.getAttribute('data-url');
        let id = getQueryString('id', urlWithId);
        let url = `https://www.mosoteach.cn/web/index.php?c=interaction_quiz&m=person_quiz_result&clazz_course_id=${clazzCourseId}&id=${id}&order_item=group`;
        let button = document.createElement('div');
        button.className = 'interaction-status processing';
        button.innerText = '习题分析';
        button.addEventListener('click', () => {
          window.open(url);
          event.stopPropagation();
        });
        activity.children[1].children[0].appendChild(button);
      }
    }
  } else {
    /**
     * *-------------------------------------*
     * * 为 测试分析 添加导出全部题目到粘贴板的按钮 *
     * *-------------------------------------*
     */

    const quizTitle = $('.manager-active-name-length')[0].innerText;
    const quizCollection = $('.view-quiz-row');
    // const quizAnswerCollection
    var quizList = [];

    // 获取 所有题目
    for (let quizIndex = 0; quizIndex < quizCollection.length; quizIndex++) {
      const quiz = quizCollection[quizIndex];
      const num =
        quiz.children[0].children[0].children[0].children[0].innerHTML;
      const question =
        quiz.children[0].children[0].children[0].children[1].children[2]
          .children[0].innerText;
      const optionCount =
        quiz.children[0].children[0].children[2].childElementCount;
      let options = [];

      // 获取 该题所有选项
      for (let optionIndex = 0; optionIndex < optionCount; optionIndex++) {
        const optionMark =
          quiz.children[0].children[0].children[2].children[optionIndex]
            .children[0].innerText;
        const option =
          quiz.children[0].children[0].children[2].children[optionIndex]
            .children[2].innerText;
        options.push(`
      ${optionMark}. ${option}`);
      }

      // 获取 答案
      let answer =
        quiz.children[1].children[0].children[0].children[1].innerText;

      quizList.push(`


    ${num}. ${question}  ${answer}
    ${options}`);
    }

    // 整理内容
    var detail = `题目标题: ${quizTitle}
题目总数: ${quizCollection.length}
题目: ${quizList}
`;

    // 创建 按钮节点
    var copyButton = document.createElement('button');
    copyButton.innerHTML = '导出该测试';
    copyButton.style = `
    width: 100px;
    height: 50px;
    position: fixed;
    top: 400px;
    left: 30px;
    background-color: #EC6941B0;
    `;
    copyButton.addEventListener('click', function() {
      var oInput = document.createElement('textarea');
      oInput.value = detail;
      document.body.appendChild(oInput);
      oInput.select();
      document.execCommand('Copy');
      oInput.className = 'oInput';
      oInput.style.display = 'none';
      alert('已复制到粘贴板');
    });

    // 挂载 按钮节点
    document.body.appendChild(copyButton);
  }
})();