快速复制

快速复制企业信息

目前为 2023-03-14 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @license MIT
  3. // @name 快速复制
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.9
  6. // @description 快速复制企业信息
  7. // @author lemondqs
  8. // @match https://www.tianyancha.com/company/**
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=tianyancha.com
  10. // @grant none
  11.  
  12. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js
  13. /* globals jQuery, $, waitForKeyElements */
  14.  
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. // 'use strict';
  19. setTimeout(function(){
  20.  
  21.  
  22. // 提前展开页面 保障信息完整
  23. $('.introduceRich_btn__sfAyp').click()
  24.  
  25. // 获取行业信息
  26. function gethyinfo() {
  27. var hy = '';
  28. let hyidx = null;
  29. $('.index_tableBox__ZadJW tr').each((idx, tr)=>{
  30. if(idx==6) {
  31. $(tr).children().each((tdid, td)=>{
  32. if (hyidx !== null && tdid === hyidx+1) {
  33. hy = $(td).text()
  34. } else if($(td).text()=='行业') {hyidx = tdid;}
  35. })
  36. }
  37. })
  38. return hy;
  39. }
  40. // 获取经营范围信息
  41. function getjyinfo() {
  42. var jy = '';
  43. let jyidx = null;
  44. $('.index_tableBox__ZadJW tr').each((idx, tr)=>{
  45. if(idx==10) {
  46. $(tr).children().each((tdid, td)=>{
  47. if (jyidx !== null && tdid === jyidx+1) {
  48. jy = $(td).text()
  49. } else if($(td).text()=='经营范围') {jyidx = tdid;}
  50. })
  51. }
  52. })
  53. return jy;
  54. }
  55. // 获取县区名
  56. function getcounty() {
  57. var info;
  58. var result = '';
  59. var loc = $('.index_detail-address__ZmaTI').html();
  60. var reg = /.+?(省|市|自治区|自治州|县|区)/g
  61. if (loc) {
  62. info = loc.match(reg)
  63. }
  64. info.forEach((it, idx)=>{
  65. if(it.includes('县')) result = it
  66. else if(it.includes('区')) result = it
  67. else if(it.includes('市')) result = it
  68. })
  69. return result;
  70. }
  71.  
  72.  
  73. // 获取全部信息
  74. function getinfo() {
  75. var com = $('.index_company-name__LqKlo').html();
  76. var man = $('.index_link-click__NmHxP').html();
  77. var tel = $('.index_detail-tel__fgpsE').html();
  78. var loc = $('.index_detail-address__ZmaTI').html();
  79. var dec = $('.introduceRich_expand-item__Vuo_n').text()//.match(/基本信息(\S*)企业注册(不可用)资本/)[1];
  80. var hyi = gethyinfo();
  81. var cou = getcounty();
  82. var jyi = getjyinfo();
  83. var obj = {com, cou, loc, hyi, man, tel, dec, jyi};
  84. return obj;
  85. }
  86. // 缓存一次保障效率
  87. var info = getinfo()
  88.  
  89. //setTimeout(console.info(Object.values(info).join('\n')), 1000)
  90.  
  91. // 保存进剪切板需异步操作
  92. async function copyinfo() {
  93. try {
  94. await navigator.clipboard.writeText(Object.values(info).join('\t')+"\n");
  95.  
  96. $("#x-copy").html("已复制");
  97. $("#x-copy").css("background-color", "#00FF6677")
  98.  
  99. setTimeout(()=>{
  100. $("#x-copy").html("复制信息");
  101. $("#x-copy").css("background-color", "#0066FF77")
  102. }, 1000)
  103. console.log('Infos copied to clipboard');
  104. } catch (err) {
  105. console.error('Failed to copy: ', err);
  106. }
  107. }
  108. // 挂载到窗体
  109. window.copyinfo = copyinfo;
  110.  
  111. // 多页支持
  112. function mulinfo() {
  113. let cominfo = {}
  114. let locst = localStorage.getItem('cominfo')
  115. if (locst) {
  116. cominfo = JSON.parse(locst)
  117. }
  118. cominfo[info.com] = Object.values(info).join('\t')+"\n";
  119. localStorage.setItem('cominfo', JSON.stringify(cominfo))
  120. return Object.values(cominfo).length
  121. }
  122.  
  123. // 执行保存
  124. let listnum = mulinfo();
  125. // 清空
  126. function reload() {
  127. localStorage.removeItem('cominfo');
  128. $("#x-copylist").html(`复制(0)条`);
  129. listnum = 0
  130. }
  131. // 挂载到窗体
  132. window.reload = reload;
  133.  
  134.  
  135. // 保存进剪切板需异步操作
  136. async function copylist() {
  137. try {
  138. if (listnum>0) {
  139. let locst = localStorage.getItem('cominfo');
  140. let infolist = Object.values(JSON.parse(locst));
  141.  
  142. await navigator.clipboard.writeText(infolist.join(''));
  143. console.info(infolist.join('\n'))
  144. $("#x-copylist").html("已复制");
  145. $("#x-copylist").css("background-color", "#00FF6677")
  146.  
  147. setTimeout(()=>{
  148. $("#x-copylist").html(`复制(${infolist.length})条`);
  149. $("#x-copylist").css("background-color", "#0066FF77")
  150. }, 1000)
  151. console.log('Infos copied to clipboard');
  152. } else {
  153. console.info("没有要复制的数据")
  154. }
  155. } catch (err) {
  156. console.error('Failed to copy: ', err);
  157. }
  158. }
  159. // 挂载到窗体
  160. window.copylist = copylist;
  161.  
  162. var infodom =
  163. `<textarea id="x-copyinfo"
  164. style="position: fixed;
  165. top: 300px;
  166. left: 20px;
  167. width: 200px;
  168. height: 120px;
  169. padding: 10px;
  170. background-color: #CCCCCC77;">${Object.values(info).join('\n')}</textarea>`;
  171.  
  172. var btn =
  173. `<div id="x-copy"
  174. style="position: fixed;
  175. top: 420px;
  176. left: 100px;
  177. width:120px;
  178. height: 40px;
  179. text-align: center;
  180. border-radius: 5px;
  181. border: 2px #FFF dotted;
  182. cursor: pointer;
  183. padding: 10px;
  184. background-color: #0066FF77;"
  185. onclick="copyinfo()">复制信息</div>`;
  186.  
  187. var mulbtn =
  188. `<div id="x-copylist"
  189. style="position: fixed;
  190. top: 460px;
  191. left: 100px;
  192. width:120px;
  193. height: 40px;
  194. text-align: center;
  195. border-radius: 5px;
  196. border: 2px #FFF dotted;
  197. cursor: pointer;
  198. padding: 10px;
  199. background-color: #0066FF77;"
  200. onclick="copylist()">复制(${listnum})条</div>`;
  201. var rebtn =
  202. `<div id="x-reload"
  203. style="position: fixed;
  204. top: 460px;
  205. left: 20px;
  206. width:60px;
  207. text-align: center;
  208. border-radius: 5px;
  209. border: 2px #FFF dotted;
  210. cursor: pointer;
  211. padding: 10px;
  212. background-color: #0066FF77;"
  213. onclick="reload()">清空</div>`;
  214.  
  215. $('body').append(infodom);
  216. $('body').append(btn);
  217. $('body').append(mulbtn);
  218. $('body').append(rebtn);
  219.  
  220. }, 1000);
  221.  
  222.  
  223. // Your code here...
  224. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址