-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBrianHessionLinkedInTime.user.js
171 lines (157 loc) · 7.16 KB
/
BrianHessionLinkedInTime.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// ==UserScript==
// @name BrianHessionLinkedInTime
// @namespace http://tampermonkey.net/
// @version 0.1
// @description New script
// @author You
// @include http://*.mturkcontent.com/*
// @include https://*.mturkcontent.com/*
// @include http://*.amazonaws.com/*
// @include https://*.amazonaws.com/*
// @include https://worker.mturk.com/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_addValueChangeListener
// @grant GM_setClipboard
// @grant GM_xmlhttpRequest
// @grant GM_openInTab
// @grant GM_getResourceText
// @grant GM_addStyle
// @grant GM_cookie
// @grant GM.cookie
// @connect google.com
// @connect bing.com
// @connect yellowpages.com
// @connect *
// @require https://raw.githubusercontent.com/hassansin/parse-address/master/parse-address.min.js
// @require https://raw.githubusercontent.com/jacobmas/MTurkScripts/master/js/MTurkScript.js
// @require https://raw.githubusercontent.com/jacobmas/MTurkScripts/master/Govt/Government.js
// @require https://raw.githubusercontent.com/jacobmas/MTurkScripts/master/global/Address.js
// @require https://raw.githubusercontent.com/jacobmas/MTurkScripts/master/global/AggParser.js
// @require https://raw.githubusercontent.com/jacobmas/MTurkScripts/master/Email/MailTester.js
// @require https://raw.githubusercontent.com/spencermountain/compromise/master/builds/compromise.min.js
// @resource GlobalCSS https://raw.githubusercontent.com/jacobmas/MTurkScripts/master/global/globalcss.css
// ==/UserScript==
(function() {
'use strict';
var my_query = {};
var bad_urls=[];
/* TODO should be requester #, last field should be if it's crowd or not */
var MTurk=new MTurkScript(20000,750+(Math.random()*1000),[],begin_script,"A3JYN1EC66FOSU",true);
var MTP=MTurkScript.prototype;
var month_list={"Jan":"01","Feb":"02","Mar":"03","Apr":"04","May":"05","Jun":"06","Jul":"07","Aug":"08","Sep":"09","Oct":"10","Nov":"11","Dec":"12"};
function is_bad_name(b_name)
{
return false;
}
function query_response(response,resolve,reject,type) {
var doc = new DOMParser()
.parseFromString(response.responseText, "text/html");
console.log("in query_response\n"+response.finalUrl+", type="+type);
var search, b_algo, i=0, inner_a;
var b_url="crunchbase.com", b_name, b_factrow,lgb_info, b_caption,p_caption;
var b1_success=false, b_header_search,b_context,parsed_context,parsed_lgb;
try
{
search=doc.getElementById("b_content");
b_algo=search.getElementsByClassName("b_algo");
lgb_info=doc.getElementById("lgb_info");
b_context=doc.getElementById("b_context");
console.log("b_algo.length="+b_algo.length);
if(b_context&&(parsed_context=MTP.parse_b_context(b_context))) {
console.log("parsed_context="+JSON.stringify(parsed_context));
if(parsed_context.person&&parsed_context.person.experience&&parsed_context.person.experience.length>0) {
if(MTP.matches_names(my_query.short_company,parsed_context.person.experience[0].company)) {
let my_time=parsed_context.person.experience[0].time;
let split_time=my_time.split(" - ");
if(split_time.length===2){
if(/Present/i.test(split_time[1])) {
document.querySelector("#present").click();
}
else {
let split_second=split_time[1].split(" ");
document.querySelector("#endMonth").value=month_list[split_second[0]];
document.querySelector("#endYear").value=split_second[1];
}
let split_first=split_time[0].split(" ");
document.querySelector("#startMonth").value=month_list[split_first[0]];
document.querySelector("#startYear").value=split_first[1];
resolve("");
}
}
}
}
if(b1_success && (resolve(b_url)||true)) return;
}
catch(error) {
reject(error);
return;
}
do_next_query(resolve,reject,type);
return;
}
function do_next_query(resolve,reject,type) {
reject("Nothing found");
}
/* Search on bing for search_str, parse bing response with callback */
function query_search(search_str, resolve,reject, callback,type,filters) {
console.log("Searching with bing for "+search_str);
if(!filters) filters="";
var search_URIBing='https://www.bing.com/search?q='+
encodeURIComponent(search_str)+"&filters="+filters+"&first=1&rdr=1";
GM_xmlhttpRequest({method: 'GET', url: search_URIBing,
onload: function(response) { callback(response, resolve, reject,type); },
onerror: function(response) { reject("Fail"); },ontimeout: function(response) { reject("Fail"); }
});
}
/* Following the finding the district stuff */
function query_promise_then(result) {
submit_if_done();
}
function begin_script(timeout,total_time,callback) {
if(timeout===undefined) timeout=200;
if(total_time===undefined) total_time=0;
if(callback===undefined) callback=init_Query;
if(MTurk!==undefined) { callback(); }
else if(total_time<2000) {
console.log("total_time="+total_time);
total_time+=timeout;
setTimeout(function() { begin_script(timeout,total_time,callback); },timeout);
return;
}
else { console.log("Failed to begin script"); }
}
function add_to_sheet() {
var x,field;
for(x in my_query.fields) {
if((MTurk.is_crowd && (field=document.getElementsByName(x)[0])) ||
(!MTurk.is_crowd && (field=document.getElementById(x)))) field.value=my_query.fields[x];
}
}
function submit_if_done() {
var is_done=true,x;
add_to_sheet();
for(x in my_query.done) if(!my_query.done[x]) is_done=false;
if(is_done && !my_query.submitted && (my_query.submitted=true)) MTurk.check_and_submit();
}
function init_Query()
{
console.log("in init_query");
var i;
var url=document.querySelector("crowd-form a").href;
var company=document.querySelectorAll("crowd-form div p")[1].innerText.trim().replace(/^[^:]*:\s*/,"");
my_query={name:"",company:company, short_company:MTP.shorten_company_name(company), url:url,fields:{},done:{},
try_count:{"query":0},
submitted:false};
console.log("my_query="+JSON.stringify(my_query));
var search_str=my_query.url;
const queryPromise = new Promise((resolve, reject) => {
console.log("Beginning URL search");
query_search(search_str, resolve, reject, query_response,"query");
});
queryPromise.then(query_promise_then)
.catch(function(val) {
console.log("Failed at this queryPromise " + val); GM_setValue("returnHit",true); });
}
})();