1. 正则表达式
  2. 写一个复制的插件

正则表达式

负向前瞻

负前瞻:

haorooms(?!hrms) 查找后面不是hrms的haorooms,

^(?: (a|b|c)(?!.*\1))*$ 查找后续不再出现的 a b c

写一个复制的插件

油猴脚本的编写—超详细(附自己写的油猴小脚本) - 掘金

url match 格式

用 js 添加一个 svg 图片不显示

How to Create an SVG Element with Vanilla JavaScript

哎本来的想法是用 svg 写,然后发现图片可以硬编码写到 js 里面…

(function() {
    'use strict';

    let copy_div = document.createElement("div");

    // where to place it 
    copy_div.style.position = "fixed";
    copy_div.style.height = "50px";
    copy_div.style.width = "50px";
    copy_div.style.top = "0px"; 
    copy_div.style.right = "10px";
    copy_div.style.zIndex = 999;


    const ns = 'http://www.w3.org/2000/svg';
    let copy_svg = document.createElementNS(ns, "svg");
    copy_div.appendChild(copy_svg);


    //the svg setting
    copy_svg.setAttributeNS(null, "height", "64px")
    copy_svg.setAttributeNS(null, "width", "64px")
    copy_svg.setAttributeNS(null, "version", "1.1")
    copy_svg.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink")
    copy_svg.setAttributeNS(null, "viewBox", "-307.2 -307.2 1126.40 1126.40")
    copy_svg.setAttributeNS(null, "transform","matrix(-1, 0, 0, 1, 0, 0)rotate(0)")
    copy_svg.setAttributeNS(null, "viewBox", "-307.2 -307.2 1126.40 1126.40")
    copy_svg.setAttribute( "xml:space", "preserve")
    copy_svg.setAttributeNS(null, "fill", "#000000")

    //svg path
    let copy_svg_g = document.createElementNS(ns,"g");
    copy_svg.appendChild(copy_svg_g);

    
    let copy_svg_path = document.createElementNS(ns,"path");
    copy_svg_path.setAttribute("d", "M504.302,195.59c-10.618-6.362-29.71-43.514-33.959-47.755c-4.249-4.256-28.662-13.81-28.662-13.81 l-13.795-43.514c-26.542,3.185-42.449,45.634-43.513,48.819c0,0-2.661,73.764-120.47,45.11 c-84.437-20.54-135.22-40.407-177.872-0.36c-2.668-4.578-4.491-9.234-5.822-14.257c-2.378-9.062-2.918-19.46-2.91-31.308 c0-5.806,0.109-11.924,0.117-18.34c-0.008-13.436-0.493-28.248-4.046-44.015C69.85,60.386,63.136,43.743,51.344,27.162 c-5.086-7.168-15.024-8.858-22.199-3.764c-7.167,5.094-8.858,15.031-3.764,22.199c9.304,13.145,14.162,25.368,16.932,37.551 c2.739,12.167,3.271,24.397,3.264,37.027c0,6.024-0.118,12.136-0.118,18.34c0.016,12.646,0.438,25.799,3.928,39.32 c2.746,10.735,7.722,21.58,15.508,31.706C31.93,261.458,50.037,316.584,50.037,316.584l-34.093,54.241 c-0.618,0.978-1.033,2.066-1.244,3.192L0.146,454.073c-0.641,3.521,0.862,7.08,3.819,9.084l40.979,27.763 c0.876,0.602,1.964,0.775,2.981,0.493c1.026-0.274,1.863-0.994,2.308-1.949l8.326-17.825c0.618-1.338,0.368-2.918-0.634-3.998 l-10.728-11.448c-2.182-2.324-2.973-5.634-2.081-8.701l17.84-61.033c0.579-1.948,1.784-3.646,3.435-4.82l23.983-17.058 c3.255-2.332,7.66-2.222,10.806,0.251c3.146,2.472,4.288,6.721,2.809,10.438L93.41,401.858c-1.22,3.051-0.681,6.525,1.401,9.06 l60.298,73.365h45.218c1.996,0,3.616-1.62,3.616-3.607v-22.504c0-1.996-1.62-3.615-3.616-3.615h-14.303 c-3.342,0-6.409-1.854-7.982-4.804l-24.484-41.049c-1.643-3.106-1.33-6.87,0.783-9.663l21.948-28.999 c1.706-2.245,4.367-3.575,7.192-3.575h61.197c2.872,0,5.579,1.376,7.277,3.701c1.698,2.324,2.191,5.313,1.33,8.059l-19.726,62.16 c-0.626,1.957-0.564,4.077,0.18,5.994l12.653,32.598h39.272v-8.49l-6.494-20.415c-0.61-1.909-0.563-3.967,0.133-5.852 l26.471-71.847c1.315-3.553,4.694-5.908,8.474-5.908h27.011c2.449,0,4.796,1.002,6.502,2.777l74.813,103.365c0,0,38.208,0,50.947,0 c12.738,0,7.809-25.414-4.241-26.542c-22.826-2.12-52.004-65.798-64.742-88.09c-12.739-22.285,24.664-91.299,53.067-94.453 c28.654-3.185,43.514-14.867,47.763-30.79C513.856,223.187,514.92,201.959,504.302,195.59z")
    copy_svg_g.appendChild(copy_svg_path);


    let url = document.URL;
    let title = document.title;

    copy_div.addEventListener(
        'click',
        async (e) => {
            await navigator.clipboard.writeText("[" + title +"](" + url + ")")
        }
        )


    // add copy button to body
    document.body.appendChild(copy_div);
    
})();

