/*
* Linkedin 1 click connect tools
*
* Version: 1.0-alpha
* This tools is developed based on Chrome for MAC 60.0
* Previous versions support will not be considered
* Use at your own risk
* /
/* Find the embed element */
mainDiv = document.querySelector(".mn-connections-summary__no-top-border-radius.p0");
/* Add the action form to DOM */
form = document.createElement("form");
form.className = "mn-connections-summary ember-view";
mainDiv.appendChild(form);
form.style.width = "90%";
/*
* Button START SCROLL will only scroll the page, and button STOP SCROLL will stop scroll.
* After the scroll process is done, then you can hit the CONNECT All button to connect people on this page.
* ONE CLICK TO CONNECT will auto scroll down and connect people with your settings or default if none available.
*/
form.innerHTML = ''
+ '<lable style="font-size: 10px; text-align: left;">How much time to spare for connecting people? - 10 mins default</lable>'
+ '<input style="margin-top:5px; margin-right: 5px;"class= "time-mins-scroll" placeholder="number of minutes" type="text" name="scroll_time">'
+ '<lable style="font-size: 10px; text-align: left;">Page fresh interval - 5s default</lable>'
+ '<input style="margin-top:5px; margin-right: 5px;"class= "scroll-interval" placeholder="number of seconds" type="text" name="scroll_interval">'
+ '<input style="margin-top:5px; margin-right: 5px;"class= "start-scroll-btn button-secondary-medium" type="button" value="Start scroll">'
+ '<input style="margin-top:5px; margin-right: 5px;"class= "stop-scroll-btn button-secondary-medium" type="button" value="Stop scroll">'
+ '<input style="margin-top:5px; margin-right: 5px;"class= "connect-all-btn button-secondary-medium" type="button" value="Connect all">'
+ '<input style="margin-top:5px; margin-right: 5px;"class= "one-click-connect-btn button-secondary-medium" type="button" value="One Click to Connect all">';
var startScrollBtn = document.querySelector(".start-scroll-btn"),
stopScrollBtn = document.querySelector(".stop-scroll-btn"),
connectAllBtn = document.querySelector(".connect-all-btn"),
oneClickConnectBtn = document.querySelector(".one-click-connect-btn");
var cycleTimes = 0, scrollCycle = 10 * 60, scrollInterval = 5, scrollIntevalInit, peoplesOnPage = {};
(document.querySelector(".time-mins-scroll").value == "") ? scrollCycle = 10 * 60 : scrollCycle = document.querySelector(".time-mins-scroll").value * 60;
(document.querySelector(".scroll-interval").value == "") ? scrollInterval = 5 : scrollInterval = document.querySelector(".scroll-interval").value;
scrollToBottom = function(){
scrollHeight = document.documentElement.scrollHeight;
window.scrollTo(0, scrollHeight);
cycleTimes = cycleTimes + 1;
console.log("page refresh #" + cycleTimes);
};
//@todo 阻止重复点击事件
startScrollBtn.addEventListener("click", function(){
(document.querySelector(".time-mins-scroll").value == "") ? scrollCycle = 10 * 60 : scrollCycle = document.querySelector(".time-mins-scroll").value * 60;
(document.querySelector(".scroll-interval").value == "") ? scrollInterval = 5 : scrollInterval = document.querySelector(".scroll-interval").value;
console.log(scrollCycle);
console.log(scrollInterval);
if(cycleTimes <= (scrollCycle / scrollInterval)){
scrollIntevalInit = setInterval(scrollToBottom, scrollInterval * 1000);
}
}, false);
//@todo 阻止重复点击事件
stopScrollBtn.addEventListener("click",function(){
clearInterval(scrollIntevalInit);
});
connectAllBtn.addEventListener("click",function(){
clearInterval(scrollIntevalInit);
peoplesOnPage = document.querySelectorAll(".mn-pymk-list__action-container .button-secondary-small");
for (var i = 0 ; i < peoplesOnPage.length; i++) {
(function(index){
setTimeout(
function(){
peoplesOnPage[index].click();
console.log("#" + index + "clicked");
}, scrollInterval * index * 1000);
})(i);
}
});
oneClickConnectBtn.addEventListener("click", function () {
(document.querySelector(".time-mins-scroll").value == "") ? scrollCycle = 10 * 60 : scrollCycle = document.querySelector(".time-mins-scroll").value * 60;
(document.querySelector(".scroll-interval").value == "") ? scrollInterval = 5 : scrollInterval = document.querySelector(".scroll-interval").value;
scrollIntevalInit = setInterval(scrollToBottom, scrollInterval * 1000);
if(cycleTimes > (scrollCycle/scrollInterval)){
clearInterval(scrollIntevalInit);
peoplesOnPage = document.querySelectorAll(".mn-pymk-list__action-container .button-secondary-small");
for (var i = 0 ; i < peoplesOnPage.length; i++) {
(function(index){
setTimeout(
function(){
console.log(index);
peoplesOnPage[index].click();
}, scrollInterval * index * 1000);
})(i);
}
}
});
console