Restore Clipboard (剪贴板消毒)

Remove annoying copyright words on various Chinese sites

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Restore Clipboard (剪贴板消毒)
// @namespace    https://github.com/harryhare
// @version      0.5.0
// @description  Remove annoying copyright words on various Chinese sites
// @author       tysheng
// @license      GPL 3.0
// @icon         https://raw.githubusercontent.com/harryhare/userscript/master/index.png
// @match        https://*.zhihu.com/**
// @match        https://*.jianshu.com/**
// @match        https://*.douban.com/**
// @match        https://*.csdn.net/**
// @match        https://*.ftchinese.com/**
// @match        https://*.1point3acres.com/**
// @match        https://blog.skk.moe/**
// @match        https://www.bilibili.com/**
// @match        https://juejin.cn/**
// @match        https://*.nowcoder.com/**
// @match        https://*.mbalib.com/**
// @match        http://www.360doc.com/**
// @match        https://www.360doc.com/**
// @match        https://*.geekbang.org/**
// @match        https://xueqiu.com/**
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const siteHandlers = {
        douban: () => {
            document.querySelectorAll('div#link-report .note, div.review-content.clearfix')
                .forEach(el => el.oncopy = e => e.stopPropagation());
        },
        csdn: () => {
            document.querySelectorAll('div#article_content')
                .forEach(el => el.oncopy = e => e.stopPropagation());
        },
        xueqiu: () => {
            document.querySelectorAll('article.article__bd')
                .forEach(el => el.oncopy = e => e.stopPropagation());
        },
        juejin: () => {
            document.querySelectorAll('div.article-content div.markdown-body')
                .forEach(el => el.oncopy = e => e.stopPropagation());
        },
        doc360: () => {
            document.querySelectorAll('div.doc360article_content')
                .forEach(el => el.oncopy = e => e.stopPropagation());
        },
        bilibili: () => {
            document.querySelectorAll('div#article-content')
                .forEach(el => el.oncopy = e => e.stopPropagation());
        },
        geekbang: () => {
            let lastSelection, lastRanges = [], lastCopyFlag = false;

            document.onselectionchange = () => {
                if (lastCopyFlag) { lastCopyFlag = false; return; }
                const sel = window.getSelection();
                lastSelection = sel.toString();
                lastRanges = [];
                for (let i = 0; i < sel.rangeCount; i++) lastRanges.push(sel.getRangeAt(i));
            };

            document.body.oncopy = async (e) => {
                lastCopyFlag = true;
                const sel = window.getSelection();
                sel.removeAllRanges();
                lastRanges.forEach(r => sel.addRange(r));
            };
        }
    };

    const url = location.href;

    if (/https:\/\/[a-z]+\.douban\.com/.test(url)) siteHandlers.douban();
    else if (/https:\/\/[a-z]+\.csdn\.net/.test(url)) siteHandlers.csdn();
    else if (/https:\/\/xueqiu\.com/.test(url)) siteHandlers.xueqiu();
    else if (/https:\/\/[a-z]+\.bilibili\.com/.test(url)) siteHandlers.bilibili();
    else if (/https:\/\/juejin\.cn/.test(url)) siteHandlers.juejin();
    else if (/https?:\/\/www\.360doc\.com/.test(url)) siteHandlers.doc360();
    else if (/https:\/\/[a-z]+\.geekbang\.org/.test(url)) siteHandlers.geekbang();
    else {
        document.body.oncopy = e => e.stopPropagation();
    }
})();