Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name UserConnector
- // @namespace http://tampermonkey.net/
- // @version 2.1
- // @description Add an easier way to connect on LinkedIn Sales Navigator
- // @author Antonio Mindov
- // @match https://www.linkedin.com/sales/people/*
- // @grant none
- // ==/UserScript==
- function execWithTimeout(f, t, max, callback) {
- let count = 0;
- let intervalId = setInterval(function(){
- if(f() || count >= max) {
- if(count < max && callback) {
- callback();
- }
- clearInterval(intervalId);
- }
- count++;
- }, t);
- }
- function clickButtonTimeout(btnClass, t, max, callback) {
- execWithTimeout(function(){
- let btn = document.getElementsByClassName(btnClass)[0];
- if(!btn){
- return false;
- }
- btn.click();
- return true;
- }, t, max, callback);
- }
- function addButtonToDiv(divClass, btn) {
- let actionsDiv = document.getElementsByClassName(divClass)[0];
- if(!actionsDiv){
- return false;
- }
- actionsDiv.appendChild(btn);
- return true;
- }
- function connectWithContact() {
- clickButtonTimeout('profile-topcard-actions__overflow-toggle', 10, 200, function() {
- clickButtonTimeout('connect profile-topcard-actions__overflow-item', 10, 200, function() {
- clickButtonTimeout('connect-cta-form__send', 10, 200);
- });
- });
- }
- function copyName() {
- let nameEl = document.getElementsByClassName('profile-topcard-person-entity__name')[0];
- if(!nameEl) {
- return false;
- }
- copyToClipboard(nameEl.innerText);
- return true;
- }
- function copyToClipboard(str) {
- const el = document.createElement('textarea');
- el.value = str;
- el.setAttribute('readonly', '');
- el.style.position = 'absolute';
- el.style.left = '-9999px';
- document.body.appendChild(el);
- el.select();
- document.execCommand('copy');
- document.body.removeChild(el);
- };
- function addShortcut(btn) {
- document.onkeydown = keydown;
- function keydown(evt){
- if (!evt) evt = event;
- if (evt.altKey && evt.keyCode==69){ //Alt + E
- event.preventDefault();
- btn.click()
- }
- }
- }
- (function() {
- 'use strict';
- let actionsDivClass = 'profile-topcard-actions'
- var btn=document.createElement("button");
- btn.innerText="Hack"
- btn.className = "ph4 button-primary-large";
- btn.addEventListener("click", function(){
- copyName();
- connectWithContact();
- });
- addShortcut(btn)
- execWithTimeout(function(){return addButtonToDiv(actionsDivClass, btn)}, 500, 20);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement