Skip to content

Instantly share code, notes, and snippets.

@phpenterprise
Last active August 15, 2025 03:13
Show Gist options
  • Save phpenterprise/dd4df97cac49eb2ec45cb3c5d06f1b83 to your computer and use it in GitHub Desktop.
Save phpenterprise/dd4df97cac49eb2ec45cb3c5d06f1b83 to your computer and use it in GitHub Desktop.
Linkedin Auto Connect/Invite Script
(Linkedin = {
release: '1.0.5 stable',
data: {},
config: {
autoStart: true,
inspectorSpeed: 5000,
sendSpeed: 4000,
pagerSpeed: 10000,
scrollDownAuto: 600,
debug: true,
message: 'Your custom note message (max 300 length)'
},
setEvents: function () {
this.debug('set events');
},
debug: function (a) {
if (this.config.debug && typeof console === 'object') {
console.log(a)
}
},
init: function () {
this.debug('start script');
this.setDefaults();
this.setEvents();
if (this.config.autoStart) {
this.inspect();
}
},
complete: function () {
this.debug('script complete');
},
sleep: function (a) {
this.setScroll();
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > a) {
break;
}
}
},
totalRows: function () {
return $('.search-result').length;
},
compile: function () {
this.data.pageButtons = $("button.search-result__action-button").filter(function () {
return $.trim($(this).text()) === "Connect";
});
this.data.pageButtonTotal = this.data.pageButtons.length;
},
stop: function () {
clearInterval(Linkedin.data.pageInterval);
clearInterval(Linkedin.data.nextInterval);
},
setDefaults: function () {
this.stop();
this.data = {
pageInterval: null,
nextInterval: null,
pageIndex: (this.data.pageIndex) ? this.data.pageIndex : 1,
pageButtons: {},
pageButtonIndex: 0,
pageButtonTotal: 0,
lockInpect: false,
lockClick: false
};
},
sendInvites: function () {
this.compile();
this.setScroll();
this.debug('validing');
if (this.data.pageButtonTotal === 0 || this.data.lockInpect === true) {
this.sleep(this.config.sendSpeed);
return this.nextPage();
}
this.sleep(this.data.speed);
this.debug('sending invite ' + (this.data.pageButtonIndex + 1) + '/' + this.data.pageButtonTotal);
var button = this.data.pageButtons[this.data.pageButtonIndex];
this.debug('clicking connect');
$(button).click();
this.sleep(Linkedin.config.sendSpeed);
this.debug('adding a note');
$("button:contains('Add a note')").click();
this.sleep(Linkedin.config.sendSpeed);
this.debug('write a note');
var textArea = $('textarea[id="custom-message"]');
textArea.val(this.config.message);
this.sleep(Linkedin.config.sendSpeed);
this.debug('send click');
$("button:contains('Send invitation')").click();
this.sleep(Linkedin.config.sendSpeed);
this.debug('close window');
$("button:contains('Cancel')").click();
this.sleep(Linkedin.config.sendSpeed);
this.debug('ignore confirm mail');
if ($('[id=email]').length) {
$('.send-invite__cancel-btn').click();
}
this.sleep(Linkedin.config.sendSpeed);
this.stop();
if (this.closeAll() && this.data.pageButtonIndex === (this.data.pageButtonTotal - 1)) {
return this.nextPage();
} else if (this.data.lockInpect === false && this.data.pageButtonIndex < (this.data.pageButtonTotal - 1)) {
this.data.pageButtonIndex++;
return this.sendInvites();
} else {
this.debug('waiting page overflow down');
this.sleep(Linkedin.config.sendSpeed);
return this.nextPage();
}
},
nextPage: function () {
Linkedin.debug('find page');
Linkedin.setScroll();
Linkedin.data.lockInpect = true;
Linkedin.data.nextInterval = setInterval(function () {
var pagerButton = $('.artdeco-pagination__button.artdeco-pagination__button--next[id^=ember]');
Linkedin.debug('check page links...');
if (pagerButton.length === 0) {
return false;
}
if (Linkedin.data.lockClick === false) {
Linkedin.debug('call next page (link)');
Linkedin.data.lockClick = true;
pagerButton.trigger('click');
}
Linkedin.checkRequest();
}, Linkedin.config.pagerSpeed);
},
checkRequest: function () {
var currentPageIndex = Linkedin.getURIParam('page');
if (currentPageIndex !== Linkedin.data.pageIndex) {
Linkedin.data.pageIndex = currentPageIndex;
Linkedin.setDefaults();
Linkedin.debug('page ready');
return Linkedin.inspect();
}
},
closeAll: function () {
if ($('.send-invite__cancel-btn').length) {
$('.send-invite__cancel-btn').click();
}
return (!$('.send-invite__cancel-btn:visible').length);
},
setScroll: function (a) {
$('body').click();
window.scrollTo(0, $(window).scrollTop() + ((a) ? a : Linkedin.config.scrollDownAuto));
},
inspect: function () {
this.debug('inspect elements');
this.data.pageInterval = setInterval(function () {
Linkedin.setScroll(Linkedin.config.scrollDownAuto);
if (Linkedin.totalRows() >= 20 && $('.artdeco-pagination__button.artdeco-pagination__button--next[id^=ember]').length) {
clearInterval(Linkedin.data.pageInterval);
Linkedin.sendInvites();
} else {
Linkedin.debug('listening..');
}
}, Linkedin.config.inspectorSpeed);
},
getURIParam: function (name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
}).init();
@phpenterprise
Copy link
Author

