OriTamper

点击锚点之后自动复制链接

// ==UserScript==
// @name         OriTamper
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  点击锚点之后自动复制链接
// @author       You
// @match        http://*/*
// @match        https://*/*
// @icon         data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAACXBIWXMAAAsTAAALEwEAmpwYAAALvUlEQVR4nO1dC3BU1Rne1L7f7UxrbZPz2CzJ7jm7YZPNiwRIgIDhmSgETIiKFN8oVhEtvgvWQqw6Vmu141TBih0VQbDISFGE2o5WFFGslCgRBB+IyksXNKfz3b1ns0sk2U129+4u95v5Z5abwP3P/+9/zv88OBw2bNiwYcOGDRs2bNiwYcOGDRs2bNiwYcOGjeMRJ55Y9B3GvDWUywsIF3cRLp6mTG6mXL5DuThEmXzKah6zHoQIQZ3iSsLFWsJkkHKpjkVQkNX8ZiVcLtf3CRNnEy7/HSnw/Hypxo0uU5dfPFTNvmioYk6tCPkpYeJaIcTXreY9q0DpwB9SLq8nXHykleD1FRkKePzBcWrP1hYV3NWq1iydoDyiSFvFc5y7C6zmPauAbzblci5h4mOtiKaJFerRRWPVvu0hJWh6bPFYw1JCvycWuVyub1jNf1aBOGU1ZfJVrYiWKZXqudWnRClB0zMrGpSrwBuyDCavtpr37EJNzVcpF22Uyy8g4JqhAbV2ecOXKiK4q1Vt3jCxa5tiYr7V7GcVCHGfRLhcpw/qm+eNUPs7oremYARh2xpVF9DKuNfhcORYvYasQa7T56Nc7oJwKyr8nf98svGYigiadPXltaEzg4kXYFm9vUP6Sm8HpWZFGQzGPBWUyw8h3IkNFerd10+LEvze9hZ1zZxadf6M6vCzjU+fqni+F2fGZ7lOtzeGd1CPCBwC4XNqVpaByHOKwZTJ/VDGudOru3lPz65oVIMGFatLLxyq3vtvc/j5aZMqdRwyt6d/3+ks+iml7kq3DKxa2LbgMAif8Qw/S8QassbyKJUebRmzzh+iPt05NSzwz95pVX9YOFKVlvm7HeprlzXowG93bm7lt47177sGFH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ojjZCjvQ8UmKxSSDCC0EX51KMTVNu8Ecb8Ow7i8nK/8vp8hgDRyIcxCbjS55xVbYzS4XCObGfqjTDSbSryw7Rr7stjnslgDhXDRKfjg2lKU7pm6a9ypCG+QrjYAgYxf261sIJJJlifqYw9hYWF33OkI/K4dySYdAtfTPtvptInb001xvZimaW3HJSLv4HRaa2Doiapsoluui40eke4fCnW4VTLgMSf9t/vufVky4UXTDAhXQJ3GDEP56LckQnAjCDlshMB2wtrklO8ClpAu7ecpsrK/J0Z2e5KubgNjJeV+ZNS4g1acG7omANX12bcUBHS1GBcX+OHb5fVQg32kQ7taFW/PNPszGdiR8Z2ORr38Jo3O4ytL81IpRx8e6pRgDOzuR8kOoGZclAqfkaY3IoF1daUZNT2tW97i5HLMjO5+3K5LHNkAzj3nqgtBWdKJhz0HZumqAnjdJ5K7qHUO8iRTQhtX6EzBd4XXOJ0jVPWrWhQxcUDDW+KMrEtbdLqSTnombwFLrEOHtMpot/b3qLmzq4N3y2PCmDGHuDxgDFPgw4ekWZB7qu/DdrBfhAsFb1lVYOKdYxxmDBxBfJzjuMFKBbpwhaourrYqMunsp4CReCCf/zPCxGFredRzHIcryBOzwjK5WtaIOXlfnXbTSOTupWh9Is7WIYPC92abVrFu2aR6fixil5S901I1kVW7iZPqjAE9/q/mhLS17Xkz6PVWa1VRj9VlyJkRx6Ts2K5cPN4RA7KwYTJB43/yiiitAp3GZW/m+fXGTfP4XIbjM7h8mUUxHAGoT8KsyVo/l72wFjjbLr4vMHGdhhdqhWfEy6eJFxMRVOD1YvOCLhwQx0V06Cc0HYSf338KCXAiVhOuLgQcZHV68t45OV7JNp7CJO/pUw8EtreRDvq2WhgCzWxQeiiHSMBoc58sYBwOYNS4bfPBhs2bNiwYcOGDRs2bNiwYcOGDRs2bNiwYcNxvOL/QlHnzQCL/t4AAAAASUVORK5CYII=
// @grant        none
// @require      https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.2.1/jquery.min.js
// @license GPLv3
// ==/UserScript==

(function() {
    'use strict';
    window.addEventListener('focus', function (event) {
        console.log('has focus' + window.location.href);
        fetch('http://127.0.0.1:5000/chrome_url', {
            method: 'POST',
            body: JSON.stringify({ 'url': window.location.href }),
        });
    });


    window.addEventListener("load", (event) => {
        console.log("load:" + window.location.href);
        fetch('http://127.0.0.1:5000/chrome_url', {
                method: 'POST',
                body: JSON.stringify({ 'url': window.location.href }),
        });

        console.log("Fully Loaded");
        var links = document.querySelectorAll("a");
        for (var i = 0; i < links.length; i++) {
            var url = links[i].href;
            if(url.indexOf('#') > -1)
            {
                links[i].addEventListener("click", function(){
                    console.log('hrefValue: '+ this.href);
                    navigator.clipboard.writeText(this.href);
                });
            }
        }
    });

})();