Greasy Fork

Greasy Fork is available in English.

leetcode助手

去除leetcode上烦人的复制小尾巴|自动开启差别比对(搬运自symant233作者的Beautify插件,对其功能进行了精简)。

当前为 2022-01-19 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         leetcode助手
// @namespace    com.zhaolei
// @require      https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js
// @version      0.2
// @description  去除leetcode上烦人的复制小尾巴|自动开启差别比对(搬运自symant233作者的Beautify插件,对其功能进行了精简)。
// @author       zhaolei
// @match        *://leetcode-cn.com/*
// @icon         https://www.google.com/s2/favicons?domain=tampermonkey.net
// @license      GPL-3.0
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    if (!$) { var $ = window.jQuery; }
    // 监听复制事件
    function listeningCopyEvent() {
        self.addEventListener('copy', (e) => {
            const selection = document.getSelection()
            if (selection.anchorNode) {
                // 阻止复制的默认事件
                e.preventDefault()
                // 把文本设置到剪切板中
                e.clipboardData.setData('text', selection.toString())
            }
        })
    }
    listeningCopyEvent()
    // 自动开启运行差别
    function enableDiff () {
        const btn = document.querySelector('label[class*="Label-StyledSwitch"]');
        if (btn && !btn.getAttribute('beautify-data')) {
            btn.setAttribute('beautify-data', true);
            btn.click();
        }
    }
    setTimeout(() => {
        $('div[class*=second-section-container] > div:last-child button').click();
        new Promise(resolve => {
            const container = document.querySelector('div[class*="CodeAreaContainer"]');
            if (container) {
                new MutationObserver((mutationList) => {
                    mutationList.forEach((mutation) => {
                        if (mutation.oldValue) enableDiff();
                    });
                }).observe(container, {
                    attributes: true,
                    attributeOldValue: true,
                    subtree: true,
                });
            }
            resolve();
        });
    }, 2600);
})();