BetterXes

优化学而思功能,美化学而思主题

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         BetterXes
// @namespace    https://github.com/wuyuhangxyz/BetterXes
// @version      0.0.1
// @description  优化学而思功能,美化学而思主题
// @author       吴宇航
// @license      GPL-3.0
// @run-at       document-start
// @match        https://code.xueersi.com/*
// @icon         https://code.xueersi.com/static/images/code-home/qrlogo.png
// @grant        none
// ==/UserScript==

// 部分代码来源于XesExt,特此鸣谢

function getSourceCode(){
    const href = window.location.href;
    const type = /langType=.+/.exec(href)[0].substring('langType='.length)
    const pid = /pid=[0-9]+/.exec(href)[0].substring('pid='.length)
    let url;
    if (type == "scratch"){
        url = `https://code.xueersi.com/scratch3/index.html?pid=${pid}&version=3.0&from=adapt&env=community`;
    }else{
        url = `https://code.xueersi.com/ide/code/${pid}?from=adapt`;
    }
    return url;
}
(function() {
    'use strict';
    window.addEventListener('load', () => {
        // 修改标题
        document.title = "BetterXes";

        // 源代码
        let adaptBtn = document.getElementsByClassName("adapt");
        adaptBtn = (adaptBtn.length == 1)?adaptBtn:document.getElementsByClassName("not-allow-adopt-con");
        if (adaptBtn.length == 1){
            adaptBtn[0].childNodes[0].className = 'never-adapt';
            adaptBtn[0].replaceWith(adaptBtn[0].cloneNode(true));
            adaptBtn[0].childNodes[1].data = ' 源代码 ';
            adaptBtn[0].addEventListener('click', (ev) => {
            window.open(getSourceCode());
            ev.preventDefault();
          });
        }

        // 去除运行频率限制
        const _setTimeout = window.setTimeout
        window.setTimeout = (code, delay, ...args) => {
          if (code.toString().includes('fnTryLockRun')) {
            code()
            return -1
          }
          return _setTimeout(code, delay, ...args)
        }
    });
})();