Linkedin Connect

Connect every possible user with your message

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Linkedin Connect
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Connect every possible user with your message
// @include     https://www.linkedin.com/search/results/people/*hiring*
// @include     https://www.linkedin.com/search/results/people/*Hiring*
// @grant        none

// ==/UserScript==




const msg = "Hi, I’m a Master’s student at Carnegie Mellon University. We are going to build a mobile app that makes the hiring process more efficient. Do you mind taking a quick survey so we can learn more about the hiring process? Thank you!\nThe survey link: https://forms.gle/NydUPcn8XzrSHoX2A"

const styles = `
.fixedElement {
background-color: white;
position:fixed;
top:0;
right:0;
width:40vw;
z-index:100;
}
`;
const styleSheet = document.createElement("style");
styleSheet.type = "text/css";
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);

var div
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
async function startConnect() {
    await sleep(1000);
    window.scrollTo(0, document.body.scrollHeight);
    await sleep(2000);
    const allButtons = document.querySelectorAll('button')
    const buttons = []
    for (const button of allButtons)
        if (button.innerText === 'Connect') buttons.push(button);
    while (buttons.length !== 0) {
        const button = buttons.pop()
        const parent = button.parentNode.parentNode.parentNode
        console.log(parent.querySelector('a').href)
        let b = document.createElement("p");
        b.innerText = parent.querySelector('a').href;
        //div.appendChild(b);
        button.click()
        await sleep(500);
        const addNoteButton = document.querySelector('[aria-label="Add a note"]');
        console.log(addNoteButton)
        addNoteButton.click()
        await sleep(500);
        const textareaMsg = document.querySelector("textarea")
        textareaMsg.value = msg
        var evt = document.createEvent("Events");
        evt.initEvent("change", true, true);
        textareaMsg.dispatchEvent(evt);
        await sleep(100)
        const doneButton = document.querySelector('[aria-label="Done"]')?document.querySelector('[aria-label="Done"]'):document.querySelector('[aria-label="Send invitation"]');
        if (doneButton.disabled) {
            document.querySelector('[aria-label="Dismiss"]').click();
            await sleep(1000)
        }
        doneButton.click()
        await sleep(1000)
        console.log("first finished")

    }
    const previousButton = document.querySelector('[aria-label="Next"]');
    previousButton.click()
}
var pushState = history.pushState;
history.pushState = function () {
    pushState.apply(history, arguments);
    const re = new RegExp("https://www.linkedin.com/search/results/people/.*hiring.*")
    if (document.URL.toLowerCase().match(re))
        startConnect()
};
window.addEventListener('load', ()=>{
    div = document.createElement("div");
    div.classList.add("fixedElement");
    document.body.appendChild(div);
    startConnect()
}, false);