· 9 years ago · Nov 16, 2016, 03:20 PM
1// ==UserScript==
2// @name Super Thursday Helper
3// @namespace http://fitzalanpartners.co.uk/
4// @version 1.0
5// @description Lets help Cordelia generate some happy leads!
6// @author Mark Williams
7// @match http://81.201.129.38/leadtracker/lead/edit/*
8// @grant none
9// ==/UserScript==
10
11(function() {
12
13 //Easiest way to discover the brand is to check the site logo.
14 var logoString = $('#site-logo').attr('src').split('/');
15 var brandString = logoString[logoString.length - 1];
16
17 //The customer reference is unique. It is always the second child in the quote-info section
18 var customerRef = $('#quote-info > tbody > tr:nth-child(2) > td').text();
19
20 //This only collects the customers firstname. Although family names are available in LT if required.
21 var customerName = $('#edit-firstname').val().split(" ")[0];
22
23 //read customer email
24 var customerEmail = $('#edit-email').val();
25
26 //read customer quote type
27 var customerQuoteType = $('#quote-info > tbody > tr:nth-child(4) > td').text();
28
29 var paneledTo = " REPACE ME ";
30 var leadOwner = $('#edit-owner option:selected').text().split(" ")[0];
31
32 if(customerQuoteType == 'HomeBuyer Report'){
33 paneledTo = $("#edit-suid option:selected").text();
34 }else{
35 paneledTo = $('#edit-soid option[selected]').text().split('|')[0];
36 }
37
38 //the brand e.g. SurveyorLocal
39 var brand = '';
40
41 var brandFriendlyName = '';
42
43 //a secret key is required for each brand. this is used in combination with email and customer reference to
44 //generate the SHA1 hash required to authenticate with Trustpilot
45 var secretkey = '';
46 var hash ='';
47
48 //discover brand based on image logo
49 switch (brandString){
50 case 'SL.png':
51 brand = 'surveyorlocal.co.uk';
52 secretkey = 'g56pw39ak72mi84ez48qs96yf72nx53o';
53 brandFriendlyName = 'Surveyor Local';
54 break;
55 case 'ID.png':
56 brand = 'in-deed.net';
57 secretkey = 'f24ka95pc68oy37qm89gs43dj25zt67x';
58 brandFriendlyName = 'In-Deed';
59 break;
60 case 'HL.png':
61 brand = 'homewardlegal.co.uk';
62 secretkey = 'n95fm63sd84ok27ax58pt97bz42wq63y';
63 brandFriendlyName = 'Homeward Legal';
64 break;
65 case 'BV.png':
66 brand = 'bestvalueconveyancing.co.uk';
67 secretkey = 'f84na65rx93gq72jd38zo59pw67ib24t';
68 brandFriendlyName = 'Best Value Conveyancing';
69 break;
70 case 'FM.png':
71 brand = 'fridaysmove.com';
72 secretkey = 'd56it23ng48rs97py32qk74zb89oc56f';
73 brandFriendlyName = 'Fridaysmove';
74 break;
75 case 'BVS.png':
76 brand = 'bestvaluesurveys.co.uk';
77 secretkey = 'k97rb84nt23dx56ai57cj49so68yw32z';
78 brandFriendlyName = 'Best Value Surveys';
79 break;
80 case 'UNKNOWN.png':
81 brand = 'thesolicitorfinder.com';
82 secretkey = 'i45ps93ae72md86yz79xr86nq34jo52b';
83 brandFriendlyName = 'The Solicitor Finder';
84 break;
85 default:
86 }
87 //generate sha1 hash required for trustpilot. Implementation at bottom of this file.
88 //see http://pajhome.org.uk/crypt/md5 for details.
89 hash = hex_sha1(secretkey+customerEmail+customerRef);
90 var tplink = encodeURIComponent("http://www.trustpilot.co.uk/evaluate/" + brand + "?&a=" + customerRef + "&b=" + btoa(customerEmail) + "&c=" + customerName + "&e=" + hash);
91 //console.log(tplink);
92
93 function homewardQuickFix1(brand){
94 if(brand == 'homewardlegal.co.uk'){
95 return 'If you leave your review before the end of the month, you will be entered into a draw to win one of three £25 Amazon giftcards!';
96 }
97 return '';
98 }
99 function homewardQuickFix2(brand){
100 if(brand == 'homewardlegal.co.uk'){
101 return 'The prize draw winners will be randomly selected from those who have left a Homeward Legal review between 5th and 30th September, and they will be notified on Tuesday 4th October.';
102 }
103 return '';
104 }
105
106
107
108
109 //append happy_lead section to navmenu and bind click event. the user will be able to copy the trustpilot link
110 $('#nav-buttons').append( '<a id="happy_lead" style="background-color:green;"><div class="nav-icon" style="font-size:21px">:)</div><span style="font-size:11px;">Happy Lead</span></a>' );
111 $("#happy_lead").click(function(){
112 copyToClipboard("http://www.trustpilot.co.uk/evaluate/" + brand + "?&a=" + customerRef + "&b=" + btoa(customerEmail) + "&c=" + customerName + "&e=" + hash);
113 });
114
115 //append excel_content to navmenu and bind click event. the user will be able to copy a string to import data into excel spreadsheets
116 $('#nav-buttons').append( '<a id="excel_content" style="background-color:green;"><div class="nav-icon" style="font-size:21px">⎘</div><span style="font-size:11px;">Excel Export</span></a>' );
117 $("#excel_content").click(function(){
118 copyToClipboard(
119 '' + brand +
120 ';' + secretkey +
121 ';' + customerName +
122 ';' + customerEmail +
123 ';' + customerRef +
124 ';' + "http://www.trustpilot.co.uk/evaluate/" + brand + "?&a=" + customerRef + "&b=" + btoa(customerEmail) + "&c=" + customerName + "&e=" + hash
125 );
126 });
127
128
129 //append happy_lead section to navmenu and bind click event. the user will be able to copy the trustpilot link
130 $('#nav-buttons').append( '<a id="happy_mail" style="background-color:green;"><div class="nav-icon" style="font-size:21px">✉</div><span style="font-size:11px;">Generate Email</span></a>');
131 $("#happy_mail").click(function(){
132 window.location.href = "mailto:"+customerEmail+"?subject="+ customerName + "%20-%20about%20your%20"+customerQuoteType+"&body=Hello " + customerName +", %0D%0A\
133%0D%0A\
134I hope you are having a good week. %0D%0A\
135%0D%0A\
136I’m delighted that you chose "+brandFriendlyName+" to arrange your "+customerQuoteType+", and am pleased to see that you’ve received your welcome call from " + paneledTo + ". %0D%0A\
137%0D%0A\
138I hope that you were happy with the service you received from "+leadOwner+", and would like to ask if you have a moment to leave your feedback? " + "%0D%0A\
139%0D%0A\
140Please click here to rate the " + brandFriendlyName + " service. "+ tplink + " %0D%0A\
141%0D%0A\
142Though you are now being looked after by your solicitor, we are still here to answer any questions you may have along the way. %0D%0A\
143%0D%0A\
144Wishing you the best of luck with your " + customerQuoteType + "!%0D%0A\
145%0D%0A\
146Many thanks,%0D%0A\
147%0D%0A\
148Cordelia %0D%0A\
149"+brandFriendlyName+" %0D%0A\
150";
151 });
152
153 function copyToClipboard(text) {
154 window.prompt("Copy to clipboard: Ctrl+C, Enter", text);
155 }
156
157 /*
158* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
159* in FIPS 180-1
160* Version 2.2 Copyright Paul Johnston 2000 - 2009.
161* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
162* Distributed under the BSD License
163* See http://pajhome.org.uk/crypt/md5 for details.
164*/
165
166/*
167* Configurable variables. You may need to tweak these to be compatible with
168* the server-side, but the defaults work in most cases.
169*/
170var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
171var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
172
173/*
174* These are the functions you'll usually want to call
175* They take string arguments and return either hex or base-64 encoded strings
176*/
177function hex_sha1(s) { return rstr2hex(rstr_sha1(str2rstr_utf8(s))); }
178function b64_sha1(s) { return rstr2b64(rstr_sha1(str2rstr_utf8(s))); }
179function any_sha1(s, e) { return rstr2any(rstr_sha1(str2rstr_utf8(s)), e); }
180function hex_hmac_sha1(k, d)
181 { return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }
182function b64_hmac_sha1(k, d)
183 { return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }
184function any_hmac_sha1(k, d, e)
185 { return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
186
187/*
188* Perform a simple self-test to see if the VM is working
189*/
190function sha1_vm_test()
191{
192 return hex_sha1("abc").toLowerCase() == "a9993e364706816aba3e25717850c26c9cd0d89d";
193}
194
195/*
196* Calculate the SHA1 of a raw string
197*/
198function rstr_sha1(s)
199{
200 return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8));
201}
202
203/*
204* Calculate the HMAC-SHA1 of a key and some data (raw strings)
205*/
206function rstr_hmac_sha1(key, data)
207{
208 var bkey = rstr2binb(key);
209 if(bkey.length > 16) bkey = binb_sha1(bkey, key.length * 8);
210
211 var ipad = Array(16), opad = Array(16);
212 for(var i = 0; i < 16; i++)
213 {
214 ipad[i] = bkey[i] ^ 0x36363636;
215 opad[i] = bkey[i] ^ 0x5C5C5C5C;
216 }
217
218 var hash = binb_sha1(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
219 return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160));
220}
221
222/*
223* Convert a raw string to a hex string
224*/
225function rstr2hex(input)
226{
227 try { hexcase } catch(e) { hexcase=0; }
228 var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
229 var output = "";
230 var x;
231 for(var i = 0; i < input.length; i++)
232 {
233 x = input.charCodeAt(i);
234 output += hex_tab.charAt((x >>> 4) & 0x0F)
235 + hex_tab.charAt( x & 0x0F);
236 }
237 return output;
238}
239
240/*
241* Convert a raw string to a base-64 string
242*/
243function rstr2b64(input)
244{
245 try { b64pad } catch(e) { b64pad=''; }
246 var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
247 var output = "";
248 var len = input.length;
249 for(var i = 0; i < len; i += 3)
250 {
251 var triplet = (input.charCodeAt(i) << 16)
252 | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
253 | (i + 2 < len ? input.charCodeAt(i+2) : 0);
254 for(var j = 0; j < 4; j++)
255 {
256 if(i * 8 + j * 6 > input.length * 8) output += b64pad;
257 else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
258 }
259 }
260 return output;
261}
262
263/*
264* Convert a raw string to an arbitrary string encoding
265*/
266function rstr2any(input, encoding)
267{
268 var divisor = encoding.length;
269 var remainders = Array();
270 var i, q, x, quotient;
271
272 /* Convert to an array of 16-bit big-endian values, forming the dividend */
273 var dividend = Array(Math.ceil(input.length / 2));
274 for(i = 0; i < dividend.length; i++)
275 {
276 dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
277 }
278
279 /*
280 * Repeatedly perform a long division. The binary array forms the dividend,
281 * the length of the encoding is the divisor. Once computed, the quotient
282 * forms the dividend for the next step. We stop when the dividend is zero.
283 * All remainders are stored for later use.
284 */
285 while(dividend.length > 0)
286 {
287 quotient = Array();
288 x = 0;
289 for(i = 0; i < dividend.length; i++)
290 {
291 x = (x << 16) + dividend[i];
292 q = Math.floor(x / divisor);
293 x -= q * divisor;
294 if(quotient.length > 0 || q > 0)
295 quotient[quotient.length] = q;
296 }
297 remainders[remainders.length] = x;
298 dividend = quotient;
299 }
300
301 /* Convert the remainders to the output string */
302 var output = "";
303 for(i = remainders.length - 1; i >= 0; i--)
304 output += encoding.charAt(remainders[i]);
305
306 /* Append leading zero equivalents */
307 var full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));
308 for(i = output.length; i < full_length; i++)
309 output = encoding[0] + output;
310
311 return output;
312}
313
314/*
315* Encode a string as utf-8.
316* For efficiency, this assumes the input is valid utf-16.
317*/
318function str2rstr_utf8(input)
319{
320 var output = "";
321 var i = -1;
322 var x, y;
323
324 while(++i < input.length)
325 {
326 /* Decode utf-16 surrogate pairs */
327 x = input.charCodeAt(i);
328 y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
329 if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
330 {
331 x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
332 i++;
333 }
334
335 /* Encode output as utf-8 */
336 if(x <= 0x7F)
337 output += String.fromCharCode(x);
338 else if(x <= 0x7FF)
339 output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
340 0x80 | ( x & 0x3F));
341 else if(x <= 0xFFFF)
342 output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
343 0x80 | ((x >>> 6 ) & 0x3F),
344 0x80 | ( x & 0x3F));
345 else if(x <= 0x1FFFFF)
346 output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
347 0x80 | ((x >>> 12) & 0x3F),
348 0x80 | ((x >>> 6 ) & 0x3F),
349 0x80 | ( x & 0x3F));
350 }
351 return output;
352}
353
354/*
355* Encode a string as utf-16
356*/
357function str2rstr_utf16le(input)
358{
359 var output = "";
360 for(var i = 0; i < input.length; i++)
361 output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
362 (input.charCodeAt(i) >>> 8) & 0xFF);
363 return output;
364}
365
366function str2rstr_utf16be(input)
367{
368 var output = "";
369 for(var i = 0; i < input.length; i++)
370 output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
371 input.charCodeAt(i) & 0xFF);
372 return output;
373}
374
375/*
376* Convert a raw string to an array of big-endian words
377* Characters >255 have their high-byte silently ignored.
378*/
379function rstr2binb(input)
380{
381 var output = Array(input.length >> 2);
382 for(var i = 0; i < output.length; i++)
383 output[i] = 0;
384 for(var i = 0; i < input.length * 8; i += 8)
385 output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
386 return output;
387}
388
389/*
390* Convert an array of big-endian words to a string
391*/
392function binb2rstr(input)
393{
394 var output = "";
395 for(var i = 0; i < input.length * 32; i += 8)
396 output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
397 return output;
398}
399
400/*
401* Calculate the SHA-1 of an array of big-endian words, and a bit length
402*/
403function binb_sha1(x, len)
404{
405 /* append padding */
406 x[len >> 5] |= 0x80 << (24 - len % 32);
407 x[((len + 64 >> 9) << 4) + 15] = len;
408
409 var w = Array(80);
410 var a = 1732584193;
411 var b = -271733879;
412 var c = -1732584194;
413 var d = 271733878;
414 var e = -1009589776;
415
416 for(var i = 0; i < x.length; i += 16)
417 {
418 var olda = a;
419 var oldb = b;
420 var oldc = c;
421 var oldd = d;
422 var olde = e;
423
424 for(var j = 0; j < 80; j++)
425 {
426 if(j < 16) w[j] = x[i + j];
427 else w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
428 var t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),
429 safe_add(safe_add(e, w[j]), sha1_kt(j)));
430 e = d;
431 d = c;
432 c = bit_rol(b, 30);
433 b = a;
434 a = t;
435 }
436
437 a = safe_add(a, olda);
438 b = safe_add(b, oldb);
439 c = safe_add(c, oldc);
440 d = safe_add(d, oldd);
441 e = safe_add(e, olde);
442 }
443 return Array(a, b, c, d, e);
444
445}
446
447/*
448* Perform the appropriate triplet combination function for the current
449* iteration
450*/
451function sha1_ft(t, b, c, d)
452{
453 if(t < 20) return (b & c) | ((~b) & d);
454 if(t < 40) return b ^ c ^ d;
455 if(t < 60) return (b & c) | (b & d) | (c & d);
456 return b ^ c ^ d;
457}
458
459/*
460* Determine the appropriate additive constant for the current iteration
461*/
462function sha1_kt(t)
463{
464 return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
465 (t < 60) ? -1894007588 : -899497514;
466}
467
468/*
469* Add integers, wrapping at 2^32. This uses 16-bit operations internally
470* to work around bugs in some JS interpreters.
471*/
472function safe_add(x, y)
473{
474 var lsw = (x & 0xFFFF) + (y & 0xFFFF);
475 var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
476 return (msw << 16) | (lsw & 0xFFFF);
477}
478
479/*
480* Bitwise rotate a 32-bit number to the left.
481*/
482function bit_rol(num, cnt)
483{
484 return (num << cnt) | (num >>> (32 - cnt));
485}
486
487
488})();