copy_killer.js

删除网站复制时讨厌的声明 目前支持网站 Leetcode | CSDN

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         copy_killer.js
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  删除网站复制时讨厌的声明 目前支持网站 Leetcode | CSDN
// @author       wuuconix
// @match        https://leetcode-cn.com/problems/*
// @match        https://blog.csdn.net/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=leetcode-cn.com
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    document.addEventListener('copy',function(e){
        let clipboardData = e.clipboardData || window.clipboardData
        let text = clipboardData.getData("text") //剪切板里的内容 这时已经有讨厌的声明了
        if (text) { //这个不能不判断。有时候text为空,但是 Default事件会给它加东西。所以我们必须在text有值得时候才preventDefault
            let leetCodeReg = /来源:力扣(LeetCode)\n链接:[\s\S]*非商业转载请注明出处。/
            let csdnReg = /————————————————[\s\S]{2}版权声明:本文为CSDN博主[\s\S]*/
            if (text.match(leetCodeReg)) {
                console.log("检测到Leetcode声明")
                text = text.replace(leetCodeReg, "")
            } else if (text.match(csdnReg, "")) {
                console.log("检测到CSDN声明")
                text = text.replace(csdnReg, "")
            }
            e.preventDefault();
            text = text.trim() //删除复制内容头尾的空格,优化复制体验
            clipboardData.setData('text/plain', text)
        }
	})
})();