XJTU ispace hack

使XJTU思源学习空间所有课件可下载

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         XJTU ispace hack
// @namespace    http://hack.xjtu.edu.cn/
// @version      0.4.2
// @description  使XJTU思源学习空间所有课件可下载
// @author       Noan
// @match        https://ispace.xjtu.edu.cn/*
// @match        http://ispace.xjtu.edu.cn/*
// @match        https://v-ispace.xjtu.edu.cn:*/*
// @match        http://v-ispace.xjtu.edu.cn:*/*
// @match        https://class.xjtu.edu.cn/*
// @match        http://class.xjtu.edu.cn/*
// @match        https://v-class.xjtu.edu.cn:*/*
// @match        http://v-class.xjtu.edu.cn:*/*
// @icon         https://ispace.xjtu.edu.cn/static/assets/images/favicon-b420ac72.ico
// @grant        none
// @license      GPL
// ==/UserScript==

(function() {
    'use strict';
    let original_XHR = window.XMLHttpRequest;

    class XMLHttpRequestHijacked extends original_XHR
    {
        override=false;
        hijack=false;
        type=-1;
        new_val={};
        set response(new_val)
        {
            this.override=true;
            this.new_val=new_val;
        }
        get response()
        {
            if(this.override)
            {
                return this.new_val;
            }
            else if(this.hijack)
            {
                if(this.type==0)
                {
                    let res=JSON.parse(super.response);
                    if(!("uploads" in res))
                    {
                        return super.response;
                    }
                    for(let i=0;i< res.uploads.length;i++)
                    {
                        if("allow_download"in res.uploads[i])
                        {
                            res.uploads[i].allow_download=true;
                        }
                    }
                    return JSON.stringify(res);
                }
                else if(this.type==1)
                {
                    let res=JSON.parse(super.response);
                    if(!("data" in res))
                    {
                        return super.response;
                    }
                    if("can_download"in res.data)
                    {
                        res.data.can_download=true;
                    }

                    return JSON.stringify(res);
                }
                else
                {
                    return super.response;
                }


            }
            else
            {
                return super.response;
            }
        }
        get responseText()
        {
            if(this.override || this.hijack)
            {
                return this.response;
            }
            else
            {
                return super.responseText;
            }

        }
        open(method, url, async=true, username, password)
        {
            if(url.search("api/activities")!=-1)
            {
                this.hijack=true;
                this.type=0;
            }
            else if(url.search("permissions")!=-1)
            {
                this.hijack=true;
                this.type=1;
            }
            let rescnt = super.open(method, url, async=true, username, password);
            return rescnt;
        }
    }

    window.XMLHttpRequest = XMLHttpRequestHijacked;
})();