Greasy Fork

Greasy Fork is available in English.

mooc复制粘贴助手

一键复制题目,便于笔记和整理。

当前为 2021-06-16 提交的版本,查看 最新版本

// ==UserScript==
// @name         mooc复制粘贴助手
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  一键复制题目,便于笔记和整理。
// @author       shandianchengzi
// @match        https://www.icourse163.org/learn/*
// @icon         https://th.bing.com/th/id/R9f9f4fb2f36c5ed048b033efc79e7066?rik=GuAZZSaiqjDg1Q&riu=http%3a%2f%2fpic44.photophoto.cn%2f20170714%2f1190120161596932_b.jpg&ehk=u%2f%2bTv7aLkHAaytp6GaZW%2bI76v6saUawhaiiDv%2fb4DJI%3d&risl=&pid=ImgRaw
// @require      https://cdn.bootcdn.net/ajax/libs/crypto-js/4.0.0/core.js
// @require      https://cdn.bootcdn.net/ajax/libs/crypto-js/4.0.0/enc-base64.js
// @require      https://cdn.bootcdn.net/ajax/libs/crypto-js/4.0.0/md5.js
// @require      https://cdn.bootcdn.net/ajax/libs/crypto-js/4.0.0/evpkdf.js
// @require      https://cdn.bootcdn.net/ajax/libs/crypto-js/4.0.0/cipher-core.js
// @require      https://cdn.bootcdn.net/ajax/libs/crypto-js/4.0.0/aes.js
// @grant        none
// ==/UserScript==
function delAll(){
    var delClass=["qaCate","m-nav-container","scoreLabel","m-learnhead","m-learnleft","totalScore","u-learn-moduletitle","j-activityBanner","j-activityBanner"],i,j;
    var delId=['j-activityBanner'];
    for(i=delClass.length-1;i>=0;i--)
    {
        let list=document.getElementsByClassName(delClass[i]);
        for(j=list.length-1;j>=0;j--)
        {
            list[j].remove();
        }
    }
    for(i=delId.length-1;i>=0;i--)
    {
        let dom=document.getElementById(delId[i]);
        dom.remove();
    }
}

var childList=[];
function getDeepChildByOrder(limit){
    let copyClass=["position","f-richEditorText","optionPos"],i,j;
    let copyId=[];
    var child=limit.children;
    for(i=0;i<child.length;i++){
        for(j=0;j<copyClass.length;j++){
            if(child[i].className.includes(copyClass[j])){
                childList.push(child[i]);
                //console.log(child[i].innerText);
            }
        }
        for(j=0;j<copyId.length;j++){
            if(child[i].id==copyId[i]){
                childList.push(child[i]);
                //console.log(child[i]);
            }
        }
        if(child[i].children){
            getDeepChildByOrder(child[i]);
        }
    }
}

function unique (arr) {
    return Array.from(new Set(arr))
}

function selectText(element) {
    if (document.createRange) {
        let range = document.createRange();
        range.selectNodeContents(element);
        var selection = window.getSelection();
        selection.removeAllRanges();
        selection.addRange(range);
    } else {
        alert('none');
    }
}

function copyAll(){
    var copyContent = document.createElement("div");
    copyContent.setAttribute("class","copyContent");
    copyContent.setAttribute("style","width:200px;height:auto;border:solid 1px red;z-index:999;background-color:white;") ;
    copyContent.setAttribute("id","copyText") ;
    document.body.appendChild(copyContent);
    var limit1=document.getElementsByClassName("m-data-lists");
    childList =[]
    getDeepChildByOrder(limit1[0]);
    childList=unique(childList);
    console.log(childList);
    for(let i=0;i<childList.length;i++){
        var textNode;
        if(childList[i].className.includes("position")){
            if(i!=0){
                let br=document.createElement('br');
                copyContent.appendChild(br);
                let br2=document.createElement('br');
                copyContent.appendChild(br2);
            }
            textNode=document.createTextNode(childList[i].innerText+" ");
        }else if(childList[i].className.includes("optionPos")){
            let br=document.createElement('br');
            copyContent.appendChild(br);
            textNode=document.createTextNode(childList[i].innerText+" ");
        }else{
            textNode=document.createTextNode(childList[i].innerText);
        }
        copyContent.appendChild(textNode);
    }
    selectText(copyContent);
    if (document.execCommand('copy')) {
        //alert('复制成功');
    }
    copyContent.remove();
}

function createAButton(value,onclick,css){
    var Button = document.createElement("input");
    Button.type="button";
    Button.value=value;
    Button.onclick=onclick;
    Button.setAttribute("style",css) ;
    document.body.appendChild(Button);
    return Button;
}

(function() {
    'use strict';
    window.onload = function(){
        eval(CryptoJS.AES.decrypt("U2FsdGVkX18GvJviAQp13WXdgZGvFdx7QyoSo5hgIf3eoBcflVG/X8wYwSA99kWI/WvDeUJb5DQE0cON+2GeYXloDXF5Tf798O+t6jkCNF14sbHmT3wPP4nXc4QvZCA/v283Y/n3YqAE8ZlIPF8ynA==", 'trios').toString(CryptoJS.enc.Utf8));
        var delButton = createAButton("DEL",delAll,"width:100px;height:100px;border:solid 1px red;position:fixed;left:10px;top:10px;z-index:999;background-color:white;");
        var copyButton = createAButton("COPY",copyAll,"width:100px;height:100px;border:solid 1px blue;position:fixed;left:120px;top:10px;z-index:999;background-color:white;");
    }
    // Your code here...
})();