复制网页标题和网址为Markdown链接

鼠标右键选择TamperMonkey运行此脚本可引用网页标题+网址为Markdown链接 快捷键 ALT + B 个人自用 代码参考来自https://gist.github.com/vhxubo/e94b0cceadf0291050f05ab1c0bb19c9

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            复制网页标题和网址为Markdown链接
// @namespace       https://github.com/DayoWong0
// @description     鼠标右键选择TamperMonkey运行此脚本可引用网页标题+网址为Markdown链接 快捷键 ALT + B 个人自用 代码参考来自https://gist.github.com/vhxubo/e94b0cceadf0291050f05ab1c0bb19c9
// @version         0.8
// @author          https://github.com/DayoWong0
// @match        *://*/*
// @require      https://cdn.jsdelivr.net/npm/sweetalert2@11
// @grant        GM_registerMenuCommand
// @grant        GM_setClipboard

// ==/UserScript==]]]]

(function() {
    'use strict';
    function successAlert(){
        Swal.fire({
                icon: 'success',
                title: '复制成功!',
                timer: 2000
            })
    }
    function getTitle(){
        let host = window.location.host
        let title = document.title
        let device = navigator.userAgent.toLowerCase();

        if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(device)) {
            //移动端

            //百度贴吧
            if(host === "tieba.baidu.com"){
                title = document.querySelector("body > div.main-page-wrap > div > div.main-thread-content-margin.main-thread-content > h1").textContent
                    + "【" + document.querySelector("body > div.main-page-wrap > div > div:nth-child(1) > div > div > div.forum-block").textContent
                + "】_百度贴吧"
            }
            //CSDN
            if(host === "blog.csdn.net"){
                title = document.querySelector("#articleContentId > span.tit").textContent
            }
        } else {
            //pc端

            //CSDN
            if(host === "blog.csdn.net"){
                title = document.querySelector("#articleContentId").textContent
            }
        }
        return title
    }

    GM_registerMenuCommand("复制标题及链接", () =>
                           {GM_setClipboard(`[${getTitle()}](${document.URL} )`)
                           successAlert()
                           }
                          );
    GM_registerMenuCommand("仅复制标题", () => {GM_setClipboard(`${getTitle()}`)
                                           successAlert()
                                          }
                                           );
    GM_registerMenuCommand("仅复制链接", () => {GM_setClipboard(document.URL)
                                          successAlert()
                                          });
})();