快速复制

快速复制企业信息

目前為 2023-03-01 提交的版本,檢視 最新版本

// ==UserScript==
// @license MIT
// @name         快速复制
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  快速复制企业信息
// @author       lemondqs
// @match        https://www.tianyancha.com/company/**
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tianyancha.com
// @grant        none

// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js
/* globals jQuery, $, waitForKeyElements */

// ==/UserScript==

(function() {
    'use strict';
    $('.introduceRich_btn__sfAyp').click()

    function getinfo() {
        var com = $('.index_company-name__LqKlo').html();
        var man = $('.index_link-click__NmHxP').html();
        var tel = $('.index_detail-tel__fgpsE').html();
        var loc = $('.index_detail-address__ZmaTI').html();
        var dec = $('.introduceRich_expand-item__Vuo_n').text().match(/基本信息(\S*)营运状况/)[1];
        var csv =`${com},${tel},${man},${loc},${dec}\n`;
        var txt =
`${com}
${tel}
${man}
${loc}
${dec}`;
        return {csv, txt};
    }
    var info = getinfo()
    setTimeout(console.info(info.txt), 1000)

    async function copyinfo() {
        try {
            await navigator.clipboard.writeText(info.csv);

            $("#x-copy").html("已复制");
            $("#x-copy").css("background-color", "#00FF6677")

            setTimeout(()=>{
                $("#x-copy").html("复制信息");
                $("#x-copy").css("background-color", "#0066FF77")
            }, 1000)
            console.log('Infos copied to clipboard');
        } catch (err) {
            console.error('Failed to copy: ', err);
        }
    }
    window.copyinfo = copyinfo;

    var dom =
`<div id="x-copy"
style="position: fixed;
top: 420px;
left: 100px;
width:120px;
text-align: center;
border-radius: 5px;
border: 2px #FFF dotted;
cursor: pointer;
padding: 10px;
background-color: #0066FF77;"
onclick="copyinfo()">复制信息</div>`;

    var infodom =
`<textarea id="x-copyinfo"
style="position: fixed;
top: 300px;
left: 20px;
width: 200px;
height: 120px;
padding: 10px;
background-color: #CCCCCC77;">${info.txt}</textarea>`;

    $('body').append(dom);
    $('body').append(infodom);

    // Your code here...
})();