Blocked by linkedin. is it working?

Wait a few days and you will be able to send bulk messages and invitations again.

Use Google deep links to submit requests manually as per the example below. This will be a feature that we will implement in the javascript class in the future in case of temporary blocking. I was able to send 1000 requests before being blocked to send invitations, 15 days later the search was released again.

image

Good luck!

@phpenterprise
Copy link
Author

Blocked by linkedin. is it working?

Can I used this for company page as well?

Unfortunately no friend, you can only send notes connection requests (custom messages) through a user account.

Good luck!

@WayneLaagewaard
Copy link

I have an error

(unknown) Uncaught ReferenceError: $ is not defined
at Object.setScroll (:158:9)
at :164:22

how can i fix this?

@phpenterprise
Copy link
Author

I have an error

(unknown) Uncaught ReferenceError: $ is not defined
at Object.setScroll (:158:9)
at :164:22

how can i fix this?

Hello friend, the script is being reviewed for an update.

@WayneLaagewaard
Copy link

Hi Patrick,

how is the review going?

@phpenterprise
Copy link
Author

I'm validating, as soon as available I'll warn you here.

@mohit0121
Copy link

hello, any luck on the update?

@ahmedglas
Copy link

hello, any luck ?

@thealphadollar
Copy link

https://gist.github.com/thealphadollar/7c0ee76664cbd28aecc1bd235f0202fd

I've updated the script and it is working. It is currently in raw form, I'll be updating it with configuration, better logging, etc very soon.

@phpenterprise Thanks for the initial work <3

@phpenterprise
Copy link
Author

@thealphadollar thanks for the help, I really didn't have time to update it.

@evgenispap
Copy link

How can I invite just one profession?

@thealphadollar
Copy link

Hey @evgenispap, I think LinkedIn's official guide to searching would be helpful to you. Please comment if you need any more help, I'm glad you found the script useful ✨

@WayneLaagewaard
Copy link

How can I invite just one profession?

First do a search and the paste the script

@ayoola000
Copy link

this still work?

@thealphadollar
Copy link

@ayoola000
Copy link

Hi do you mind if i build an app with your code, constantly typing is hard :(

@Zhatabsaifi
Copy link

Why this script send the note message only to few connection not all ?

When first time i used this script this was perfectly run. But now it's not send the note message.
I don't know why?

@thealphadollar
Copy link

@djain1989
Copy link

Thanks to the creator of this script.

Automating my need using this :)
Just tried using this and it seems to be working as of today.

image

@rival123
Copy link

How to add a note while sending the invites. I don't find that code in the above script can someone please help me with that

@thealphadollar
Copy link

@waynelaagewaard1
Copy link

Is there still a need for such functionality?

@syedfahad1122
Copy link

syedfahad1122 commented Aug 17, 2022

Nice Script Working Well Cheers!
CROSS - SITE scripting working well Hurrah come ping me i'll resolve all your bug

@DereC4
Copy link

DereC4 commented Aug 15, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment