把当前网站链接生成markdown格式的链接形式:[title](url)
当前为
// ==UserScript==
// @name 生成markdown链接
// @namespace http://tampermonkey.net/
// @version 0.2.6
// @description 把当前网站链接生成markdown格式的链接形式:[title](url)
// @author myaijarvis
// @icon https://g.csdnimg.cn/static/logo/favicon32.ico
// @run-at document-end
// @match https://blog.csdn.net/*/article/details/*
// @match https://*.blog.csdn.net/article/details/*
// @match https://www.cnblogs.com/*/p/*
// @match https://www.cnblogs.com/*/articles/*
// @match https://www.cnblogs.com/*/archive/*
// @match https://juejin.cn/post/*
// @match https://www.jianshu.com/p/*
// @match https://www.bilibili.com/video/*
// @match https://www.runoob.com/*
// @match https://cuiqingcai.com/*.html
// @match https://www.w3school.com.cn/*
// @match https://github.com/*
// @match https://mp.weixin.qq.com/s/*
// @match https://*.zhihu.com/p/*
// @match http://www.360doc.com/content/*
// @match https://www.toutiao.com/*
// @match https://blog.gitee.com/*
// @match https://leetcode-cn.com/problems/*
// @match https://labuladong.gitee.io/*
// @match https://programmercarl.com/*
// @match http://www.51gjie.com/*
// @match https://www.bilibili.com/bangumi/play/*
// @match http://www.xiaodigu.cc/*/*
// @match https://www.iqiyi.com/v_*
// @match https://greasyfork.org/*/scripts/*
// @match https://scriptcat.org/script-show-page/*
// @match https://www.luogu.com.cn/problem/*
// @match http://vj.saikr.com/problem/*
// @match https://blog.csdn.net/*/category_*
// @match https://mp.weixin.qq.com/s?__biz=*
// @match https://jingyan.baidu.com/article/*
// @match http://lx.lanqiao.cn/problem.page?gpid=*
// @match https://blog.dotcpp.com/*
// @match https://www.dotcpp.com/oj/*
// @match https://bbs.csdn.net/forums/*
// @match https://segmentfault.com/a/*
// @match https://mp.weixin.qq.com/mp/homepage*
// @match https://www.biancheng.net/*
// @match https://leetcode-cn.com/circle/article/*
// @match http://c.biancheng.net/*
// @match https://www.luogu.com.cn/blog/*
// @match https://www.acwing.com/*
// @match http://vj.saikr.com/problem/*
// @match https://www.liaoxuefeng.com/wiki/*
// @require http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js
// @grant GM_getResourceURL
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant unsafeWindow
// ==/UserScript==
// 全局变量最好都初始化在匿名函数(function () {})();之前
(function () {
"use strict";
//console.log(layui);
addStyle();
addBtn();
let isclick = false; // 防止过快重复点击
$("#copyBtn").click(function () {
if(!isclick){
copy();
isclick =true;
setTimeout(()=>{
isclick =false;
},3000);
}
});
})();
function addStyle(){
//debugger;
let layui_css = `.layui-btn{display: inline-block; vertical-align: middle; height: 38px; line-height: 38px; border: 1px solid transparent; padding: 0 18px; background-color: #009688; color: #fff; white-space: nowrap; text-align: center; font-size: 14px; border-radius: 2px; cursor: pointer; -moz-user-select: none; -webkit-user-select: none; -ms-user-select: none;}
.layui-btn-sm{height: 30px; line-height: 30px; padding: 0 10px; font-size: 12px;}`;
GM_addStyle(layui_css);
}
//创建复制按钮
function addBtn() {
let element = $(
`<button style="top: 150px;right:0px; position: fixed;z-index:1000;cursor:pointer;background:green;" class="layui-btn layui-btn-sm" id="copyBtn">复制</button>`
);
$("body").append(element);
}
//复制操作
function copy() {
//debugger;
let title = document.title;
title = title.replace(/\(.*?\)/, "").trim(); // 去掉CSDN "(1条消息)title" 再去掉前后空格
title = title.replace(/CSDN博客.*/,"CSDN博客"); // title_author-CSDN博客_keyword 去掉keyword
let url = document.URL;
let removeFlag=true;
let pattern = /\?.*/; // 去掉?后面的参数
let text = "";
if (url.match(/github.com/)) {
text = `【[GitHub](${url})】`;
}else if(url.match(/mp\.weixin\.qq\.com\/mp\/homepage/)){
title = $('.rich_media_title').text()+"_"+ $('.account_nickname_inner').text()+ "_微信公众号专栏";
removeFlag=false;
}else if (url.match(/mp\.weixin\.qq\.com/)) {
title = $('meta[property="twitter:title"]').attr("content")+"_"+ $('#js_author_name').text()+ "_微信公众号";
removeFlag=false;
}else if (url.match(/programmercarl.com/)) {
title += $('h1:eq(0)').text()+$('h2:eq(0)').text();
}else if(url.match(/blog.csdn.net\/.*?\/category_*/)){
url = url.replace(pattern, "");
text = `【参考 ==分类专栏==:[${title}](${url})】`;
}else if(url.match(/bbs\.csdn\.net\/forums\/*/)){
url = url.replace(pattern, "");
text = `【参考 ==编程社区==:[${title}](${url})】`;
}else if(url.match(/lx\.lanqiao\.cn\/problem\.page\?gpid=/)){
title += $('body > div.main > div:nth-child(1) > div.panel-heading > h2').text();
removeFlag=false;
}else if(url.match(/bilibili\.com\/video\/.*?\?p=/)){
removeFlag=false;
}
if(removeFlag){
url = url.replace(pattern, ""); // 去掉?后面的参数
}
if(text==""){
text = `【参考:[${title}](${url})】`;
}
console.log("copy=> " + text);
let oInput = document.createElement("input");
oInput.value = text;
document.body.appendChild(oInput);
oInput.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
oInput.className = "oInput";
oInput.style.display = "none";
$("#copyBtn").css("background", "red").text("复制成功");
setTimeout(() => {
$("#copyBtn").css("background", "green").text("复制");
}, 3000);
}