Unlock locked steps in Symbolab

unlocks locked symbolab step-by-step instructions by overwriting XMLHttpRequest

目前為 2020-10-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Unlock locked steps in Symbolab
// @namespace    http://*.symbolab.com/*
// @version      1.1
// @description  unlocks locked symbolab step-by-step instructions by overwriting XMLHttpRequest
// @author       joseph
// @match        *://*.symbolab.com/*
// @grant        none
// ==/UserScript==

(function(open) {
    
    var patched = 0;

    function patchResponseLoop(obj) {
        for (var k in obj)
        {
            if (typeof obj[k] == "object" && obj[k] !== null) {
                patchResponseLoop(obj[k]);
            } else {
                if (k == "isLocked") {
                    obj[k] = false;
                    console.log("[patcher] patched a symbolab isLocked property");
                    patched++;
                }
            }
        }
    }

    var open_prototype = XMLHttpRequest.prototype.open,
        intercept_response = function(urlpattern, callback) {
            XMLHttpRequest.prototype.open = function() {
                arguments['1'].match(urlpattern) && this.addEventListener('readystatechange', function(event) {
                    if ( this.readyState === 4 ) {
                        var response = callback(event.target.responseText);
                        // allow intercepted responses to be written to
                        Object.defineProperty(this, 'response', {writable: true});
                        Object.defineProperty(this, 'responseText', {writable: true});

                        this.response = this.responseText = response;
                    }
                });
                return open_prototype.apply(this, arguments);
            };
        };

    intercept_response(/steps/i, function(response) {
        console.log("[patcher] intercept request, current RES ", JSON.parse(response));

        var parsedO = JSON.parse(response);

        patchResponseLoop(parsedO);

        console.log("[patcher] === PATCHSET COMPLETE, enjoy ===");
        document.getElementById("PlotLink").innerHTML = "<b>Unlocked " + patched + " step(s)!</b>";

        return JSON.stringify(parsedO);
    });

})(XMLHttpRequest.prototype.open);