您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
把当前网站链接生成markdown格式的链接形式:[title](url)
当前为
// ==UserScript== // @name 生成markdown链接 // @namespace http://tampermonkey.net/ // @version 0.3.4 // @description 把当前网站链接生成markdown格式的链接形式:[title](url) // @author myaijarvis // @icon https://g.csdnimg.cn/static/logo/favicon32.ico // @run-at document-end // @match *://*/* // @exclude *://*/*.ipynb // @exclude https://www.kaggle.com/code/*/edit // @exclude https://editor.csdn.net/* // @exclude https://www.bilibili.com/bangumi/play/* // @exclude https://aistudio.baidu.com/*/user/* // @require http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js // @grant GM_getResourceURL // @grant GM_getResourceText // @grant GM_addStyle // @grant unsafeWindow // @noframes // @license MIT // ==/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;width:auto;" 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; }else if(url.match(/kaggle\.com\/code\/.*?/)){ title = document.title; }else if(url.match(/leetcode\.cn\/problems\/.*?\/solutions\/.*?\/.*?/)){ title = document.title + '- 题解 - ' + document.querySelector("#__next > div.flex.min-h-screen.min-w-\\[360px\\].flex-col.text-label-1.dark\\:text-dark-label-1 > div > div > div > div > div > div > div.shadow-level1.dark\\:shadow-dark-level1.flex.w-full.min-w-0.flex-col.rounded-xl.lc-lg\\:max-w-\\[700px\\].bg-layer-1.dark\\:bg-dark-layer-1 > div.relative.flex.w-full.flex-col > div.flex.w-full.flex-col.gap-4.px-5.pt-4.pb-8 > div:nth-child(1) > div > div > div.flex.items-start.gap-3 > div").innerHTML; } 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); }