md链接

生成markdown格式的形式:[title](url)

目前為 2021-12-29 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         md链接
// @namespace    http://tampermonkey.net/
// @version      0.1.4
// @description  生成markdown格式的形式:[title](url)
// @author       myaijarvis
// @match        https://blog.csdn.net/*/article/details/*
// @match        https://*.blog.csdn.net/article/details/*
// @match        https://www.cnblogs.com/*/p/*
// @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/*

// @icon         https://www.google.com/s2/favicons?domain=undefined.localhost
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
// @require      https://cdn.bootcdn.net/ajax/libs/layer/3.5.1/layer.min.js
// @icon         https://g.csdnimg.cn/static/logo/favicon32.ico
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function () {
    "use strict";

    // Your code here...

    /*
  // @match        https://*.zhihu.com/p/*
  知乎有点小问题,待更新
  */
    // 引入css
    $("head").append(
        `<link href='https://www.layuicdn.com/layui/css/layui.css' rel="stylesheet"></link>`
  );
    $("head").append(
        `<link href='https://cdn.bootcdn.net/ajax/libs/layer/3.1.1/theme/default/layer.min.css' rel="stylesheet"></link>`
  );

    //复制操作
    //创建复制按钮
    function addBtn() {
        let element = $(
            `<button style="top: 100px;right:0px; position: fixed;z-index:1000;" class="layui-btn layui-btn-sm" id="copyBtn">复制</button>`
    );
      $('body').append(element);
  }

    function copy() {
        let title = document.title;
        title = title.replace(/\(.*?\)/, "").trim(); // 去掉CSDN "(1条消息)"  再去掉前后空格

        let url = document.URL;
        let pattern = /\?.*/; // ?是特殊字符,需要加反斜杠
        url=url.replace(pattern, ""); // 去掉?后面的参数

        let text=''
        if(url.match(/github.com/)){
            text=`[GitHub](${url})`
        }else if(url.match(/mp.weixin.qq.com/)){
            title=$('meta[property="twitter:title"]').attr('content')
            text=`参考:[${title}](${url})`
        }else{
            text=`参考:[${title}](${url})`
        }

      console.log("copy=> " + url);
      let oInput = document.createElement("input");
      oInput.value = text;
      document.body.appendChild(oInput);
      oInput.select(); // 选择对象
      document.execCommand("Copy"); // 执行浏览器复制命令
      oInput.className = "oInput";
      oInput.style.display = "none";
      layer.msg("复制成功");
    }

    addBtn();

    $("#copyBtn").click(function () {
        copy();
    });
})();