-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickstart.html
627 lines (575 loc) · 18.8 KB
/
quickstart.html
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
<!DOCTYPE html>
<html>
<head>
<title>Seekr</title>
<meta charset='utf-8' />
<style type="text/css">
@import url('https://fonts.googleapis.com/css?family=Lato:400,700');
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
font-family: arial;
}
body {
background: #243756;
}
h1 {
color: #ccc;
text-align: center;
font-family: 'Lato', cursive;
font-size: 50px;
}
.login-form {
width: 350px;
padding: 40px 30px;
background: #eee;
margin: auto;
position: absolute;
left: 0;
right: 0;
top: 50%;
-moz-transform: translateY(-50%);
-ms-transform: translateY(-50%);
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
box-shadow: 0px 0px 18px 5px rgba(0,0,0,0.4);
}
.form-group {
position: relative;
margin-bottom: 15px;
}
.form-control {
width: 100%;
height: 50px;
border: none;
padding: 5px 7px 5px 15px;
background: #fff;
color: #666;
border: 2px solid #ddd;
font-size: 20px;
}
.form-control:focus, .form-control:focus + .fa {
border-color: #006a77;
color: #006a77;
}
.log-btn {
background: #d34836;
dispaly: inline-block;
width: 100%;
font-size: 25px;
height: 50px;
color: #000000;
text-decoration: none;
border: none;
font-weight: bold;
}
.loginBtn {
box-sizing: border-box;
position: relative;
/* width: 13em; - apply for fixed size */
margin: 3em;
padding: 0 15px 0 46px;
border: none;
text-align: left;
line-height: 34px;
white-space: nowrap;
border-radius: 0.2em;
font-size: 16px;
color: #FFF;
}
.loginBtn:before {
content: "";
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
width: 34px;
height: 100%;
}
.loginBtn:focus {
outline: none;
}
.loginBtn:active {
box-shadow: inset 0 0 0 32px rgba(0,0,0,0.1);
}
/* Facebook */
.loginBtn--facebook {
background-color: #4C69BA;
background-image: linear-gradient(#4C69BA, #3B55A0);
/*font-family: "Helvetica neue", Helvetica Neue, Helvetica, Arial, sans-serif;*/
text-shadow: 0 -1px 0 #354C8C;
}
.loginBtn--facebook:before {
border-right: #364e92 1px solid;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/icon_facebook.png') 6px 6px no-repeat;
}
.loginBtn--facebook:hover,
.loginBtn--facebook:focus {
background-color: #5B7BD5;
background-image: linear-gradient(#5B7BD5, #4864B1);
}
/* Google */
.loginBtn--google {
/*font-family: "Roboto", Roboto, arial, sans-serif;*/
background: #DD4B39;
}
.loginBtn--google:before {
border-right: #BB3F30 1px solid;
background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/14082/icon_google.png') 6px 6px no-repeat;
}
.loginBtn--google:hover,
.loginBtn--google:focus {
background: #E74B37;
}
</style>
</head>
<body>
<div class="login-form">
<h1>Seekr</h1>
<div class="form-group ">
<input type="text" class="form-control" placeholder="Enter Job Page URL" id="UserName">
<button id="googleButton" class="loginBtn loginBtn--google">
Login with Google
</button>
<!--Add buttons to initiate auth sequence and sign out-->
<button id="authorize-button" style="display: none;">Authorize</button>
<button id="signout-button" style="display: none;">Sign Out</button>
<pre id="content"></pre>
<script type="text/javascript">
// Client ID and API key from the Developer Console
var CLIENT_ID = '892126478911-0nc4ftgjcvspklejqnogp3nt4amb3m9t.apps.googleusercontent.com';
// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest"];
// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = 'https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.modify';
var authorizeButton = document.getElementById('authorize-button');
var signoutButton = document.getElementById('signout-button');
var googleButton = document.getElementById('googleButton');
var labelIds = []
/**
* On load, called to load the auth2 library and API client library.
*/
function handleClientLoad() {
gapi.load('client:auth2', initClient);
}
/**
* Initializes the API client library and sets up sign-in state
* listeners.
*/
function initClient() {
gapi.client.init({
discoveryDocs: DISCOVERY_DOCS,
clientId: CLIENT_ID,
scope: SCOPES
}).then(function () {
// Listen for sign-in state changes.
gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
// Handle the initial sign-in state.
updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
authorizeButton.onclick = handleAuthClick;
signoutButton.onclick = handleSignoutClick;
googleButton.onclick = handleGoogleButton;
});
}
function handleGoogleButton() {
if(!gapi.auth2.getAuthInstance().isSignedIn.get()) {
document.getElementById('googleButton').innerHTML = 'Sign out '
handleAuthClick();
} else {
document.getElementById('googleButton').innerHTML = 'Login with Google'
handleSignoutClick();
}
}
/**
* Called when the signed in status changes, to update the UI
* appropriately. After a sign-in, the API is called.
*/
function updateSigninStatus(isSignedIn) {
if (isSignedIn) {
console.log('insieeeeeee')
document.getElementById('googleButton').innerHTML = 'Sign out '
authorizeButton.style.display = 'none';
signoutButton.style.display = 'none';
listLabels();
} else {
document.getElementById('googleButton').innerHTML = 'Login with Google'
authorizeButton.style.display = 'none';
signoutButton.style.display = 'none';
}
}
/**
* Sign in the user upon button click.
*/
function handleAuthClick(event) {
gapi.auth2.getAuthInstance().signIn();
}
/**
* Sign out the user upon button click.
*/
function handleSignoutClick(event) {
gapi.auth2.getAuthInstance().signOut();
}
/**
* Append a pre element to the body containing the given message
* as its text node. Used to display the results of the API call.
*
* @param {string} message Text to be placed in pre element.
*/
function appendPre(message) {
var pre = document.getElementById('content');
var textContent = document.createTextNode(message + '\n');
pre.appendChild(textContent);
}
/**
* Print all Labels in the authorized user's inbox. If no labels
* are found an appropriate message is printed.
*/
function listLabels() {
var GoogleAuth = gapi.auth2.getAuthInstance()
// console.log('The user is => ')
console.log(GoogleAuth.currentUser.get())
gapi.client.gmail.users.labels.list({
'userId': 'me'
}).then(function(response) {
console.log(response)
var labels = response.result.labels;
if (labels && labels.length > 0) {
for (i = 0; i < labels.length; i++) {
var label = labels[i];
console.log(label.name)
}
} else {
appendPre('No Labels found.');
}
});
gapi.client.gmail.users.messages.list({
'userId': 'me'
}).then((response) => {
// console.log(response)
var messages = response.result.messages
if(messages && messages.length > 0) {
for(i=0;i< messages.length; i++) {
gapi.client.gmail.users.messages.get({
'userId': 'me',
'id': messages[i].id
}).then((res) => {
console.log(res.result)
getAttachments('me', res.result)
})
}
}
})
}
function getAttachments(userId, message) {
var parts = message.payload.parts;
// console.log(JSON.stringify(parts))
if(parts){
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
if (part.filename && part.filename.length > 0) {
var attachId = part.body.attachmentId;
gapi.client.gmail.users.messages.attachments.get({
'id': attachId,
'messageId': message.id,
'userId': 'me'
}).then((res) => {
// sendNameandID(message_id, part.filename) Tarun comment out this once API ready
var base64=(res.result.data).replace(/_/g, '/'); //Replace this characters
base64=base64.replace(/-/g, '+');
var base64Fixed = fixBase64(base64);
var blob = new Blob([base64Fixed], { type: "application/pdf" } );
// saveAs(blob,"sidhanth.pdf")
//set your file type!
var reader = new FileReader();
reader.onload = function() {
console.log('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
// console.log(reader.result);
console.log('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
}
reader.readAsText(blob)
// console.log('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
// console.log(blob)
// console.log('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
// saveAs(blob,"name of file"); //Using FileSaver library
})
}
}
}
else {
}
// request.execute(function(attachment) {
// callback(part.filename, part.mimeType, attachment);
// });
}
function sendNameandID (messageID, fileName) { // Tarun add end point here to send message id and filename
fetch('https://mywebsite.com/endpoint/', {
method: 'POST',
headers: {
},
body: JSON.stringify({
message_id: messageID,
filename: fileName,
})
}).then((res) => {
if(res.labels <= 0 ) {
// do nothing as this is a junk attachment
} else {
for ( i = 0 ; i < res.labels.length ; i++ ) {
if (checkIfLabelPresent(res.labels[i])) {
labelIds.add(getIdofLabel(res.labels[i]))
} else {
gapi.client.gmail.users.labels.create({
'userId': 'me',
'name': res.labels[i]
}).then((response) => {
labelIds.add(response.id)
})
}
}
addLabeltoMessage(res.messageId) // Tarun just check if messageId is the key in the JSON response
}
})
}
function getIdofLabel (a) {
gapi.client.gmail.users.labels.list({
'userId': 'me'
}).then(function(response) {
var labels = response.result.labels;
for(i = 0; i < labels.length ; i++) {
if(a === labels[i].name) {
return labels[i].id
}
}
return false
})
}
function addLabeltoMessage (messageId) {
gapi.client.gmail.users.messages.modify({
'userId': 'me',
'id': messageId,
'addLabelIds': labelIds
})
}
function checkIfLabelPresent (a) {
gapi.client.gmail.users.labels.list({
'userId': 'me'
}).then(function(response) {
var labels = response.result.labels;
for(i = 0; i < labels.length ; i++) {
if(a === labels[i].name) {
return true
}
}
return false
})
}
function addLabel() {
// const res = { "labels" : ["a","b"]}
// Tarun this will create label
fetch('https://reqres.in/api/users').then((res) => {
for(i = 0 ; i < res.labels.length ; i++) {
gapi.client.gmail.users.labels.create({
'userId': 'me',
'name': res.labels[i]
})
}
})
}
function fixBase64(binaryData) {
var base64str = binaryData// base64 string from thr response of server
var binary = atob(base64str.replace(/\s/g, ''));// decode base64 string, remove space for IE compatibility
var len = binary.length; // get binary length
var buffer = new ArrayBuffer(len); // create ArrayBuffer with binary length
var view = new Uint8Array(buffer); // create 8-bit Array
// save unicode of binary data into 8-bit Array
for (var i = 0; i < len; i++)
view[i] = binary.charCodeAt(i);
return view;
}
function dataURItoBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return URL.createObjectURL(new Blob([ab] , {type:'text/plain'}))
// bb.append(ab);
// return bb.getBlob(mimeString);
}
var saveAs = saveAs || (function(view) {
"use strict";
// IE <10 is explicitly unsupported
if (typeof view === "undefined" || typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
return;
}
var
doc = view.document
// only get URL when necessary in case Blob.js hasn't overridden it yet
, get_URL = function() {
return view.URL || view.webkitURL || view;
}
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
, can_use_save_link = "download" in save_link
, click = function(node) {
var event = new MouseEvent("click");
node.dispatchEvent(event);
}
, is_safari = /constructor/i.test(view.HTMLElement) || view.safari
, is_chrome_ios =/CriOS\/[\d]+/.test(navigator.userAgent)
, throw_outside = function(ex) {
(view.setImmediate || view.setTimeout)(function() {
throw ex;
}, 0);
}
, force_saveable_type = "application/octet-stream"
// the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
, arbitrary_revoke_timeout = 1000 * 40 // in ms
, revoke = function(file) {
var revoker = function() {
if (typeof file === "string") { // file is an object URL
get_URL().revokeObjectURL(file);
} else { // file is a File
file.remove();
}
};
setTimeout(revoker, arbitrary_revoke_timeout);
}
, dispatch = function(filesaver, event_types, event) {
event_types = [].concat(event_types);
var i = event_types.length;
while (i--) {
var listener = filesaver["on" + event_types[i]];
if (typeof listener === "function") {
try {
listener.call(filesaver, event || filesaver);
} catch (ex) {
throw_outside(ex);
}
}
}
}
, auto_bom = function(blob) {
// prepend BOM for UTF-8 XML and text/* types (including HTML)
// note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
return new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});
}
return blob;
}
, FileSaver = function(blob, name, no_auto_bom) {
if (!no_auto_bom) {
blob = auto_bom(blob);
}
// First try a.download, then web filesystem, then object URLs
var
filesaver = this
, type = blob.type
, force = type === force_saveable_type
, object_url
, dispatch_all = function() {
dispatch(filesaver, "writestart progress write writeend".split(" "));
}
// on any filesys errors revert to saving with object URLs
, fs_error = function() {
if ((is_chrome_ios || (force && is_safari)) && view.FileReader) {
// Safari doesn't allow downloading of blob urls
var reader = new FileReader();
reader.onloadend = function() {
var url = is_chrome_ios ? reader.result : reader.result.replace(/^data:[^;]*;/, 'data:attachment/file;');
var popup = view.open(url, '_blank');
if(!popup) view.location.href = url;
url=undefined; // release reference before dispatching
filesaver.readyState = filesaver.DONE;
dispatch_all();
};
reader.readAsDataURL(blob);
filesaver.readyState = filesaver.INIT;
return;
}
// don't create more object URLs than needed
if (!object_url) {
object_url = get_URL().createObjectURL(blob);
}
if (force) {
view.location.href = object_url;
} else {
var opened = view.open(object_url, "_blank");
if (!opened) {
// Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html
view.location.href = object_url;
}
}
filesaver.readyState = filesaver.DONE;
dispatch_all();
revoke(object_url);
}
;
filesaver.readyState = filesaver.INIT;
if (can_use_save_link) {
object_url = get_URL().createObjectURL(blob);
setTimeout(function() {
save_link.href = object_url;
save_link.download = name;
click(save_link);
dispatch_all();
revoke(object_url);
filesaver.readyState = filesaver.DONE;
});
return;
}
fs_error();
}
, FS_proto = FileSaver.prototype
, saveAs = function(blob, name, no_auto_bom) {
return new FileSaver(blob, name || blob.name || "download", no_auto_bom);
}
;
// IE 10+ (native saveAs)
if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
return function(blob, name, no_auto_bom) {
name = name || blob.name || "download";
if (!no_auto_bom) {
blob = auto_bom(blob);
}
return navigator.msSaveOrOpenBlob(blob, name);
};
}
FS_proto.abort = function(){};
FS_proto.readyState = FS_proto.INIT = 0;
FS_proto.WRITING = 1;
FS_proto.DONE = 2;
FS_proto.error =
FS_proto.onwritestart =
FS_proto.onprogress =
FS_proto.onwrite =
FS_proto.onabort =
FS_proto.onerror =
FS_proto.onwriteend =
null;
return saveAs;
}(
typeof self !== "undefined" && self
|| typeof window !== "undefined" && window
|| this.content
));
// `self` is undefined in Firefox for Android content script context
// while `this` is nsIContentFrameMessageManager
// with an attribute `content` that corresponds to the window
if (typeof module !== "undefined" && module.exports) {
module.exports.saveAs = saveAs;
} else if ((typeof define !== "undefined" && define !== null) && (define.amd !== null)) {
define("FileSaver.js", function() {
return saveAs;
});
}
</script>
<script async defer src="https://apis.google.com/js/api.js"
onload="this.onload=function(){};handleClientLoad()"
onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
</body>
</html>