CSDN,CNBLOG博客文章一键转载插件

CSDN博客文章转载插件 可以实现CSDN上的文章一键转载

目前為 2019-07-31 提交的版本,檢視 最新版本

// ==UserScript==
// @name         CSDN,CNBLOG博客文章一键转载插件 
// @version      2.30
// @description  CSDN博客文章转载插件 可以实现CSDN上的文章一键转载
// @author       By Jackie http://csdn.admans.cn/
// @match        *://blog.csdn.net/*/article/details/*
// @match        *://mp.csdn.net/postedit*
// @match        *://www.cnblogs.com/*/p/*.html
// @match        *://www.cnblogs.com/*/articles/*.html
// @match        *://i.cnblogs.com/EditArticles.aspx?opt=1
// @match        *://i.cnblogs.com/EditPosts.aspx?opt=1
// @require      https://unpkg.com/turndown/dist/turndown.js
// @grant    GM_addStyle
// @namespace https://gf.qytechs.cn/users/164689
// ==/UserScript==

GM_addStyle("#ReproduceBtn{position: absolute;float: right;right: 0px;width: auto;background: #0f962191;z-index: 99;color: white;text-align: center;margin: 5px;padding: 5px;border-radius: 5px;cursor: pointer;}"); 
(function(){
        'use strict';
         //document.domain="csdn.net";  
          var cnblog=location.href.indexOf("cnblogs.com") > -1?true:false;
          if(cnblog)
          {
            document.domain="cnblogs.com";    
          }
          else
          {
            document.domain="csdn.net";  
          }
        //文章查看窗口
        if(location.href.indexOf("article/details") > -1||location.href.indexOf("www.cnblogs.com")>-1)
        {
              var divBtn = document.createElement("div");
              divBtn.setAttribute("id", "ReproduceBtn");
              divBtn.innerHTML ='转载'; 
              if(cnblog){ 
                divBtn.style.marginTop="-40px";
                divBtn.style.position="relative";
              }
              var article=document.getElementsByClassName('article_content')[0]||document.getElementById('cnblogs_post_body');;
              article.insertBefore(divBtn,article.childNodes[0]); 
              var posteditUrl=cnblog?"https://i.cnblogs.com/EditPosts.aspx?opt=1":"https://mp.csdn.net/postedit";

              divBtn.onclick=function()
              {
                  window.open(posteditUrl);   
              }
        }
      else //文章发布窗口
      {
         document.onreadystatechange = function(e){
                if(document.readyState == 'complete') {
                  setTimeout(function(){                 
                      if(window.opener)
                        {
                          var contentDocumentbody=document.getElementsByTagName("iframe")[0]==undefined?null:document.getElementsByTagName("iframe")[0].contentDocument.body;
                          var blogContent=(window.opener.document.getElementById('content_views')||window.opener.document.getElementById('cnblogs_post_body')).innerHTML
                                           +"<br>---------------------" 
                                           +"<br>作者:"+(window.opener.document.getElementsByClassName('follow-nickName')[0]||window.opener.document.getElementById('profile_block').childNodes[1]).innerText 
                                           +"<br>来源:"+(cnblog==true?"CNBLOGS":"CSDN")
                                           +"<br>原文:"+window.opener.location.href 
                                           +"<br>版权声明:本文为作者原创文章,转载请附上博文链接!";
                          (document.getElementById('txtTitle')||document.getElementById('Editor_Edit_txbTitle')).value="[转]"+window.opener.document.title.split('-')[0];
                            //(cnblog?window.opener.document.title:window.opener.document.getElementsByClassName('title-article')[0].innerText);
                          //清除代码前的多余行号
                          if(contentDocumentbody)
                          {
                            contentDocumentbody.innerHTML=blogContent.replace(/<ul class=\"pre-numbering\"[\s\S].*<\/ul>/g,'').replace(/<div class=\"cnblogs_code_toolbar\"[\s\S].*<\/div>/g,'').replace(/<a[\s\S].*class=\"toolbar_item[\s\S].*>?<\/a>/g,'');                          
                            if(contentDocumentbody.children.ReadBtn)contentDocumentbody.children.ReadBtn.remove();
                            if(contentDocumentbody.children.ReproduceBtn)contentDocumentbody.children.ReproduceBtn.remove();
                          }
                          if(document.getElementById("selType"))document.getElementById("selType").value="2";
                          //转载地址
                                                                                  if(document.getElementById('articleInput'))document.getElementById('articleInput').value=window.opener.location.href ;
                          var cnblogsMDeditor=document.getElementById("Editor_Edit_EditorBody");
                          if(cnblogsMDeditor)
                          {
                            var htmlContent=blogContent.replace(/<ul class=\"pre-numbering\"[\s\S].*<\/ul>/g,'');
                            htmlContent=htmlContent.replace(/<div class=\"cnblogs_code_toolbar\"[\s\S].*<\/div>/g,'');
                            htmlContent=htmlContent.replace(/<a[\s\S].*class=\"toolbar_item[\s\S].*>?<\/a>/g,'');
                            htmlContent=htmlContent.replace(/<div id=\"ReproduceBtn\"[\s\S].*<\/div>/g,'');
                            htmlContent=htmlContent.replace(/<div id=\"ReadBtn\"[\s\S].*<\/div>/g,'');
                            htmlContent=htmlContent.replace(/<div class=\"line[\s\S].*>\d+<\/div>/g,'');
                            var turndownService = new TurndownService();
                            var mdContent = turndownService.turndown(htmlContent);
                            cnblogsMDeditor.value=mdContent;
                          }
                        }},1000);                  
                 
                }
            }         
          
      } 
        
    })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址