Power LinkedIn – Configurable – 1) Auto 'Send Now' on Connect + 2) Expand Profile Description

Configurable LinkedIn power user extensions to automatically 1) clicking Send Now button for Contact Connect requests, and 2) expanding Profile Descriptions. These are enabled by default but can be disabled by editing User Settings part of script. Temporarily skip Auto Send Now by adding connectNote& to URL, as detailed on script support URL page | By Dan Moorehead ([email protected]), PowerAccess™ Framework for MS Access (https://www.PowerAccessDB.com) & Visual3D Game Engine founder

ของเมื่อวันที่ 26-07-2017 ดู เวอร์ชันล่าสุด

// ==UserScript==
// @name		Power LinkedIn – Configurable – 1) Auto 'Send Now' on Connect + 2) Expand Profile Description
// @version		1.1.0
// @description	Configurable LinkedIn power user extensions to automatically 1) clicking Send Now button for Contact Connect requests, and 2) expanding Profile Descriptions. These are enabled by default but can be disabled by editing User Settings part of script. Temporarily skip Auto Send Now by adding connectNote& to URL, as detailed on script support URL page | By Dan Moorehead ([email protected]), PowerAccess™ Framework for MS Access (https://www.PowerAccessDB.com) & Visual3D Game Engine founder
// @author		Dan Moorehead ([email protected]), PowerAccess™ Framework for MS Access (https://www.PowerAccessDB.com/PowerAccess-Framework-MS-Access) and Visual3D Game Engine founder
// @copyright	© 2017 Dan Moorehead ([email protected]), PowerAccess™ Framework for MS Access (https://www.PowerAccessDB.com/PowerAccess-Framework-MS-Access) and Visual3D Game Engine (https://www.PowerAccessDB.com/Visual3D-Game-Engine) founder
// @include		/^https?://(www\.)?linkedin\.com(/.*)?$/
// @namespace	https://www.PowerAccessDB.com/
// @homepage	https://www.PowerAccessDB.com/PowerAccess-Framework-MS-Access
// @supportURL	https://gf.zukizuki.org/en/scripts/31771-linkedin-auto-send-now-connect-requests-for-contacts-skipping-add-a-note-prompt
// @require		https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @grant       none
// @icon		data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAAsSAAALEgHS3X78AAAAFXRF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EN/t/iXDpz+X/JjzgEDYz2vF5r3hLW3XnUSYjazVojlIVibTowSpUSs1Eol8vhKoUSVLpdOMlQmXBKTRvqgUiItKqhhC+ALfVx6MKijHaAAAAAElFTkSuQmCC
// ==/UserScript==


//************ NOTES: ************
//
// Temporarily disable Auto Send Now so you can customize Connect note by adding "connectNote&" to the URL (either after the /? or after adding a ? to the URL if one doesn't already exist) in address bar and pressing Enter.
//
// User Settings: You can enable/disable features by editing the USER SETTINGS: section below, or or change advanced behavior there, by, for example, changing between "= true" and "= false" there
//
// You may be able to slightly optimize this by changing the INCLUDE: rule above to the following, to restrict from running on some pages where is less likely to be needed, though doing so isn't always reliable
//  /^https?://(www\.)?linkedin\.com/(search/results/people/|in/).*$/
//
// To change what pages this runs on without editing this script, you can use the add-in to add a user include rule, such as by going to something like:
//      Greasemonkey (or Tampermonkey, Violentmonkey, etc. - whatever your add-in is) > Dashboard (or Options) > (the name of this LinkedIn Script) > Settings > Includes/Excludes > "Add User Include":
//
// TO-DO:
//
// * Maybe add a settings page you can visit to more easily edit settings without changing the script if have time, such as via one of these methods: https://stackoverflow.com/questions/14594346/create-a-config-or-options-page-for-a-greasemonkey-script/43462416#43462416
// * Anyone, please feel free to improve this script (such as by adding a user settings dialog) and contact me with an updated version to publish
//
//************ END OF NOTES: ************


$(function () {
    'use strict';   //enable function-level strict syntax mode

    //************ USER SETTINGS: ************

    var autoSendNowOnConnect = true;
    var autoExpandProfileDescription = true;

    //************ END OF USER SETTINGS ************


    //************ SELECTORS - TO FIND BUTTONS TO CLICK: Customize only if broken due to LinkedIn changes: ************

    //CSS selector to find any button with text "Send now" which is in an Invite actions modal dialog overlay
    var sendNowOnConnectSelector = 'section.modal div.send-invite__actions > button.button-primary-large.ml3:contains("Send now")';
    var expandProfileSelector = 'button.pv-top-card-section__summary-toggle-button.button-tertiary-small.mt4:contains("See more")';

    //************ END OF SELECTORS ************


    //Utility Functions:

    function getUrlParam(name) {
        //also handles ' ?paramName' with no = or value. If don't want to allow it, then instead use '=([^&#]*)'
        var results = new RegExp('[\?&]' + name + '(=([^&#]*)|(?=[&#])|$)').exec(window.location.href);
        if (results === null) {
            return null; //param not found
        } else {
            return decodeURI(results[1]); //OR: with ' || 0;' to change empty string to 0, for case like "&paramName=&otherParam=val"
        }
    }

    //Advanced Behavior Determined:

    //if user adds "?connectNote="" to the URL of page their visiting, then skip auto-Clicking "Send now" button on Connect
    if(getUrlParam("connectNote") !== null) {
        //disable auto send now, just for this page vist
        autoSendNowOnConnect = false;
    }

    //event to trigger for buttons
    var eventName = 'click';

    //enable handling late added elements (such as Send now button), if needed, depending on options enabled
    var handleLateLoaded = autoSendNowOnConnect;


    //More Utility Functions:

    //find any elements via selector either within whole document or that are within or descendants of members of limitToNodes list
    //then perform click (or whatever event name is defined in eventName variable)
    function clickAll(selector, limitToNodes) {
        if(limitToNodes) {
            //find in descendants of added nodes + then inspect the addedNodes themselves too
            $(limitToNodes).find(selector).addBack(selector).trigger(eventName);
        } else {
            $(selector).trigger(eventName);
        }
    }

    //Perform Script Behavior:

    //begin handling late added elements (such as Send now button), if needed, depending on options enabled
    if (handleLateLoaded) {

        //create alias of MutationObserver class for whatever browser-specific class name is
        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;

        //create observer to inspect elements as added to DOM
        var config = { childList: true, characterData: false, attributes: false, subtree: true };
        var observer = new MutationObserver( function (mutations) {
            mutations.forEach( function (mutation) {
                if (mutation.addedNodes) {
                    //find any "Send now" button in descendants of added nodes + then inspect the addedNodes themselves too
                    //if found, click them

                    if(autoSendNowOnConnect) {
                        clickAll(sendNowOnConnectSelector, mutation.addedNodes);
                    }
                    if(autoExpandProfileDescription) {
                        clickAll(expandProfileSelector);
                    }
                }
            });
        });

        //begin observing any node additions anywhere in the document
        observer.observe(document, config);
    }

    //now auto click any Send now buttons that might already have been loaded before started observing, if enabled
    if(autoSendNowOnConnect) {
        clickAll(sendNowOnConnectSelector);
    }

    //also auto click 'See more' expansion button to see all of profile description, if enabled
    if(autoExpandProfileDescription) {
        clickAll(expandProfileSelector);
    }

});