From 876d23c41ebc2104b214f6e1072c957031d8f09a Mon Sep 17 00:00:00 2001 From: Eric Engoron Date: Sat, 11 Mar 2017 16:31:32 -0500 Subject: [PATCH 1/6] Fixed LinkedIn to work with New Layout --- js/contentscript.js | 178 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 139 insertions(+), 39 deletions(-) diff --git a/js/contentscript.js b/js/contentscript.js index 57395e3..f62db32 100644 --- a/js/contentscript.js +++ b/js/contentscript.js @@ -71,6 +71,22 @@ function getQueryParam(href, query) { } } +function isInUS(location) +{ + +//Is a location in the US? Used to choose State Vs. Country in Address fields with 1 comma on LinkedIn. + + array = ['Alabama','Alaska','American Samoa','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Federated States of Micronesia','Florida','Georgia','Guam','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Marshall Islands','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Northern Mariana Islands','Ohio','Oklahoma','Oregon','Palau','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virgin Island','Virginia','Washington','West Virginia','Wisconsin','Wyoming']; + for(var i = 0; i < array.length; i++) + { + if(array[i] === location) + { + return true; + } + } + + return false; +} function handleFacebook() { // Sample pages to test: @@ -139,79 +155,163 @@ function handleFacebook() { } function handleLinkedIn() { - var posatcom = $("p.title").text().trim().split(" at "); - var name = $("span.full-name").text(); - var phone = $("div#phone-view").find('li').first().text().match(/[\+\d\s\-]+/); + //open contact panel for contact data + //note: Due to a weird linkedin bug, for the panel to be opened via code on successive linkedin leads, without refreshing the browser, the button must be clicked twice. + if($("button.contact-see-more-less.link-without-visited-state").attr("data-control-name") === "contact_see_more") + { + $("button.contact-see-more-less.link-without-visited-state").click(); + + if($("button.contact-see-more-less.link-without-visited-state").attr("data-control-name") === "contact_see_more") + $("button.contact-see-more-less.link-without-visited-state").click(); + } + + //Company and position + var posatcom = $("div.pv-top-card-section__information.mt3").find("h2").first().text().trim().split(" at "); + + //Name of Contact + var name = $("div.pv-top-card-section__information.mt3").find("h1").first().text(); + //*******Description Stuff **************\\ + //When description is truncated, get full description + var description = $("div.truncate-multiline--truncation-target").find("span").first().text().trim() + " " + $("div.truncate-multiline--truncation-target").find("span").last().text().trim(); + //When the description is not truncated, get full description + if(description === " ") + { + description = $("div.pv-top-card-section__rich-content.ph2").find("p").first().text().trim(); + //remove show less from description text + description = description.slice(0, -16); + + } + + //For extremely short descriptions + else if ($("div.truncate-multiline--truncation-target").find("span").first().text().trim() === $("div.truncate-multiline--truncation-target").find("span").last().text().trim()) + description = $("div.truncate-multiline--truncation-target").find("span").first().text(); + + + //Get Phone Number from Contact Details + var phone = $("section.pv-contact-info__contact-type.ci-phone").find("li").first().text().match(/[\+\d\s\-\.]+/); if (phone && phone.length > 0) { phone = $.trim(phone[0]); } - // old style ************************************ - var old_phone; - var old_nums = $("li.abook-phone").toArray(); - if (old_nums.length > 0) { - old_phone = old_nums[0].innerText.split(" ")[0]; + phone = phone || ""; + + //Get Email Address From Contact Details + var email = $("section.pv-contact-info__contact-type.ci-email").find("span").last().text().trim(); + + //parse addresses on linkedin + var address_full = document.getElementsByClassName("pv-top-card-section__location Sans-15px-black-55% mb1 inline-block")[0].innerHTML|| "" ; + address_full = address_full.replace('Area', ''); + address_full = address_full.replace('Greater', ''); + address_full = address_full.trim(); + var city = "", state = "", country = "", address_1 = ""; + var address = address_full.split(','); + + if(address.length === 3) + { + city = address[0]; + state = address [1]; + country = address [2]; } - var twitterHandle = ""; - var twitteriframe = $('.twitter-follow-button')[0]; - if (twitteriframe && twitteriframe.src) { - var matches = twitteriframe.src.match(/screen_name=\w+/); - if (matches.length > 0) { - twitterhandle = matches[0].substr("screen_name=".length); + else if(address.length == 2) + { + if(isInUS(address[1].trim())) + { + city = address[0]; + state = address[1]; + } + + else + { + city = address[0]; + country = address[1]; } } - var site = $("a[name=overviewsite]").attr('href'); - site = site? site.slice(20,-13) : ''; - // ********************************** + else + address_1 = address[0]; + + //get all website urls + var website_urls = $("section.pv-contact-info__contact-type.ci-websites").find("li").toArray(); + + //for skype in the future. + //var im_names = $("section.pv-contact-info__contact-type.ci-ims").find("li").toArray(); + + //get twitter handle for contact + var twitterHandle = $("section.pv-contact-info__contact-type.ci-twitter").find('a').first().attr("href") || ""; - phone = phone || old_phone || ""; - var email = $("div#email-view").find('a').first().text() || $("li.abook-email").children('a').text() || ""; - var description = $("p.description").text() || ""; - var url = $("div#website-view").find('a').first().attr('href') || unescape(site) || ""; - if (url && url.indexOf('http') !== 0) { - url = 'http://linkedin.com' + url; - } - var address = $("span.locality").children().text() || ""; var lead = {}; - if (posatcom[1]) lead.name = posatcom[1]; + if (posatcom[1]) + lead.name = posatcom[1]; lead.contacts = [ { name: name ? name : null, - emails: email ? [{ email: email, type: 'office' }] : [], - title: posatcom[0] ? posatcom[0] : null, - phones: phone ? [{ phone: phone, type: 'office' }]: [], + emails: email ? [{ 'email': email, 'type': 'office' }] : [], + title: posatcom[0] ? posatcom [0] : null, + phones: phone ? [{ 'phone': phone, 'type': 'office' }]: [], urls: [] } ]; + + //url for this lead being created defaults to the linkedin-url if no company website is in contact details + lead.url = window.location.href; - if (url) lead.url = url; - - if (description) lead.description = description; + //description of lead taken from linkedin profile + if (description) + lead.description = description; - if (address) lead.addresses = [{ address_1: address }]; + //push address to lead + if (address) + lead.addresses = [{ 'state': state.trim(), 'city': city.trim(), 'country' : country.trim(), 'address_1': address_1.trim() }]; lead.custom = { source: 'LinkedIn' }; - var twitter = $("div#twitter-view").find('a').first().text() || twitterHandle || ""; - var profile = $("dl.public-profile").find('span').text() || $("dl.public-profile").find('a').attr('href') || ""; - //var industry = $("dd.industry").children().text() || ""; + var twitter = twitterHandle || ""; + var websites = website_urls || ""; + //push twitter handle to lead if (twitter) { - lead.contacts[0].urls.push({ url: 'https://twitter.com/' + twitter, type: 'url' }); + lead.contacts[0].urls.push({ 'url': twitter, 'type': 'url' }); } - if (profile) { - lead.contacts[0].urls.push({ url: profile, type: 'url' }); + + //push website url to lead + if (websites) { + for (var i=0, len=website_urls.length; i < len; i++) + { + var website_link = $(website_urls[i]).find('a').first().attr("href"); + var website_type = $(website_urls[i]).find('span').first().text().trim(); + //if it's a company website, change the url of the main lead + if(website_type === "(Company Website)") + lead.url = website_link; + else + lead.contacts[0].urls.push({ 'url': website_link, 'type': 'url' }); + } } + //push skype urls to lead (for the future) + // if(im_names) + // { + // for (var k=0, leng=im_names.length; k < leng; k++) + // { + // var handle = $(im_names[k]).find("span").text(); + // var str_open_paren = handle.split('(')[1]; + // var platform = str_open_paren.split(')')[0].trim(); + // if(platform === "Skype") + // { + // var skype_handle = handle.split('(')[0].trim(); + // //lead.contacts[0].urls.push({ 'url': "skype://" + skype_handle, 'type': 'url' }); + // } + + // } + // } + return lead; } From 02508e45663edc9ce498444ca2146b93942f2eac Mon Sep 17 00:00:00 2001 From: Eric Engoron Date: Sat, 11 Mar 2017 17:09:56 -0500 Subject: [PATCH 2/6] Fixed LinkedIn for new layout -- Better Format --- js/contentscript.js | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/js/contentscript.js b/js/contentscript.js index f62db32..9a89560 100644 --- a/js/contentscript.js +++ b/js/contentscript.js @@ -76,13 +76,16 @@ function isInUS(location) //Is a location in the US? Used to choose State Vs. Country in Address fields with 1 comma on LinkedIn. - array = ['Alabama','Alaska','American Samoa','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Federated States of Micronesia','Florida','Georgia','Guam','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Marshall Islands','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Northern Mariana Islands','Ohio','Oklahoma','Oregon','Palau','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virgin Island','Virginia','Washington','West Virginia','Wisconsin','Wyoming']; +var array = ['Alabama','Alaska','American Samoa','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Federated States of Micronesia','Florida','Georgia','Guam','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Marshall Islands','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Northern Mariana Islands','Ohio','Oklahoma','Oregon','Palau','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virgin Island','Virginia','Washington','West Virginia','Wisconsin','Wyoming']; for(var i = 0; i < array.length; i++) { + if(array[i] === location) { + return true; } + } return false; @@ -235,9 +238,6 @@ function handleLinkedIn() { //get all website urls var website_urls = $("section.pv-contact-info__contact-type.ci-websites").find("li").toArray(); - - //for skype in the future. - //var im_names = $("section.pv-contact-info__contact-type.ci-ims").find("li").toArray(); //get twitter handle for contact var twitterHandle = $("section.pv-contact-info__contact-type.ci-twitter").find('a').first().attr("href") || ""; @@ -263,55 +263,44 @@ function handleLinkedIn() { //description of lead taken from linkedin profile if (description) + { lead.description = description; + } //push address to lead if (address) + { lead.addresses = [{ 'state': state.trim(), 'city': city.trim(), 'country' : country.trim(), 'address_1': address_1.trim() }]; - - lead.custom = { - source: 'LinkedIn' - }; + } + + lead.custom = {'source': 'LinkedIn'}; var twitter = twitterHandle || ""; var websites = website_urls || ""; //push twitter handle to lead - if (twitter) { + if (twitter) + { lead.contacts[0].urls.push({ 'url': twitter, 'type': 'url' }); } //push website url to lead - if (websites) { - for (var i=0, len=website_urls.length; i < len; i++) + if (websites) + { + for (var i = 0, len = website_urls.length; i < len; i++) { var website_link = $(website_urls[i]).find('a').first().attr("href"); var website_type = $(website_urls[i]).find('span').first().text().trim(); + //if it's a company website, change the url of the main lead if(website_type === "(Company Website)") lead.url = website_link; + else lead.contacts[0].urls.push({ 'url': website_link, 'type': 'url' }); } } - //push skype urls to lead (for the future) - // if(im_names) - // { - // for (var k=0, leng=im_names.length; k < leng; k++) - // { - // var handle = $(im_names[k]).find("span").text(); - // var str_open_paren = handle.split('(')[1]; - // var platform = str_open_paren.split(')')[0].trim(); - // if(platform === "Skype") - // { - // var skype_handle = handle.split('(')[0].trim(); - // //lead.contacts[0].urls.push({ 'url': "skype://" + skype_handle, 'type': 'url' }); - // } - - // } - // } - return lead; } From 61483534a4b08adc59b7db78dbab0dcddab60c7e Mon Sep 17 00:00:00 2001 From: Eric Engoron Date: Sat, 11 Mar 2017 17:12:51 -0500 Subject: [PATCH 3/6] Fixed LinkedIn for new layout -- Better Format --- js/contentscript.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/js/contentscript.js b/js/contentscript.js index 9a89560..025cc74 100644 --- a/js/contentscript.js +++ b/js/contentscript.js @@ -76,19 +76,19 @@ function isInUS(location) //Is a location in the US? Used to choose State Vs. Country in Address fields with 1 comma on LinkedIn. -var array = ['Alabama','Alaska','American Samoa','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Federated States of Micronesia','Florida','Georgia','Guam','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Marshall Islands','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Northern Mariana Islands','Ohio','Oklahoma','Oregon','Palau','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virgin Island','Virginia','Washington','West Virginia','Wisconsin','Wyoming']; - for(var i = 0; i < array.length; i++) - { - - if(array[i] === location) + var array = ['Alabama','Alaska','American Samoa','Arizona','Arkansas','California','Colorado','Connecticut','Delaware','District of Columbia','Federated States of Micronesia','Florida','Georgia','Guam','Hawaii','Idaho','Illinois','Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Marshall Islands','Maryland','Massachusetts','Michigan','Minnesota','Mississippi','Missouri','Montana','Nebraska','Nevada','New Hampshire','New Jersey','New Mexico','New York','North Carolina','North Dakota','Northern Mariana Islands','Ohio','Oklahoma','Oregon','Palau','Pennsylvania','Puerto Rico','Rhode Island','South Carolina','South Dakota','Tennessee','Texas','Utah','Vermont','Virgin Island','Virginia','Washington','West Virginia','Wisconsin','Wyoming']; + for(var i = 0; i < array.length; i++) { + + if(array[i] === location) + { - return true; - } + return true; + } - } + } - return false; + return false; } function handleFacebook() { From 3bbb09373a786de49e442758e2d3c2508bcbd2a4 Mon Sep 17 00:00:00 2001 From: Eric Engoron Date: Sat, 11 Mar 2017 17:13:45 -0500 Subject: [PATCH 4/6] Fixed LinkedIn for new layout -- Better Format --- js/contentscript.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/contentscript.js b/js/contentscript.js index 025cc74..fbebd7b 100644 --- a/js/contentscript.js +++ b/js/contentscript.js @@ -82,8 +82,7 @@ function isInUS(location) if(array[i] === location) { - - return true; + return true; } } From c96c37f5066ac41d30285b6c3dde8e24c5f28e4c Mon Sep 17 00:00:00 2001 From: Eric Engoron Date: Sat, 11 Mar 2017 17:59:42 -0500 Subject: [PATCH 5/6] Fixed Yelp Name Issue --- js/contentscript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/contentscript.js b/js/contentscript.js index fbebd7b..972ade1 100644 --- a/js/contentscript.js +++ b/js/contentscript.js @@ -328,7 +328,7 @@ function handleGitHub() { function handleYelp() { var url = getQueryParam($('.biz-website a').attr('href'), 'url'); var lead = { - name: $('h1[itemprop="name"]').text().trim(), + name: $('h1.biz-page-title.embossed-text-white').text().trim(), url: url, addresses: [], contacts: [ From a54a6a6a17f9ceea2d02fe7d2cc304d48e78107a Mon Sep 17 00:00:00 2001 From: Eric Engoron Date: Sat, 11 Mar 2017 18:43:04 -0500 Subject: [PATCH 6/6] Fixed Yelp Country Issue #5 --- js/contentscript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/contentscript.js b/js/contentscript.js index 972ade1..6b512e9 100644 --- a/js/contentscript.js +++ b/js/contentscript.js @@ -358,7 +358,7 @@ function handleYelp() { address.city = $('span[itemprop="addressLocality"]').text().trim(); address.state = $('span[itemprop="addressRegion"]').text().trim(); address.zipcode = $('span[itemprop="postalCode"]').text().trim(); - address.country = $('span[itemprop="addressCountry"]').text().trim(); + address.country = $('meta[itemprop="addressCountry"]').attr("content").trim(); lead.addresses.push(address); }