找到了一个好看的 SVG 库 SVG Repo - Free SVG Vectors and Icons

如何操作剪贴板: 剪贴板操作 Clipboard API 教程 - 阮一峰的网络日志

最终效果:

// ==UserScript==
// @name         cope tilte as markdown
// @namespace
// @version      0.1
// @description  try to take over the world!
// @author       giacomo
// @match        https://*/*
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    // before copy
    const icon_0 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIAAgMAAACJFjxpAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAJUExURczMzEdwTDk0NQdKak4AAAACdFJOU/4A/KwBCwAACz9JREFUeNrt3b+OpDgTAPACCelEdBeQnzbkKQi+L+ck8z4O7zHQRZaf8oLZbsCu8p9ygftmPdnO9jS/LlcZY9MYtso/0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAN0AAPHGMBGGoCFoCA4H7ACgAAUA/wdXwyBPBQAMgQwEMBIENwN0C9AV0dwLsFqDaAJ2rw62eqAjiOT7QBPJUClQCnFCCSAB5LASIJ4LEUIHqCJwHd8wBVG3DJQTwLvzlguQKmxwHwYYDhaYCqDXjl4KjrAkZr6Y4AHiiC2VpdFWCtNXUAX8fvawNGa19J8DBAvVPgAwC6BmB95+CvCljeRVAVMNYDwGcA5l8XoE5FYGt0xWdAlXPBeqrCioCvIthrA6oMSPx+aKgBmI8i+OUAXhU+fWV0AuwlAAVQAOjPAN7VMT3Fl9IRnkcDPMAanGzPAvBmSMKT7VHAeCoCFkCFJ9uzAK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wBs2/+3yoCtARqgARqgARqgARqgARqgARqgARqgARqgARqgARqgARqgARqgARqgARqgARqgARqgARqgARrgowH/Aij5SNjDlu6YAAAAAElFTkSuQmCC'
    // after copy
    const icon_1 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIAAgMAAACJFjxpAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAJUExURUdwTExKS+7o6dyqgsIAAAACdFJOUwC4syn2hgAACFpJREFUeNrtnTGS4zYQRYUAiDcRA56GrrJzumo5AXI7wGkYaG5Auoo4pVer0QwJNkAtukd/7e0femTyEej+aKAp7emkUqlUKpVKpVKpVCqVSqVSqVQqlUqlUqlUKpVKpVKpVCqVSqVSqVQqlUr1BJ077P2tf8UC+Bh75P1NiPECnYEY44wEaL4BLMgwbL8BRCRAuAL02BiMcQQCRDCARQM4NECLBvBogAAGuGUh0AduWQh0wlsWAteCWxYu2LUwxgltA5df3gY6tA10YBsAJsENAFiTOnQWOnQW/iTlSI8G6H5hgAC2gZ8EAOhDt6UA6EMm/hQAowKgt8ZAJ3ZoI1QAOEAD3hi+AQDXolYCwAxogKXHAljGei4C4Bhe2krUI46xsWglygHHeAYvAdAyvKyVAqhd0YMUwIQECIxMEgOoDQI5gB4HYDhHDHIAMxpgwQFYznm7BMCtrKuMQkGAEQZwO2+vTAMJgNspT+VVBAEWGICPjK6PBMDtvL0yDyUB+ur/mXdSbO4AI2gE3hqPlc8hCTChpuAOMINGwN0BFhBAwwdgTYHxd4AqI+CPwEvEAtjwAdAjAFYDUOVEXAAbwQAeDLAZAATAZgCq0pkHsB2AquvwABwaoN0CzE8H8GiAsAVYai9RuxgZOEBM1FUCjDJJ8HyAJgUYK2dxlMnCBy9khmHot7M4ymThQ+l0Hl5CXIZBBCCkAMdGMLzVD8sgALBLgsM8tMPHR7/yAewO4CAN7Lp8unVZDKdz6/YAxSudtzHz+vEQnVAWli3t7AlaVt+y3QMUovBMhiwLIOwB8qcku+e/RQEHwBA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5OPzJqpiZkOXKvlA9CFZe7CqW/zARxdWme8eAUwiQN01H8+AmjYAC19zPEogGNXJJmyLufFaQzwAUIsV19dOQvYACazvTOHq1G/+Vw1gM1tcEOZ607GBnDx4FFzAMtJBiBb2XsSYLd2vxtpx83COfOHKbMcX5KR6rhJcHkIYL92MwE+lqIxMzfTQQHLBcgeMzlyavZrd8sDcNnzZtJhzL5+bHkVSZvd3pL5Zfe2xQTw2cNWQw2N29tWwwPIJgHtxcTS6VgApnDSGIoAJxkAVzhrDYVifTVjlgVQOmIhvJhyDcMqiXzhnK8t7JdWA8YCMKHQcSAAKNdgAdjSYTPhxY4asMAAaErn/W4PQJ5hcwB8qfFHAHhqwEJ9RWJC6ZyR8OJADZivB7DFrtcewJAD1tYD+GK/wYQsALWNrQCgO0OFyXXkgFUDnP1B02sH0JBJ62oB/FHbL+TOb+lt7I+WROaw8bkD8CRvLYA7bP2GNEADyVsL0Bw1v036R0vnTC1Ae9R43QJ8+fLbSyxuljpGDBYBvv/x+s+HBJq3rezeHva+N09m8q+s+MoRCEcx6NbDY7M5U707DUeNX0ceSu8+bis7Buv+U19KkyU9I04+3lS+ymMO3z5o1/OT/7iv7B6bw/cvcgALPZI/2sA/7nz79YVNLmRt9ctU4egdnLB2HZuLwaa6fx+OXr/YAJhcDNba0NoJ++Ic9fTxXFqO/Pj5RHPwKpwhjwNzvdSKd0jM+/tBpwcAsvVrK/ZydQZgKZ/ovvnlfHoeQE8BXD4PYC5tCe5zI/E9l1yMfE2WnIXi/IwZyDn3RGVr/0SAkfCrT5mB3NLRE4Z2OT1Bd9PoiEWzPyHVPCMEyxucCxjgGSFYDM+/TmD1J5VKpVKpVCqVSqVSqVQqlUqlUqlUKpVKpVKpVCqVSqVSqVQqlUqlUqlUqoL+BapMYlUeb3RdAAAAAElFTkSuQmCC'

    //img display setting
    const img = document.createElement('img');
    img.src = icon_0;
    img.style.width = '50px';
    img.style.height = '50px';
    img.style.position = 'fixed';
    img.style.top = '10px';
    img.style.right = '10px';
    img.style.zIndex = 1001;

    // click and copy, no permission needed
    img.addEventListener(
        'click',
        async (e) => {
            let url = document.URL;
            let title = document.title;
            await navigator.clipboard.writeText("[" + title +"](" + url + ")")
        }
    )

    // change icon
    img.addEventListener(
        'click',
        function() {
            img.src = icon_1;

            // last for 1 s
            setTimeout(() => {
                img.src = icon_0;
            }, 1000);
        }
    )

    // add copy button to body
    document.body.appendChild(img);

})();