OneClick Tools - Canvas Instructure

Copy/Google with a single click on all instructure.com quizzes/exam questions of your course.

当前为 2024-02-28 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         OneClick Tools - Canvas Instructure
// @namespace    https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
// @version      2
// @description  Copy/Google with a single click on all instructure.com quizzes/exam questions of your course.
// @author       hacker09
// @match        https://*.instructure.com/courses/*/quizzes/*
// @icon         https://du11hjcvx0uqb.cloudfront.net/br/dist/images/favicon-e10d657a73.ico
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  document.querySelectorAll(".text").forEach(el => { //forEach question
    el.style.cursor = "pointer"; //Change cursor style to pointer
    el.addEventListener('mouseup', function(event) { //When the mouse is clicked
      event.preventDefault(); //Prevent the default context menu from being opened
      var textToCopy = el.cloneNode(true); //Clone the question/answers
      textToCopy.querySelectorAll('.original_question_text, #question_input_1_statusbar, .ic-RichContentEditor, .tox-editor-header, style')?.forEach(editor => editor.remove()); //If existent, select elements to remove their text
      if (event.button === 0) { //If the user single clicks anywhere on the question/answer
        navigator.clipboard.writeText(textToCopy.innerText.replace(/(\r?\n\s*){2,}/g, '\n')); //Copy the text and question
      } else if (event.button === 2) { //If the user right clicks anywhere on the question/answer
        navigator.clipboard.writeText(el.querySelector(".question_text.user_content.enhanced").innerText); //Copy only the question
        open('https://www.google.com/search?q=' + encodeURIComponent(textToCopy.innerText.replace(/(\r?\n\s*){2,}/g, '\n'))); //Google the question and answer
      } //Finishes the else condition
    }); //Finishes the mouseup event listener
  }); //Finishes the forEach loop
})();