快速复制企业信息
当前为
// ==UserScript==
// @license MIT
// @name 快速复制
// @namespace http://tampermonkey.net/
// @version 0.5
// @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 obj = {com, man, tel, loc, dec};
return obj;
}
// 缓存一次保障效率
var info = getinfo()
//setTimeout(console.info(Object.values(info).join('\n')), 1000)
// 保存进剪切板需异步操作
async function copyinfo() {
try {
await navigator.clipboard.writeText(Object.values(info).join(',')+"\n");
$("#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;
// 多页支持
function mulinfo() {
let cominfo = {}
let locst = localStorage.getItem('cominfo')
if (locst) {
cominfo = JSON.parse(locst)
}
cominfo[info.com] = Object.values(info).join(',')+"\n";
localStorage.setItem('cominfo', JSON.stringify(cominfo))
return Object.values(cominfo).length
}
// 执行保存
let listnum = mulinfo();
// 清空
function reload() {
localStorage.removeItem('cominfo');
$("#x-copylist").html(`复制(0)条`);
listnum = 0
}
// 挂载到窗体
window.reload = reload;
// 保存进剪切板需异步操作
async function copylist() {
try {
if (listnum>0) {
let locst = localStorage.getItem('cominfo');
let infolist = Object.values(JSON.parse(locst));
await navigator.clipboard.writeText(infolist.join(''));
console.info(infolist.join('\n'))
$("#x-copylist").html("已复制");
$("#x-copylist").css("background-color", "#00FF6677")
setTimeout(()=>{
$("#x-copylist").html(`复制(${infolist.length})条`);
$("#x-copylist").css("background-color", "#0066FF77")
}, 1000)
console.log('Infos copied to clipboard');
} else {
console.info("没有要复制的数据")
}
} catch (err) {
console.error('Failed to copy: ', err);
}
}
// 挂载到窗体
window.copylist = copylist;
var infodom =
`<textarea id="x-copyinfo"
style="position: fixed;
top: 300px;
left: 20px;
width: 200px;
height: 120px;
padding: 10px;
background-color: #CCCCCC77;">${Object.values(info).join('\n')}</textarea>`;
var btn =
`<div id="x-copy"
style="position: fixed;
top: 420px;
left: 100px;
width:120px;
height: 40px;
text-align: center;
border-radius: 5px;
border: 2px #FFF dotted;
cursor: pointer;
padding: 10px;
background-color: #0066FF77;"
onclick="copyinfo()">复制信息</div>`;
var mulbtn =
`<div id="x-copylist"
style="position: fixed;
top: 460px;
left: 100px;
width:120px;
height: 40px;
text-align: center;
border-radius: 5px;
border: 2px #FFF dotted;
cursor: pointer;
padding: 10px;
background-color: #0066FF77;"
onclick="copylist()">复制(${listnum})条</div>`;
var rebtn =
`<div id="x-reload"
style="position: fixed;
top: 460px;
left: 20px;
width:60px;
text-align: center;
border-radius: 5px;
border: 2px #FFF dotted;
cursor: pointer;
padding: 10px;
background-color: #0066FF77;"
onclick="reload()">清空</div>`;
$('body').append(infodom);
$('body').append(btn);
$('body').append(mulbtn);
$('body').append(rebtn);
// Your code here...
})();