copy_killer.js

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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)
        }
	})
})();