🔥净化LeetCode复制内容、自动开启差别对比🔥

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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.toString() !== "") {
                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);
})();