// ==UserScript==
// @name CSDN,CNBLOG博客文章一键转载插件
// @version 4.1.2
// @description CSDN博客文章转载插件 可以实现CSDN上的文章一键转载
// @author By Jackie http://csdn.admans.cn/
// @match *://blog.csdn.net/*/article/details/*
// @match *://mp.csdn.net/postedit*
// @match *://mp.csdn.net/postedit?opt=1
// @match *://mp.csdn.net/console/editor/html?opt=1
// @match *://www.cnblogs.com/*/p/*.html
// @match *://www.cnblogs.com/*/articles/*.html
// @match *://www.cnblogs.com/*/archive/*/*/*/*.html
// @match *://*.blog.csdn.net/article/details/*
// @match *://i.cnblogs.com/EditArticles.aspx?opt=1
// @match *://i.cnblogs.com/EditPosts.aspx?opt=1
// @match *://i-beta.cnblogs.com/posts/edit?opt=1
// @match *://mp.csdn.net/mp_blog/creation/editor?opt=1
// @match *://editor.csdn.net/md/?not_checkout=1
// @match *://mp.csdn.net/mp_blog/creation/editor?*
// @require https://unpkg.com/turndown/dist/turndown.js
// @grant GM_addStyle
// @namespace https://greasyfork.org/users/164689
// @supportURL https://github.com/JackieZheng/CsdnCnblogReproduce/issues/
// @icon https://www.google.cn/s2/favicons?domain=csdn.net
// @downloadURL none
// ==/UserScript==
GM_addStyle("#ReproduceBtn{position: absolute;float: right;right: 0px;width: auto;background: #0f962191;z-index: 9989;color: white;text-align: center;margin: 5px;padding: 5px;border-radius: 5px;cursor: pointer;line-height: 100%;}");
GM_addStyle(".tag__box{width: 100% !important;}");
GM_addStyle(".tag__box div.tag__options-list{width: 100% !important;max-height:300px !important;padding: 8px 8px 0 0;display: flex;flex-direction: row;align-content: flex-start;align-items: center;justify-content: space-between;flex-wrap: wrap;}");
GM_addStyle(".tag__box div .tag__options-list .tag__option-box:last-child {margin-right: auto;}");
GM_addStyle(".tag__box div .tag__options-list .tag__option-box:hover {color:#67c23a;}");
GM_addStyle(".tag__box div.tag__options-content{height: auto !important;}");
(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.getElementsByClassName('postBody')[0] || document.getElementsByClassName('blogpost-body')[0];
article.insertBefore(divBtn, article.childNodes[0]);
var posteditUrl = cnblog ? "https://i-beta.cnblogs.com/posts/edit?opt=1": "https://mp.csdn.net/console/editor/html?opt=1";
divBtn.onclick = function() {
window.open(posteditUrl);
}
}
//文章发布窗口
else
{
document.onreadystatechange = function(e) {
if (document.readyState == 'complete') {
//setTimeout(()=>{},8000);
var contentToPaste=null;
var timer = setInterval(function(){
if(!contentToPaste)
{
contentToPaste = document.getElementsByTagName("iframe")[0] == undefined ? null: document.getElementsByTagName("iframe")[0].contentDocument.body;
}
else{
clearInterval(timer);
opt(contentToPaste);
}
},30)
}
}
}
function opt(contentDocumentbody) {
if (window.opener && (location.href.indexOf("?opt=1") > -1||location.href.indexOf("?not_checkout=1") > -1)) {
var authorName = "";
if (window.opener.document.getElementsByClassName('follow-nickName').length > 0) {
authorName = window.opener.document.getElementsByClassName('follow-nickName')[0].innerText;
} else if (window.opener.document.getElementById('profile_block')) {
authorName = window.opener.document.getElementById('profile_block').childNodes[1].innerText;
} else if (window.opener.document.getElementById('author_profile_detail')) {
authorName = window.opener.document.getElementById('author_profile_detail').childNodes[1].innerText;
}
var blogContent = (window.opener.document.getElementById('content_views') || window.opener.document.getElementById('cnblogs_post_body')).innerHTML + "
---------------------" + "
作者:" + authorName + "
来源:" + (cnblog == true ? "CNBLOGS": "CSDN") + "
原文:" + window.opener.location.href.split('?')[0] + "
版权声明:本文为作者原创文章,转载请附上博文链接!" + "
内容解析By:CSDN,CNBLOG博客文章一键转载插件";
var input_title = (document.getElementById('post-title') ||document.getElementById('txtTitle') || document.getElementById('Editor_Edit_txbTitle') || document.querySelector('input.cnb-input'))||document.getElementsByClassName("article-bar__title")[0];
if (input_title) {
var aTitle = "[转]" + window.opener.document.title.split('_')[0];
aTitle = aTitle + "(转载请删除括号里的内容)";
input_title.value = aTitle;
}
if (contentDocumentbody) {
var aContent = blogContent.replace(/