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.

Revisions

  1. phpenterprise revised this gist Jun 10, 2019. 1 changed file with 32 additions and 25 deletions.
    57 changes: 32 additions & 25 deletions linkedin-auto-connect.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    (Linkedin = {
    release: '1.0.5 stable',
    data: {},
    config: {
    autoStart: true,
    inspectorSpeed: 5000,
    sendSpeed: 4000,
    pagerSpeed: 10000,
    @@ -20,7 +22,9 @@
    this.debug('start script');
    this.setDefaults();
    this.setEvents();
    this.inspect();
    if (this.config.autoStart) {
    this.inspect();
    }
    },
    complete: function () {
    this.debug('script complete');
    @@ -48,31 +52,31 @@
    clearInterval(Linkedin.data.nextInterval);
    },
    setDefaults: function () {
    clearInterval(Linkedin.data.pageInterval);
    clearInterval(Linkedin.data.nextInterval);
    this.stop();
    this.data = {
    pageInterval: null,
    nextInterval: null,
    pageIndex: (this.data.pageIndex) ? this.data.pageIndex : 1,
    pageButtons: {},
    pageButtonIndex: 0,
    pageButtonTotal: 0
    pageButtonTotal: 0,
    lockInpect: false,
    lockClick: false
    };
    },
    sendInvites: function () {

    this.compile();
    this.setScroll();
    this.debug('validing');

    if (this.data.pageButtonTotal === 0) {
    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];
    @@ -104,12 +108,11 @@
    }

    this.sleep(Linkedin.config.sendSpeed);
    this.resetRequest();
    this.stop();

    if (this.closeAll() && this.data.pageButtonIndex === (this.data.pageButtonTotal - 1)) {
    return this.nextPage();
    } else if (this.data.pageButtonIndex < (this.data.pageButtonTotal - 1)) {
    } else if (this.data.lockInpect === false && this.data.pageButtonIndex < (this.data.pageButtonTotal - 1)) {
    this.data.pageButtonIndex++;
    return this.sendInvites();
    } else {
    @@ -121,31 +124,29 @@
    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 link');
    Linkedin.debug('check page links...');
    if (pagerButton.length === 0) {
    return false;
    }
    clearInterval(Linkedin.data.nextInterval);
    pagerButton.trigger('click');
    Linkedin.setDefaults();
    Linkedin.debug('call next page');
    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 () {
    $(document).ajaxComplete(function () {
    Linkedin.debug('ready');
    Linkedin.resetRequest();
    Linkedin.inspect();
    });
    },
    resetRequest: function () {
    this.debug('reset request');
    $(document).ajaxComplete(function () {
    Linkedin.debug('default request called');
    });
    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) {
    @@ -168,5 +169,11 @@
    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();
  2. phpenterprise revised this gist Jun 5, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion linkedin-auto-connect.js
    Original file line number Diff line number Diff line change
    @@ -107,7 +107,7 @@
    this.resetRequest();
    this.stop();

    if (this.data.pageButtonIndex >= (this.data.pageButtonTotal - 1) && this.closeAll()) {
    if (this.closeAll() && this.data.pageButtonIndex === (this.data.pageButtonTotal - 1)) {
    return this.nextPage();
    } else if (this.data.pageButtonIndex < (this.data.pageButtonTotal - 1)) {
    this.data.pageButtonIndex++;
  3. phpenterprise revised this gist Jun 5, 2019. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions linkedin-auto-connect.js
    Original file line number Diff line number Diff line change
    @@ -104,12 +104,18 @@
    }

    this.sleep(Linkedin.config.sendSpeed);
    this.resetRequest();
    this.stop();

    if (this.data.pageButtonIndex >= (this.data.pageButtonTotal - 1) && this.closeAll()) {
    return this.nextPage();
    } else {
    } else if (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 () {
    @@ -155,7 +161,7 @@
    this.debug('inspect elements');
    this.data.pageInterval = setInterval(function () {
    Linkedin.setScroll(Linkedin.config.scrollDownAuto);
    if (Linkedin.totalRows() >= 20) {
    if (Linkedin.totalRows() >= 20 && $('.artdeco-pagination__button.artdeco-pagination__button--next[id^=ember]').length) {
    clearInterval(Linkedin.data.pageInterval);
    Linkedin.sendInvites();
    } else {
  4. phpenterprise revised this gist Jun 5, 2019. 1 changed file with 149 additions and 136 deletions.
    285 changes: 149 additions & 136 deletions linkedin-auto-connect.js
    Original file line number Diff line number Diff line change
    @@ -1,153 +1,166 @@
    (Linkedin = {
    data: {},
    config: {
    inspectorSpeed: 2000,
    sendSpeed: 3000,
    pagerSpeed: 10000,
    scrollDownAuto: 500,
    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();
    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;
    }
    data: {},
    config: {
    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();
    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 () {
    clearInterval(Linkedin.data.pageInterval);
    clearInterval(Linkedin.data.nextInterval);
    this.data = {
    pageInterval: null,
    nextInterval: null,
    pageButtons: {},
    pageButtonIndex: 0,
    pageButtonTotal: 0
    };
    },
    sendInvites: function () {
    }
    },
    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 () {
    clearInterval(Linkedin.data.pageInterval);
    clearInterval(Linkedin.data.nextInterval);
    this.data = {
    pageInterval: null,
    nextInterval: null,
    pageButtons: {},
    pageButtonIndex: 0,
    pageButtonTotal: 0
    };
    },
    sendInvites: function () {

    this.compile();
    this.setScroll();
    this.debug('validing');
    this.compile();
    this.setScroll();
    this.debug('validing');

    if (this.data.pageButtonTotal === 0) {
    if (this.data.pageButtonTotal === 0) {

    this.sleep(this.config.sendSpeed);
    this.sleep(this.config.sendSpeed);

    return this.nextPage();
    }
    return this.nextPage();
    }

    this.sleep(this.data.speed);
    this.sleep(this.data.speed);

    this.debug('sending invite ' + (this.data.pageButtonIndex + 1) + '/' + this.data.pageButtonTotal);
    this.debug('sending invite ' + (this.data.pageButtonIndex + 1) + '/' + this.data.pageButtonTotal);

    var button = this.data.pageButtons[this.data.pageButtonIndex];
    var button = this.data.pageButtons[this.data.pageButtonIndex];

    this.debug('clicking connect');
    $(button).click();
    this.sleep(Linkedin.config.sendSpeed);
    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('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('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('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('close window');
    $("button:contains('Cancel')").click();
    this.sleep(Linkedin.config.sendSpeed);

    if (this.data.pageButtonIndex >= (this.data.pageButtonTotal - 1)) {
    return this.nextPage();
    } else {
    this.data.pageButtonIndex++;
    return this.sendInvites();
    this.debug('ignore confirm mail');
    if ($('[id=email]').length) {
    $('.send-invite__cancel-btn').click();
    }

    this.sleep(Linkedin.config.sendSpeed);

    if (this.data.pageButtonIndex >= (this.data.pageButtonTotal - 1) && this.closeAll()) {
    return this.nextPage();
    } else {
    this.data.pageButtonIndex++;
    return this.sendInvites();
    }
    },
    nextPage: function () {
    Linkedin.debug('find page');
    Linkedin.setScroll();
    Linkedin.data.nextInterval = setInterval(function () {
    var pagerButton = $('.artdeco-pagination__button.artdeco-pagination__button--next[id^=ember]');
    Linkedin.debug('check page link');
    if (pagerButton.length === 0) {
    return false;
    }
    },
    nextPage: function () {
    Linkedin.debug('find page');
    Linkedin.setScroll();
    Linkedin.data.nextInterval = setInterval(function () {
    var pagerButton = $('.artdeco-pagination__button.artdeco-pagination__button--next[id^=ember]');
    Linkedin.debug('check page link');
    if (pagerButton.length === 0) {
    return false;
    }
    clearInterval(Linkedin.data.nextInterval);
    pagerButton.trigger('click');
    Linkedin.setDefaults();
    Linkedin.debug('call next page');
    Linkedin.checkRequest();
    }, Linkedin.config.pagerSpeed);
    },
    checkRequest: function () {
    $(document).ajaxComplete(function () {
    Linkedin.debug('ready');
    Linkedin.resetRequest();
    Linkedin.inspect();
    });
    },
    resetRequest: function () {
    this.debug('reset request');
    $(document).ajaxComplete(function () {
    Linkedin.debug('default request called');
    });
    },
    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) {
    clearInterval(Linkedin.data.pageInterval);
    Linkedin.sendInvites();
    } else {
    Linkedin.debug('listening..');
    }
    }, Linkedin.config.inspectorSpeed);
    clearInterval(Linkedin.data.nextInterval);
    pagerButton.trigger('click');
    Linkedin.setDefaults();
    Linkedin.debug('call next page');
    Linkedin.checkRequest();
    }, Linkedin.config.pagerSpeed);
    },
    checkRequest: function () {
    $(document).ajaxComplete(function () {
    Linkedin.debug('ready');
    Linkedin.resetRequest();
    Linkedin.inspect();
    });
    },
    resetRequest: function () {
    this.debug('reset request');
    $(document).ajaxComplete(function () {
    Linkedin.debug('default request called');
    });
    },
    closeAll: function () {
    if ($('.send-invite__cancel-btn').length) {
    $('.send-invite__cancel-btn').click();
    }
    }).init();
    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) {
    clearInterval(Linkedin.data.pageInterval);
    Linkedin.sendInvites();
    } else {
    Linkedin.debug('listening..');
    }
    }, Linkedin.config.inspectorSpeed);
    }
    }).init();
  5. phpenterprise renamed this gist Jun 5, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. phpenterprise created this gist Jun 5, 2019.
    153 changes: 153 additions & 0 deletions linkedin-auto-connect
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,153 @@
    (Linkedin = {
    data: {},
    config: {
    inspectorSpeed: 2000,
    sendSpeed: 3000,
    pagerSpeed: 10000,
    scrollDownAuto: 500,
    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();
    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 () {
    clearInterval(Linkedin.data.pageInterval);
    clearInterval(Linkedin.data.nextInterval);
    this.data = {
    pageInterval: null,
    nextInterval: null,
    pageButtons: {},
    pageButtonIndex: 0,
    pageButtonTotal: 0
    };
    },
    sendInvites: function () {

    this.compile();
    this.setScroll();
    this.debug('validing');

    if (this.data.pageButtonTotal === 0) {

    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);

    if (this.data.pageButtonIndex >= (this.data.pageButtonTotal - 1)) {
    return this.nextPage();
    } else {
    this.data.pageButtonIndex++;
    return this.sendInvites();
    }
    },
    nextPage: function () {
    Linkedin.debug('find page');
    Linkedin.setScroll();
    Linkedin.data.nextInterval = setInterval(function () {
    var pagerButton = $('.artdeco-pagination__button.artdeco-pagination__button--next[id^=ember]');
    Linkedin.debug('check page link');
    if (pagerButton.length === 0) {
    return false;
    }
    clearInterval(Linkedin.data.nextInterval);
    pagerButton.trigger('click');
    Linkedin.setDefaults();
    Linkedin.debug('call next page');
    Linkedin.checkRequest();
    }, Linkedin.config.pagerSpeed);
    },
    checkRequest: function () {
    $(document).ajaxComplete(function () {
    Linkedin.debug('ready');
    Linkedin.resetRequest();
    Linkedin.inspect();
    });
    },
    resetRequest: function () {
    this.debug('reset request');
    $(document).ajaxComplete(function () {
    Linkedin.debug('default request called');
    });
    },
    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) {
    clearInterval(Linkedin.data.pageInterval);
    Linkedin.sendInvites();
    } else {
    Linkedin.debug('listening..');
    }
    }, Linkedin.config.inspectorSpeed);
    }
    }).init();