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

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

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 or Violentmonkey 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         🔥净化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);
})();