玩转CSDN

仅供参考学习

2021-09-06 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         玩转CSDN
// @namespace    http://tampermonkey.net/
// @version      0.1000
// @match        *://blog.csdn.net/*
// @icon         https://source.unsplash.com/random
// @description  仅供参考学习
// @author       wwwbh
// @icon         https://www.google.com/s2/favicons?domain=csdn.net
// @grant        none
// ==/UserScript==
 
(function() {
    'use strict';
    function copy(signElem) {
        let codeelem = null;
        try{
            codeelem = signElem.parentNode;
            if(codeelem.id.indexOf('code')===-1){
                throw new EvalError('value error',lineNumber=22);
            }
        }catch(err){
            codeelem = signElem.previousSibling;
        }
        document.oncopy=function(e){
            e.clipboardData.setData('text',codeelem.innerText);
            e.preventDefault();
            document.oncopy=null;
        }
        document.execCommand("Copy");
        signElem.setAttribute('data-title','复制成功');
        signElem.style.cssText += 'background-color: green';
        setTimeout(()=>{
            signElem.setAttribute('data-title','点击复制');
            signElem.style.removeProperty('background-color','green');
        },1000);
    };
 
    let codes = document.querySelectorAll('#content_views pre code');
    let signs = document.querySelectorAll('.signin');
    for(var i=0;i<codes.length;i++){
        let sign = signs[i];
        codes[i].removeAttribute('onclick');
        codes[i].style.setProperty('user-select','auto');
        codes[i].setAttribute('id','code-'+i);
        codes[i].parentNode.style.setProperty('user-select','auto');
        sign.removeAttribute('onclick');
        sign.setAttribute('data-title','点击复制');
        sign.removeAttribute('data-report-click');
        sign.setAttribute('data-clipboard-action','copy');
        sign.setAttribute('aria-label','copied!');
        sign.setAttribute('data-clipboard-target','#code-'+i);
        sign.addEventListener('click', function(){
            copy(this);
        },'true');
    };
})();