Advertisement
Guest User

UserConnector v2.1

a guest
Sep 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         UserConnector
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2.1
  5. // @description  Add an easier way to connect on LinkedIn Sales Navigator
  6. // @author       Antonio Mindov
  7. // @match        https://www.linkedin.com/sales/people/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. function execWithTimeout(f, t, max, callback) {
  12.     let count = 0;
  13.     let intervalId = setInterval(function(){
  14.         if(f() || count >= max) {
  15.             if(count < max && callback) {
  16.                 callback();
  17.             }
  18.             clearInterval(intervalId);
  19.         }
  20.         count++;
  21.     }, t);
  22. }
  23.  
  24. function clickButtonTimeout(btnClass, t, max, callback) {
  25.     execWithTimeout(function(){
  26.         let btn = document.getElementsByClassName(btnClass)[0];
  27.         if(!btn){
  28.             return false;
  29.         }
  30.         btn.click();
  31.         return true;
  32.     }, t, max, callback);
  33. }
  34.  
  35. function addButtonToDiv(divClass, btn) {
  36.     let actionsDiv = document.getElementsByClassName(divClass)[0];
  37.     if(!actionsDiv){
  38.         return false;
  39.     }
  40.     actionsDiv.appendChild(btn);
  41.     return true;
  42. }
  43.  
  44. function connectWithContact() {
  45.     clickButtonTimeout('profile-topcard-actions__overflow-toggle', 10, 200, function() {
  46.         clickButtonTimeout('connect profile-topcard-actions__overflow-item', 10, 200, function() {
  47.             clickButtonTimeout('connect-cta-form__send', 10, 200);
  48.         });
  49.     });
  50. }
  51.  
  52. function copyName() {
  53.     let nameEl = document.getElementsByClassName('profile-topcard-person-entity__name')[0];
  54.     if(!nameEl) {
  55.         return false;
  56.     }
  57.     copyToClipboard(nameEl.innerText);
  58.     return true;
  59. }
  60.  
  61. function copyToClipboard(str) {
  62.     const el = document.createElement('textarea');
  63.     el.value = str;
  64.     el.setAttribute('readonly', '');
  65.     el.style.position = 'absolute';
  66.     el.style.left = '-9999px';
  67.     document.body.appendChild(el);
  68.     el.select();
  69.     document.execCommand('copy');
  70.     document.body.removeChild(el);
  71. };
  72.  
  73. function addShortcut(btn) {
  74.     document.onkeydown = keydown;
  75.  
  76.     function keydown(evt){
  77.         if (!evt) evt = event;
  78.         if (evt.altKey && evt.keyCode==69){ //Alt + E
  79.             event.preventDefault();
  80.             btn.click()
  81.         }
  82.     }
  83. }
  84.  
  85. (function() {
  86.     'use strict';
  87.     let actionsDivClass = 'profile-topcard-actions'
  88.     var btn=document.createElement("button");
  89.     btn.innerText="Hack"
  90.     btn.className = "ph4 button-primary-large";
  91.     btn.addEventListener("click", function(){
  92.         copyName();
  93.         connectWithContact();
  94.     });
  95.  
  96.     addShortcut(btn)
  97.     execWithTimeout(function(){return addButtonToDiv(actionsDivClass, btn)}, 500, 20);
  98. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement