CodeAntidote commited on
Commit
cbb6224
·
verified ·
1 Parent(s): 8101208

Hard reset JobAlign search and AI generation

Browse files
Files changed (1) hide show
  1. app.js +1485 -937
app.js CHANGED
@@ -1,653 +1,1081 @@
1
- document.addEventListener("DOMContentLoaded", function () {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- const searchButton =
4
- document.getElementById("searchJobsBtn");
5
-
6
- const keywordInput =
7
- document.getElementById("jobKeyword");
8
 
9
- const locationInput =
10
- document.getElementById("jobLocation");
11
 
12
- const resultsBox =
13
- document.getElementById("jobResults");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
 
15
 
16
- const selectedJobCard =
17
- document.getElementById("selectedJobCard");
18
 
19
- const selectedJobTitle =
20
- document.getElementById("selectedJobTitle");
 
 
 
 
 
21
 
22
- const selectedCompany =
23
- document.getElementById("selectedCompany");
24
 
25
- const selectedLocation =
26
- document.getElementById("selectedLocation");
 
27
 
28
- const jobDescription =
29
- document.getElementById("jobDescription");
30
 
31
- const jobUrlInput =
32
- document.getElementById("jobUrl");
 
 
 
33
 
34
- const openOriginalJobBtn =
35
- document.getElementById("openOriginalJobBtn");
 
 
 
36
 
37
 
38
- const resumeFile =
39
- document.getElementById("resumeFile");
 
40
 
41
- const resumeText =
42
- document.getElementById("resumeText");
43
 
44
- const saveResumeBtn =
45
- document.getElementById("saveResumeBtn");
 
46
 
47
- const resumeStatus =
48
- document.getElementById("resumeStatus");
 
 
 
49
 
 
 
 
 
 
 
 
50
 
51
- const analyzeJobBtn =
52
- document.getElementById("analyzeJobBtn");
53
 
54
- const atsScore =
55
- document.getElementById("atsScore");
 
 
 
 
 
 
 
 
 
56
 
57
- const keywordScore =
58
- document.getElementById("keywordScore");
59
 
60
- const matchedSkills =
61
- document.getElementById("matchedSkills");
62
 
63
- const missingSkills =
64
- document.getElementById("missingSkills");
 
 
 
65
 
66
- const analysisResults =
67
- document.getElementById("analysisResults");
 
 
 
68
 
 
 
 
 
 
69
 
70
- const generateResumeBtn =
71
- document.getElementById("generateResumeBtn");
72
 
73
- const copyResumeBtn =
74
- document.getElementById("copyResumeBtn");
75
 
76
- const downloadResumeBtn =
77
- document.getElementById("downloadResumeBtn");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- const generationStatus =
80
- document.getElementById("generationStatus");
81
 
82
- const resumeOutput =
83
- document.getElementById("resumeOutput");
84
 
85
- const interviewCheck =
86
- document.getElementById("interviewCheck");
 
 
 
 
 
 
 
87
 
 
88
 
89
- let currentMatches = [];
90
- let selectedJob = null;
 
 
91
 
92
 
 
 
 
93
 
94
- /* =====================================================
95
- LOAD SAVED MASTER RESUME
96
- ===================================================== */
97
 
98
- const savedResume =
99
- localStorage.getItem(
100
- "jobalign_master_resume"
101
- );
102
 
 
 
 
 
 
 
 
 
 
103
 
104
- if (savedResume) {
 
 
 
 
 
 
 
 
105
 
106
- resumeText.value =
107
- savedResume;
 
 
 
 
 
 
 
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
- resumeStatus.innerHTML = `
 
 
 
 
 
 
 
 
111
 
112
- <div class="status-dot"></div>
 
 
 
 
 
 
 
 
113
 
114
- <span class="success-text">
115
- Master resume loaded from this browser
116
- </span>
117
- `;
 
 
 
 
 
 
 
118
  }
119
 
120
 
 
 
 
 
121
 
122
- /* =====================================================
123
- SEARCH
124
- ===================================================== */
125
-
126
- searchButton.addEventListener(
127
- "click",
128
- searchJobs
129
- );
130
-
131
-
132
- keywordInput.addEventListener(
133
- "keydown",
134
- function (event) {
135
-
136
- if (event.key === "Enter") {
137
-
138
- searchJobs();
139
- }
140
- }
141
- );
142
-
143
-
144
- async function searchJobs() {
145
 
146
- const keyword =
147
- keywordInput
148
- .value
149
- .trim()
150
- .toLowerCase();
151
 
 
152
 
153
- const location =
154
- locationInput
155
- .value
156
- .trim()
157
- .toLowerCase();
158
 
 
 
 
159
 
160
- if (!keyword) {
161
 
162
- alert(
163
- "Please enter a job title or keyword."
164
- );
 
 
 
165
 
166
- keywordInput.focus();
167
 
168
- return;
169
- }
 
 
 
 
170
 
 
 
 
 
 
 
 
171
 
172
- searchButton.disabled =
173
- true;
174
 
 
175
 
176
- searchButton.textContent =
177
- "Searching...";
 
178
 
 
 
 
179
 
180
- resultsBox.innerHTML = `
181
 
182
- <div class="empty-state">
183
 
184
- <div>
 
 
185
 
186
- <strong>
187
- Searching live jobs...
188
- </strong>
 
 
189
 
190
- <br><br>
 
 
 
 
 
 
 
191
 
192
- ${escapeHTML(keyword)}
 
193
 
194
- ${
195
- location
196
- ? " • " +
197
- escapeHTML(location)
198
- : ""
199
- }
200
 
201
- </div>
202
 
203
- </div>
204
- `;
 
205
 
 
 
 
 
 
 
 
206
 
207
- try {
 
 
208
 
209
- const response =
210
- await fetch(
211
- "https://www.arbeitnow.com/api/job-board-api"
212
- );
213
 
 
 
214
 
215
- if (!response.ok) {
 
 
216
 
217
- throw new Error(
218
- "Job source returned status " +
219
- response.status
220
- );
221
- }
222
 
 
 
223
 
224
- const data =
225
- await response.json();
226
 
 
227
 
228
- const allJobs =
229
- Array.isArray(data.data)
230
- ? data.data
231
- : [];
 
 
 
 
232
 
 
 
 
 
 
 
 
 
233
 
234
- currentMatches =
235
- allJobs
236
- .filter(
237
- function (job) {
 
 
 
 
238
 
239
- return jobMatches(
240
- job,
241
- keyword,
242
- location
243
- );
244
- }
245
- )
246
- .sort(
247
- function (a, b) {
248
-
249
- return calculateMatchScore(
250
- b,
251
- keyword
252
- ) -
253
- calculateMatchScore(
254
- a,
255
- keyword
256
- );
257
- }
258
- )
259
- .slice(
260
- 0,
261
- 20
262
- );
263
 
264
 
265
- renderJobs();
 
 
 
266
 
267
- } catch (error) {
268
 
269
- console.error(error);
 
 
270
 
 
 
271
 
272
- resultsBox.innerHTML = `
 
 
273
 
274
- <div
275
- class="empty-state"
276
- style="color:#ff7777;"
277
- >
278
 
279
- <div>
 
 
 
 
 
280
 
281
- <strong>
282
- Job search failed.
283
- </strong>
 
 
284
 
285
- <br><br>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
286
 
287
- ${escapeHTML(error.message)}
288
 
289
- </div>
 
 
290
 
291
- </div>
292
- `;
293
 
294
- } finally {
 
 
295
 
296
- searchButton.disabled =
297
- false;
 
 
 
 
298
 
 
299
 
300
- searchButton.textContent =
301
- "Search Jobs";
302
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  }
304
 
305
 
 
 
 
306
 
307
- /* =====================================================
308
- FILTERING
309
- ===================================================== */
310
 
311
- function jobMatches(
312
- job,
313
- keyword,
314
- location
315
- ) {
316
 
317
- const searchableText = [
318
 
319
- job.title || "",
320
- job.company_name || "",
321
- job.description || "",
322
- Array.isArray(job.tags)
323
- ? job.tags.join(" ")
324
- : ""
325
- ]
326
- .join(" ")
327
- .toLowerCase();
328
 
 
 
 
 
 
 
 
 
 
329
 
330
- const keywordWords =
331
- keyword
332
- .split(/\s+/)
333
- .filter(
334
- function (word) {
335
 
336
- return word.length > 2;
337
- }
338
- );
339
 
 
 
 
340
 
341
- const keywordMatch =
342
- keywordWords.some(
343
- function (word) {
344
-
345
- return searchableText.includes(
346
- word
347
- );
348
- }
349
- );
350
 
 
 
 
 
351
 
352
- if (!keywordMatch) {
 
 
 
353
 
354
- return false;
 
 
 
 
 
 
 
 
355
  }
356
 
 
357
 
358
- if (!location) {
 
 
 
359
 
360
- return true;
 
 
361
  }
362
 
363
-
364
  if (
365
- location === "remote"
 
366
  ) {
367
-
368
- return Boolean(
369
- job.remote
370
- );
371
  }
372
 
 
 
373
 
374
- const jobLocation =
375
- (
376
- job.location || ""
377
- ).toLowerCase();
378
 
 
 
 
379
 
380
- return (
381
- jobLocation.includes(
382
- location
383
- ) ||
384
- (
385
- job.remote &&
386
- location.includes(
387
- "remote"
388
- )
389
- )
390
  );
391
- }
392
 
 
 
 
393
 
 
 
 
 
 
 
394
 
395
- /* =====================================================
396
- MATCH SCORE
397
- ===================================================== */
 
 
 
 
 
 
 
 
 
 
 
398
 
399
- function calculateMatchScore(
400
- job,
401
- keyword
402
- ) {
 
 
 
 
 
 
 
 
 
 
403
 
404
- const title =
405
- (
406
- job.title || ""
407
- ).toLowerCase();
 
 
 
 
 
 
408
 
 
409
 
410
- const description =
411
- stripHTML(
412
- job.description || ""
413
- ).toLowerCase();
 
 
 
 
414
 
 
 
 
 
415
 
416
- const words =
417
- keyword
418
- .split(/\s+/)
419
- .filter(
420
- function (word) {
 
 
 
 
 
421
 
422
- return word.length > 2;
423
- }
 
 
 
 
 
424
  );
425
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
 
427
- let score = 0;
 
428
 
 
 
 
 
 
 
 
 
 
429
 
430
- words.forEach(
431
- function (word) {
 
432
 
433
- if (
434
- title.includes(word)
435
- ) {
436
 
437
- score += 10;
438
- }
 
439
 
 
 
 
 
440
 
441
- if (
442
- description.includes(word)
443
- ) {
444
 
445
- score += 2;
446
- }
447
- }
448
- );
449
 
 
 
 
450
 
451
- return score;
452
- }
 
 
453
 
 
 
 
 
454
 
 
 
 
455
 
456
- /* =====================================================
457
- RENDER RESULTS
458
- ===================================================== */
459
 
460
- function renderJobs() {
 
 
 
461
 
462
  if (
463
- currentMatches.length === 0
 
 
 
 
464
  ) {
 
 
465
 
466
- resultsBox.innerHTML = `
 
 
467
 
468
- <div class="empty-state">
 
469
 
470
- <div>
471
 
472
- No matching jobs found.
 
 
473
 
474
- <br><br>
475
 
476
- Try a broader keyword such as:
477
 
 
 
 
 
 
 
 
478
  <br><br>
479
-
480
- Data<br>
481
- Engineer<br>
482
- Product<br>
483
- Python<br>
484
- Software
485
-
486
  <br><br>
487
-
488
- You can also leave location blank.
489
-
490
  </div>
491
-
492
  </div>
493
  `;
494
 
495
  return;
496
  }
497
 
498
-
499
  const cards =
500
  currentMatches
501
- .map(
502
- function (job, index) {
503
-
504
- return createJobCard(
505
- job,
506
- index
507
- );
508
- }
509
- )
510
  .join("");
511
 
512
-
513
  resultsBox.innerHTML = `
514
-
515
- <div style="
516
- margin-bottom:18px;
517
- ">
518
-
519
- <strong style="
520
- font-size:18px;
521
- ">
522
- ${currentMatches.length}
523
- matching jobs
524
  </strong>
525
 
526
-
527
  <div style="
528
  color:#777;
529
- margin-top:5px;
530
  font-size:12px;
531
  ">
532
- Select a job to load its description
 
 
533
  </div>
534
-
535
  </div>
536
 
537
-
538
  <div style="
539
  display:grid;
540
  gap:12px;
541
  ">
542
-
543
  ${cards}
544
-
545
  </div>
546
- `;
547
-
548
-
549
- document
550
- .querySelectorAll(
551
- ".select-job-btn"
552
- )
553
- .forEach(
554
- function (button) {
555
-
556
- button.addEventListener(
557
- "click",
558
- function () {
559
-
560
- const index =
561
- parseInt(
562
- button.dataset.index,
563
- 10
564
- );
565
-
566
-
567
- fillSelectedJob(
568
- currentMatches[index]
569
- );
570
- }
571
- );
572
- }
573
- );
574
- }
575
-
576
-
577
-
578
- /* =====================================================
579
- JOB CARD
580
- ===================================================== */
581
-
582
- function createJobCard(
583
- job,
584
- index
585
- ) {
586
 
587
- const title =
588
- job.title ||
589
- "Untitled position";
590
 
 
 
 
591
 
592
- const company =
593
- job.company_name ||
594
- "Company not listed";
 
595
 
 
 
 
 
 
 
 
596
 
597
- const location =
598
- job.location ||
599
- (
600
- job.remote
601
- ? "Remote"
602
- : "Location not listed"
603
- );
604
 
 
605
 
606
  const description =
607
  stripHTML(
608
  job.description || ""
609
  );
610
 
611
-
612
  const excerpt =
613
- description.length > 260
614
  ? description.substring(
615
  0,
616
- 260
617
  ) + "..."
618
  : description;
619
 
620
-
621
  const tags =
622
  Array.isArray(job.tags)
623
  ? job.tags.slice(0, 5)
624
  : [];
625
 
626
-
627
- const tagHtml =
628
  tags
629
- .map(
630
- function (tag) {
631
-
632
- return `
633
-
634
- <span style="
635
- border:1px solid #292929;
636
- border-radius:999px;
637
- padding:5px 9px;
638
- font-size:11px;
639
- color:#aaa;
640
- ">
641
- ${escapeHTML(tag)}
642
- </span>
643
- `;
644
- }
645
- )
646
  .join("");
647
 
648
-
649
  return `
650
-
651
  <div style="
652
  padding:20px;
653
  border:1px solid #2b2b2b;
@@ -675,34 +1103,35 @@ document.addEventListener("DOMContentLoaded", function () {
675
  letter-spacing:1px;
676
  margin-bottom:7px;
677
  ">
678
- ${escapeHTML(company)}
 
 
 
679
  </div>
680
 
681
-
682
  <strong style="
683
  display:block;
684
  font-size:18px;
685
  margin-bottom:8px;
686
  ">
687
- ${escapeHTML(title)}
688
  </strong>
689
 
690
-
691
  <div style="
692
  color:#999;
693
  font-size:13px;
694
  margin-bottom:12px;
695
  ">
696
- ${escapeHTML(location)}
697
-
698
- ${
699
- job.remote
700
- ? " • Remote"
701
- : ""
702
- }
 
703
  </div>
704
 
705
-
706
  <p style="
707
  color:#888;
708
  line-height:1.6;
@@ -711,7 +1140,6 @@ document.addEventListener("DOMContentLoaded", function () {
711
  ${escapeHTML(excerpt)}
712
  </p>
713
 
714
-
715
  ${
716
  tags.length
717
  ? `
@@ -721,14 +1149,22 @@ document.addEventListener("DOMContentLoaded", function () {
721
  gap:6px;
722
  margin-top:14px;
723
  ">
724
- ${tagHtml}
725
  </div>
726
  `
727
  : ""
728
  }
729
 
730
- </div>
 
 
 
 
 
 
 
731
 
 
732
 
733
  <button
734
  class="primary-btn select-job-btn"
@@ -739,41 +1175,30 @@ document.addEventListener("DOMContentLoaded", function () {
739
  </button>
740
 
741
  </div>
742
-
743
  </div>
744
  `;
745
  }
746
 
747
 
748
-
749
- /* =====================================================
750
  SELECT JOB
751
- ===================================================== */
752
 
753
  function fillSelectedJob(job) {
754
 
755
  if (!job) {
756
-
757
- alert(
758
- "Unable to load this job."
759
- );
760
-
761
  return;
762
  }
763
 
764
-
765
- selectedJob =
766
- job;
767
-
768
 
769
  selectedJobTitle.value =
770
  job.title || "";
771
 
772
-
773
  selectedCompany.value =
774
  job.company_name || "";
775
 
776
-
777
  selectedLocation.value =
778
  job.location ||
779
  (
@@ -782,63 +1207,39 @@ document.addEventListener("DOMContentLoaded", function () {
782
  : ""
783
  );
784
 
785
-
786
  jobDescription.value =
787
  stripHTML(
788
  job.description || ""
789
  );
790
 
791
-
792
  jobUrlInput.value =
793
  job.url || "";
794
 
795
-
796
  resetAnalysis();
797
 
798
-
799
  generationStatus.innerHTML = `
800
-
801
  <div class="status-dot"></div>
802
-
803
  <span class="success-text">
804
-
805
  Selected:
806
- ${escapeHTML(
807
- job.title || ""
808
- )}
809
-
810
  at
811
-
812
- ${escapeHTML(
813
- job.company_name || ""
814
- )}
815
-
816
  </span>
817
  `;
818
 
819
-
820
  analysisResults.innerHTML = `
821
-
822
  <div class="empty-state">
823
-
824
  <div>
825
-
826
  Job loaded successfully.
827
-
828
  <br><br>
829
-
830
  Add your master resume and click
831
-
832
  <strong>
833
  Analyze Selected Job
834
  </strong>.
835
-
836
  </div>
837
-
838
  </div>
839
  `;
840
 
841
-
842
  selectedJobCard.scrollIntoView({
843
  behavior: "smooth",
844
  block: "start"
@@ -846,10 +1247,9 @@ document.addEventListener("DOMContentLoaded", function () {
846
  }
847
 
848
 
849
-
850
- /* =====================================================
851
- ORIGINAL LISTING
852
- ===================================================== */
853
 
854
  openOriginalJobBtn.addEventListener(
855
  "click",
@@ -858,17 +1258,11 @@ document.addEventListener("DOMContentLoaded", function () {
858
  const url =
859
  jobUrlInput.value.trim();
860
 
861
-
862
  if (!url) {
863
-
864
- alert(
865
- "Select a job first."
866
- );
867
-
868
  return;
869
  }
870
 
871
-
872
  window.open(
873
  url,
874
  "_blank",
@@ -878,287 +1272,179 @@ document.addEventListener("DOMContentLoaded", function () {
878
  );
879
 
880
 
 
 
 
881
 
882
- /* =====================================================
883
- SAVE RESUME
884
- ===================================================== */
885
-
886
- saveResumeBtn.addEventListener(
887
- "click",
888
- function () {
889
-
890
- const resume =
891
- resumeText.value.trim();
892
-
893
-
894
- if (
895
- resume.length < 100
896
- ) {
897
 
898
- alert(
899
- "Paste your complete master resume first."
900
- );
901
 
 
902
  return;
903
  }
904
 
905
-
906
- localStorage.setItem(
907
- "jobalign_master_resume",
908
- resume
909
- );
910
-
911
 
912
  resumeStatus.innerHTML = `
913
-
914
  <div class="status-dot"></div>
915
-
916
- <span class="success-text">
917
- Master resume saved in this browser
918
  </span>
919
  `;
920
- }
921
- );
922
-
923
-
924
-
925
- /* =====================================================
926
- TXT UPLOAD
927
- ===================================================== */
928
-
929
- /* =====================================================
930
- RESUME FILE UPLOAD
931
- ===================================================== */
932
-
933
- resumeFile.addEventListener(
934
- "change",
935
- async function () {
936
-
937
- const file =
938
- resumeFile.files[0];
939
-
940
-
941
- if (!file) {
942
- return;
943
- }
944
-
945
-
946
- const extension =
947
- file.name
948
- .split(".")
949
- .pop()
950
- .toLowerCase();
951
-
952
-
953
- resumeStatus.innerHTML = `
954
-
955
- <div class="status-dot"></div>
956
-
957
- <span>
958
- Reading ${escapeHTML(file.name)}...
959
- </span>
960
- `;
961
-
962
-
963
- try {
964
-
965
- /* -----------------------------
966
- TXT
967
- ----------------------------- */
968
-
969
- if (extension === "txt") {
970
-
971
- const content =
972
- await file.text();
973
-
974
-
975
- saveExtractedResume(
976
- content,
977
- file.name
978
- );
979
-
980
- return;
981
- }
982
-
983
 
984
- /* -----------------------------
985
- DOCX
986
- ----------------------------- */
987
 
988
- if (extension === "docx") {
989
 
990
- if (
991
- typeof mammoth === "undefined"
992
- ) {
993
 
994
- throw new Error(
995
- "DOCX reader did not load. Refresh the page and try again."
 
996
  );
 
 
997
  }
998
 
 
999
 
1000
- const arrayBuffer =
1001
- await file.arrayBuffer();
 
 
 
 
 
 
1002
 
 
 
1003
 
1004
- const result =
1005
- await mammoth.extractRawText({
1006
- arrayBuffer:
1007
- arrayBuffer
1008
- });
1009
 
 
 
1010
 
1011
- const extractedText =
1012
- result.value.trim();
 
 
 
1013
 
 
 
 
 
1014
 
1015
- if (
1016
- extractedText.length < 100
1017
- ) {
1018
 
 
1019
  throw new Error(
1020
- "Very little text was found in this DOCX."
1021
  );
1022
  }
1023
 
1024
-
1025
- saveExtractedResume(
1026
- extractedText,
1027
- file.name
1028
  );
1029
 
1030
- return;
1031
- }
1032
-
1033
-
1034
- /* -----------------------------
1035
- PDF
1036
- ----------------------------- */
1037
 
1038
- if (extension === "pdf") {
1039
 
1040
  resumeStatus.innerHTML = `
1041
-
1042
  <div class="status-dot"></div>
1043
-
1044
- <span class="warning-text">
1045
-
1046
- PDF reading is not enabled yet.
1047
- Please upload the DOCX version for now.
1048
-
1049
  </span>
1050
  `;
1051
-
1052
- return;
1053
  }
 
 
1054
 
1055
 
1056
- /* -----------------------------
1057
- OLD .DOC
1058
- ----------------------------- */
 
1059
 
1060
- if (extension === "doc") {
 
 
 
 
1061
 
1062
- resumeStatus.innerHTML = `
1063
 
1064
- <div class="status-dot"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1065
 
1066
- <span class="warning-text">
1067
 
1068
- Old .DOC files are not supported.
1069
- Save the resume as .DOCX and upload it again.
 
1070
 
1071
- </span>
1072
- `;
1073
 
 
 
 
 
1074
  return;
1075
  }
1076
 
1077
-
1078
- throw new Error(
1079
- "Unsupported resume format."
1080
  );
1081
 
1082
-
1083
- } catch (error) {
1084
-
1085
- console.error(error);
1086
-
1087
-
1088
  resumeStatus.innerHTML = `
1089
-
1090
  <div class="status-dot"></div>
1091
-
1092
- <span class="danger-text">
1093
-
1094
- Could not read resume:
1095
- ${escapeHTML(error.message)}
1096
-
1097
  </span>
1098
  `;
1099
  }
1100
- }
1101
- );
1102
-
1103
-
1104
- /* =====================================================
1105
- SAVE EXTRACTED RESUME
1106
- ===================================================== */
1107
-
1108
- function saveExtractedResume(
1109
- content,
1110
- fileName
1111
- ) {
1112
-
1113
- const cleanedContent =
1114
- content
1115
- .replace(
1116
- /\r/g,
1117
- ""
1118
- )
1119
- .replace(
1120
- /\n{3,}/g,
1121
- "\n\n"
1122
- )
1123
- .trim();
1124
-
1125
-
1126
- resumeText.value =
1127
- cleanedContent;
1128
-
1129
-
1130
- localStorage.setItem(
1131
- "jobalign_master_resume",
1132
- cleanedContent
1133
- );
1134
-
1135
-
1136
- localStorage.setItem(
1137
- "jobalign_master_resume_filename",
1138
- fileName
1139
  );
1140
 
1141
 
1142
- resumeStatus.innerHTML = `
1143
-
1144
- <div class="status-dot"></div>
1145
-
1146
- <span class="success-text">
1147
-
1148
- ${escapeHTML(fileName)}
1149
- loaded and saved successfully
1150
-
1151
- </span>
1152
- `;
1153
- }
1154
-
1155
-
1156
- /* =====================================================
1157
- ATS SKILL DICTIONARY
1158
- ===================================================== */
1159
 
1160
  const skills = [
1161
-
1162
  "python",
1163
  "sql",
1164
  "java",
@@ -1261,11 +1547,6 @@ function saveExtractedResume(
1261
  ];
1262
 
1263
 
1264
-
1265
- /* =====================================================
1266
- ANALYZE
1267
- ===================================================== */
1268
-
1269
  analyzeJobBtn.addEventListener(
1270
  "click",
1271
  analyzeJob
@@ -1275,84 +1556,50 @@ function saveExtractedResume(
1275
  function analyzeJob() {
1276
 
1277
  const jd =
1278
- jobDescription
1279
- .value
1280
- .toLowerCase();
1281
-
1282
 
1283
  const resume =
1284
- resumeText
1285
- .value
1286
- .toLowerCase();
1287
-
1288
-
1289
- if (
1290
- jd.length < 100
1291
- ) {
1292
 
 
1293
  alert(
1294
  "Search and select a job first."
1295
  );
1296
-
1297
  return;
1298
  }
1299
 
1300
-
1301
- if (
1302
- resume.length < 100
1303
- ) {
1304
-
1305
  alert(
1306
  "Add your master resume first."
1307
  );
1308
-
1309
  return;
1310
  }
1311
 
 
 
 
 
 
 
 
 
 
1312
 
1313
- const required =
1314
- skills.filter(
1315
- function (skill) {
1316
-
1317
- return jd.includes(
1318
- skill
1319
- );
1320
- }
1321
- );
1322
-
1323
-
1324
- const matched =
1325
- required.filter(
1326
- function (skill) {
1327
-
1328
- return resume.includes(
1329
- skill
1330
- );
1331
- }
1332
- );
1333
-
1334
-
1335
- const gaps =
1336
- required.filter(
1337
- function (skill) {
1338
-
1339
- return !resume.includes(
1340
- skill
1341
- );
1342
- }
1343
- );
1344
-
1345
 
1346
  const coverage =
1347
  required.length
1348
  ? Math.round(
1349
- matched.length /
1350
- required.length *
1351
- 100
 
1352
  )
1353
  : 50;
1354
 
1355
-
1356
  const calculatedAts =
1357
  Math.min(
1358
  97,
@@ -1362,38 +1609,29 @@ function saveExtractedResume(
1362
  )
1363
  );
1364
 
1365
-
1366
  atsScore.textContent =
1367
  calculatedAts + "%";
1368
 
1369
-
1370
  keywordScore.textContent =
1371
  coverage + "%";
1372
 
1373
-
1374
  matchedSkills.textContent =
1375
  matched.length;
1376
 
1377
-
1378
  missingSkills.textContent =
1379
  gaps.length;
1380
 
1381
-
1382
  analysisResults.innerHTML = `
1383
-
1384
  <div>
1385
-
1386
  <strong>
1387
  Matching experience
1388
  </strong>
1389
 
1390
-
1391
  <p style="
1392
  color:#aaa;
1393
  margin-top:8px;
1394
  line-height:1.7;
1395
  ">
1396
-
1397
  ${
1398
  matched.length
1399
  ? escapeHTML(
@@ -1401,27 +1639,19 @@ function saveExtractedResume(
1401
  )
1402
  : "No major keyword matches detected."
1403
  }
1404
-
1405
  </p>
1406
-
1407
  </div>
1408
 
1409
-
1410
- <div style="
1411
- margin-top:20px;
1412
- ">
1413
-
1414
  <strong>
1415
  Job priorities not currently visible
1416
  </strong>
1417
 
1418
-
1419
  <p style="
1420
  color:#aaa;
1421
  margin-top:8px;
1422
  line-height:1.7;
1423
  ">
1424
-
1425
  ${
1426
  gaps.length
1427
  ? escapeHTML(
@@ -1429,129 +1659,172 @@ function saveExtractedResume(
1429
  )
1430
  : "No obvious technical keyword gaps detected."
1431
  }
1432
-
1433
  </p>
1434
-
1435
- </div>
1436
-
1437
-
1438
- <div style="
1439
- margin-top:20px;
1440
- padding-top:15px;
1441
- border-top:1px solid #262626;
1442
- color:#666;
1443
- font-size:12px;
1444
- ">
1445
-
1446
- This is the local ATS comparison.
1447
- The AI hard-realignment layer will be connected next.
1448
-
1449
  </div>
1450
  `;
1451
  }
1452
 
1453
 
1454
-
1455
- /* =====================================================
1456
- GENERATE TARGETED RESUME WITH LOCAL AI
1457
- ===================================================== */
1458
 
1459
  generateResumeBtn.addEventListener(
1460
  "click",
1461
- function () {
1462
 
1463
  const jd =
1464
  jobDescription.value.trim();
1465
 
1466
-
1467
  const resume =
1468
  resumeText.value.trim();
1469
 
 
 
1470
 
1471
- if (
1472
- jd.length < 100
1473
- ) {
1474
 
 
 
 
 
1475
  alert(
1476
- "Select a job first."
1477
  );
1478
-
1479
  return;
1480
  }
1481
 
1482
-
1483
- if (
1484
- resume.length < 100
1485
- ) {
1486
-
1487
  alert(
1488
  "Add your master resume first."
1489
  );
1490
-
1491
  return;
1492
  }
1493
 
 
 
 
1494
 
1495
- generationStatus.innerHTML = `
1496
-
1497
- <div class="status-dot"></div>
1498
 
1499
- <span class="success-text">
 
1500
 
1501
- Job and master resume are ready
1502
- for alignment
1503
 
1504
- </span>
1505
- `;
1506
 
 
1507
 
1508
- resumeOutput.textContent =
1509
- `JOBALIGN
1510
 
1511
- A product by John_D
 
 
 
1512
 
 
 
 
 
 
 
 
 
1513
 
1514
- TARGET POSITION
 
1515
 
1516
- ${selectedJobTitle.value}
 
 
 
 
1517
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1518
 
1519
- COMPANY
 
 
 
 
 
 
 
 
1520
 
1521
- ${selectedCompany.value}
 
 
 
 
1522
 
 
 
 
 
 
 
 
 
 
 
1523
 
1524
- LOCATION
1525
 
1526
- ${selectedLocation.value}
 
 
 
1527
 
 
 
 
 
 
 
 
1528
 
1529
- STATUS
 
1530
 
1531
- The live job description and your master resume
1532
- have both been captured successfully.
1533
 
1534
- The next build step connects the resume
1535
- hard-realignment engine.
1536
 
1537
- Final workflow:
 
1538
 
1539
- SEARCH LIVE JOB
1540
- → SELECT JOB
1541
- → LOAD COMPLETE JD
1542
- → ANALYZE REQUIREMENTS
1543
- → HARD-REALIGN MASTER RESUME
1544
- → GENERATE TARGETED RESUME
1545
- → INTERVIEW DEFENSE
1546
- → DOWNLOAD`;
1547
  }
1548
  );
1549
 
1550
 
1551
-
1552
- /* =====================================================
1553
  COPY
1554
- ===================================================== */
1555
 
1556
  copyResumeBtn.addEventListener(
1557
  "click",
@@ -1560,40 +1833,30 @@ SEARCH LIVE JOB
1560
  const text =
1561
  resumeOutput.innerText.trim();
1562
 
1563
-
1564
  if (
1565
  !text ||
1566
  text ===
1567
  "Your job-specific resume will appear here."
1568
  ) {
1569
-
1570
  alert(
1571
- "Generate the resume first."
1572
  );
1573
-
1574
  return;
1575
  }
1576
 
1577
-
1578
  try {
1579
 
1580
  await navigator
1581
  .clipboard
1582
- .writeText(
1583
- text
1584
- );
1585
-
1586
 
1587
  copyResumeBtn.textContent =
1588
  "Copied";
1589
 
1590
-
1591
  setTimeout(
1592
  function () {
1593
-
1594
  copyResumeBtn.textContent =
1595
  "Copy Resume";
1596
-
1597
  },
1598
  1500
1599
  );
@@ -1608,10 +1871,9 @@ SEARCH LIVE JOB
1608
  );
1609
 
1610
 
1611
-
1612
- /* =====================================================
1613
  DOWNLOAD
1614
- ===================================================== */
1615
 
1616
  downloadResumeBtn.addEventListener(
1617
  "click",
@@ -1620,21 +1882,17 @@ SEARCH LIVE JOB
1620
  const text =
1621
  resumeOutput.innerText.trim();
1622
 
1623
-
1624
  if (
1625
  !text ||
1626
  text ===
1627
  "Your job-specific resume will appear here."
1628
  ) {
1629
-
1630
  alert(
1631
- "Generate the resume first."
1632
  );
1633
-
1634
  return;
1635
  }
1636
 
1637
-
1638
  const blob =
1639
  new Blob(
1640
  [text],
@@ -1644,80 +1902,371 @@ SEARCH LIVE JOB
1644
  }
1645
  );
1646
 
1647
-
1648
  const downloadUrl =
1649
- URL.createObjectURL(
1650
- blob
1651
- );
1652
-
1653
 
1654
  const link =
1655
- document.createElement(
1656
- "a"
1657
- );
1658
 
 
1659
 
1660
- const company =
1661
  safeFileName(
1662
  selectedCompany.value ||
1663
  "Company"
1664
- );
1665
-
1666
-
1667
- const role =
1668
  safeFileName(
1669
  selectedJobTitle.value ||
1670
  "Resume"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1671
  );
 
 
1672
 
1673
 
1674
- link.href =
1675
- downloadUrl;
1676
 
 
 
1677
 
1678
- link.download =
1679
- company +
1680
- "_" +
1681
- role +
1682
- "_Resume.txt";
 
 
 
 
 
 
 
 
1683
 
 
 
 
1684
 
1685
- link.click();
 
 
 
 
 
 
 
1686
 
 
 
 
 
1687
 
1688
- URL.revokeObjectURL(
1689
- downloadUrl
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1690
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1691
  }
1692
- );
1693
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1694
 
 
 
 
1695
 
1696
- /* =====================================================
1697
- HELPERS
1698
- ===================================================== */
1699
 
1700
  function stripHTML(html) {
1701
 
1702
  const element =
1703
- document.createElement(
1704
- "div"
1705
- );
1706
-
1707
 
1708
  element.innerHTML =
1709
- html;
1710
-
1711
 
1712
  return (
1713
  element.textContent ||
1714
  element.innerText ||
1715
  ""
1716
  )
 
 
 
 
 
 
 
 
 
1717
  .replace(
1718
- /\s+/g,
1719
  " "
1720
  )
 
1721
  .trim();
1722
  }
1723
 
@@ -1725,24 +2274,28 @@ SEARCH LIVE JOB
1725
  function escapeHTML(value) {
1726
 
1727
  const element =
1728
- document.createElement(
1729
- "div"
1730
- );
1731
-
1732
 
1733
  element.textContent =
1734
- String(
1735
- value || ""
1736
- );
1737
-
1738
 
1739
  return element.innerHTML;
1740
  }
1741
 
1742
 
 
 
 
 
 
 
 
 
 
 
1743
  function safeFileName(value) {
1744
 
1745
- return value
1746
  .replace(
1747
  /[^a-z0-9]+/gi,
1748
  "_"
@@ -1756,20 +2309,15 @@ SEARCH LIVE JOB
1756
 
1757
  function resetAnalysis() {
1758
 
1759
- atsScore.textContent =
1760
- "--";
1761
-
1762
-
1763
- keywordScore.textContent =
1764
- "--";
1765
-
1766
-
1767
- matchedSkills.textContent =
1768
- "--";
1769
-
1770
-
1771
- missingSkills.textContent =
1772
- "--";
1773
  }
1774
 
1775
- });
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ app_js = r'''document.addEventListener("DOMContentLoaded", function () {
4
+
5
+ /* =========================================================
6
+ JOBALIGN
7
+ A product by John_D
8
+
9
+ LOCATION-AWARE FREE JOB SEARCH
10
+ - The Muse: local/city/state/country listings
11
+ - Jobicy: remote jobs with geographic eligibility
12
+ - Remote OK: additional remote jobs
13
+
14
+ IMPORTANT:
15
+ This free build can only show jobs exposed by these public
16
+ feeds. It does not scrape LinkedIn, Indeed, or Glassdoor.
17
+ ========================================================= */
18
+
19
+
20
+ /* =========================================================
21
+ ELEMENTS
22
+ ========================================================= */
23
+
24
+ const searchButton = document.getElementById("searchJobsBtn");
25
+ const keywordInput = document.getElementById("jobKeyword");
26
+ const locationInput = document.getElementById("jobLocation");
27
+ const jobSource = document.getElementById("jobSource");
28
+ const resultsBox = document.getElementById("jobResults");
29
+
30
+ const selectedJobCard = document.getElementById("selectedJobCard");
31
+ const selectedJobTitle = document.getElementById("selectedJobTitle");
32
+ const selectedCompany = document.getElementById("selectedCompany");
33
+ const selectedLocation = document.getElementById("selectedLocation");
34
+ const jobDescription = document.getElementById("jobDescription");
35
+ const jobUrlInput = document.getElementById("jobUrl");
36
+ const openOriginalJobBtn = document.getElementById("openOriginalJobBtn");
37
+
38
+ const resumeFile = document.getElementById("resumeFile");
39
+ const resumeText = document.getElementById("resumeText");
40
+ const saveResumeBtn = document.getElementById("saveResumeBtn");
41
+ const resumeStatus = document.getElementById("resumeStatus");
42
+
43
+ const analyzeJobBtn = document.getElementById("analyzeJobBtn");
44
+ const atsScore = document.getElementById("atsScore");
45
+ const keywordScore = document.getElementById("keywordScore");
46
+ const matchedSkills = document.getElementById("matchedSkills");
47
+ const missingSkills = document.getElementById("missingSkills");
48
+ const analysisResults = document.getElementById("analysisResults");
49
+
50
+ const generateResumeBtn = document.getElementById("generateResumeBtn");
51
+ const copyResumeBtn = document.getElementById("copyResumeBtn");
52
+ const downloadResumeBtn = document.getElementById("downloadResumeBtn");
53
+ const generationStatus = document.getElementById("generationStatus");
54
+ const resumeOutput = document.getElementById("resumeOutput");
55
+ const interviewCheck = document.getElementById("interviewCheck");
56
 
57
+ let currentMatches = [];
58
+ let selectedJob = null;
 
 
 
59
 
 
 
60
 
61
+ /* =========================================================
62
+ US STATE MAP
63
+ ========================================================= */
64
+
65
+ const US_STATES = {
66
+ "alabama": "AL",
67
+ "alaska": "AK",
68
+ "arizona": "AZ",
69
+ "arkansas": "AR",
70
+ "california": "CA",
71
+ "colorado": "CO",
72
+ "connecticut": "CT",
73
+ "delaware": "DE",
74
+ "florida": "FL",
75
+ "georgia": "GA",
76
+ "hawaii": "HI",
77
+ "idaho": "ID",
78
+ "illinois": "IL",
79
+ "indiana": "IN",
80
+ "iowa": "IA",
81
+ "kansas": "KS",
82
+ "kentucky": "KY",
83
+ "louisiana": "LA",
84
+ "maine": "ME",
85
+ "maryland": "MD",
86
+ "massachusetts": "MA",
87
+ "michigan": "MI",
88
+ "minnesota": "MN",
89
+ "mississippi": "MS",
90
+ "missouri": "MO",
91
+ "montana": "MT",
92
+ "nebraska": "NE",
93
+ "nevada": "NV",
94
+ "new hampshire": "NH",
95
+ "new jersey": "NJ",
96
+ "new mexico": "NM",
97
+ "new york": "NY",
98
+ "north carolina": "NC",
99
+ "north dakota": "ND",
100
+ "ohio": "OH",
101
+ "oklahoma": "OK",
102
+ "oregon": "OR",
103
+ "pennsylvania": "PA",
104
+ "rhode island": "RI",
105
+ "south carolina": "SC",
106
+ "south dakota": "SD",
107
+ "tennessee": "TN",
108
+ "texas": "TX",
109
+ "utah": "UT",
110
+ "vermont": "VT",
111
+ "virginia": "VA",
112
+ "washington": "WA",
113
+ "west virginia": "WV",
114
+ "wisconsin": "WI",
115
+ "wyoming": "WY"
116
+ };
117
+
118
+ const US_STATE_CODES = Object.values(US_STATES);
119
+
120
+
121
+ /* =========================================================
122
+ LOAD SAVED MASTER RESUME
123
+ ========================================================= */
124
 
125
+ const savedResume = localStorage.getItem("jobalign_master_resume");
126
 
127
+ if (savedResume) {
128
+ resumeText.value = savedResume;
129
 
130
+ resumeStatus.innerHTML = `
131
+ <div class="status-dot"></div>
132
+ <span class="success-text">
133
+ Master resume loaded from this browser
134
+ </span>
135
+ `;
136
+ }
137
 
 
 
138
 
139
+ /* =========================================================
140
+ SEARCH EVENTS
141
+ ========================================================= */
142
 
143
+ searchButton.addEventListener("click", searchJobs);
 
144
 
145
+ keywordInput.addEventListener("keydown", function (event) {
146
+ if (event.key === "Enter") {
147
+ searchJobs();
148
+ }
149
+ });
150
 
151
+ locationInput.addEventListener("keydown", function (event) {
152
+ if (event.key === "Enter") {
153
+ searchJobs();
154
+ }
155
+ });
156
 
157
 
158
+ /* =========================================================
159
+ MAIN SEARCH
160
+ ========================================================= */
161
 
162
+ async function searchJobs() {
 
163
 
164
+ const keyword = keywordInput.value.trim();
165
+ const location = locationInput.value.trim();
166
+ const sourceMode = jobSource ? jobSource.value : "auto";
167
 
168
+ if (!keyword) {
169
+ alert("Enter a job title or keyword.");
170
+ keywordInput.focus();
171
+ return;
172
+ }
173
 
174
+ if (!location) {
175
+ alert(
176
+ "Enter the location you want, for example San Francisco, CA, Utah, United States, Berlin, Germany, or Remote."
177
+ );
178
+ locationInput.focus();
179
+ return;
180
+ }
181
 
182
+ searchButton.disabled = true;
183
+ searchButton.textContent = "Searching...";
184
 
185
+ resultsBox.innerHTML = `
186
+ <div class="empty-state">
187
+ <div>
188
+ <strong>Searching live jobs...</strong>
189
+ <br><br>
190
+ ${escapeHTML(keyword)}
191
+ <br>
192
+ ${escapeHTML(location)}
193
+ </div>
194
+ </div>
195
+ `;
196
 
197
+ try {
 
198
 
199
+ const requestPlan = buildRequestPlan(location, sourceMode);
200
+ const requests = [];
201
 
202
+ if (requestPlan.useMuse) {
203
+ requests.push(
204
+ fetchMuseJobs(location, requestPlan)
205
+ );
206
+ }
207
 
208
+ if (requestPlan.useJobicy) {
209
+ requests.push(
210
+ fetchJobicyJobs(keyword, requestPlan.jobicyGeo)
211
+ );
212
+ }
213
 
214
+ if (requestPlan.useRemoteOK) {
215
+ requests.push(
216
+ fetchRemoteOKJobs()
217
+ );
218
+ }
219
 
220
+ const results = await Promise.allSettled(requests);
 
221
 
222
+ let jobs = [];
 
223
 
224
+ results.forEach(function (result) {
225
+ if (result.status === "fulfilled") {
226
+ jobs = jobs.concat(result.value);
227
+ } else {
228
+ console.warn("A free job source failed:", result.reason);
229
+ }
230
+ });
231
+
232
+ jobs = dedupeJobs(jobs);
233
+
234
+ jobs = jobs
235
+ .map(function (job) {
236
+ return {
237
+ ...job,
238
+ roleScore: calculateRoleScore(job, keyword),
239
+ locationScore: calculateLocationScore(job, location)
240
+ };
241
+ })
242
+ .filter(function (job) {
243
+ return job.roleScore > 0;
244
+ });
245
+
246
+ /*
247
+ * LOCATION IS A REAL FILTER.
248
+ * A San Francisco search will not fall back to Germany.
249
+ * A Utah search will not fall back to California.
250
+ */
251
+ jobs = jobs.filter(function (job) {
252
+ return locationMatches(job, location);
253
+ });
254
+
255
+ jobs.sort(function (a, b) {
256
+ const scoreA =
257
+ (a.roleScore * 4) +
258
+ a.locationScore;
259
+
260
+ const scoreB =
261
+ (b.roleScore * 4) +
262
+ b.locationScore;
263
+
264
+ return scoreB - scoreA;
265
+ });
266
+
267
+ currentMatches = jobs.slice(0, 40);
268
+
269
+ renderJobs(keyword, location);
270
 
271
+ } catch (error) {
 
272
 
273
+ console.error("JobAlign search error:", error);
 
274
 
275
+ resultsBox.innerHTML = `
276
+ <div class="empty-state" style="color:#ff7777;">
277
+ <div>
278
+ <strong>Job search failed.</strong>
279
+ <br><br>
280
+ ${escapeHTML(error.message)}
281
+ </div>
282
+ </div>
283
+ `;
284
 
285
+ } finally {
286
 
287
+ searchButton.disabled = false;
288
+ searchButton.textContent = "Search Jobs";
289
+ }
290
+ }
291
 
292
 
293
+ /* =========================================================
294
+ SEARCH PLAN
295
+ ========================================================= */
296
 
297
+ function buildRequestPlan(location, sourceMode) {
 
 
298
 
299
+ const normalized = normalizeSimple(location);
300
+ const remote = normalized.includes("remote");
301
+ const broadUS = isBroadUSLocation(location);
302
+ const broadEurope = isBroadEuropeLocation(location);
303
 
304
+ if (sourceMode === "remote") {
305
+ return {
306
+ useMuse: true,
307
+ useJobicy: true,
308
+ useRemoteOK: true,
309
+ jobicyGeo: "",
310
+ remoteOnly: true
311
+ };
312
+ }
313
 
314
+ if (sourceMode === "usa") {
315
+ return {
316
+ useMuse: true,
317
+ useJobicy: true,
318
+ useRemoteOK: remote || broadUS,
319
+ jobicyGeo: "usa",
320
+ remoteOnly: remote
321
+ };
322
+ }
323
 
324
+ if (sourceMode === "europe") {
325
+ return {
326
+ useMuse: true,
327
+ useJobicy: true,
328
+ useRemoteOK: remote,
329
+ jobicyGeo: "europe",
330
+ remoteOnly: remote
331
+ };
332
+ }
333
 
334
+ if (remote) {
335
+ return {
336
+ useMuse: true,
337
+ useJobicy: true,
338
+ useRemoteOK: true,
339
+ jobicyGeo:
340
+ looksLikeUSLocation(location)
341
+ ? "usa"
342
+ : looksLikeEuropeLocation(location)
343
+ ? "europe"
344
+ : "",
345
+ remoteOnly: true
346
+ };
347
+ }
348
 
349
+ if (broadUS) {
350
+ return {
351
+ useMuse: true,
352
+ useJobicy: true,
353
+ useRemoteOK: true,
354
+ jobicyGeo: "usa",
355
+ remoteOnly: false
356
+ };
357
+ }
358
 
359
+ if (broadEurope) {
360
+ return {
361
+ useMuse: true,
362
+ useJobicy: true,
363
+ useRemoteOK: false,
364
+ jobicyGeo: "europe",
365
+ remoteOnly: false
366
+ };
367
+ }
368
 
369
+ /*
370
+ * City, state, or country search:
371
+ * local source first. No unrelated fallback.
372
+ */
373
+ return {
374
+ useMuse: true,
375
+ useJobicy: false,
376
+ useRemoteOK: false,
377
+ jobicyGeo: "",
378
+ remoteOnly: false
379
+ };
380
  }
381
 
382
 
383
+ /* =========================================================
384
+ THE MUSE
385
+ LOCATION-AWARE LOCAL JOBS
386
+ ========================================================= */
387
 
388
+ async function fetchMuseJobs(location, plan) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
 
390
+ const locationsToTry = buildMuseLocationQueries(location, plan);
391
+ const seenUrls = new Set();
392
+ let jobs = [];
 
 
393
 
394
+ for (const queryLocation of locationsToTry) {
395
 
396
+ /*
397
+ * Keep requests modest on the keyless testing API.
398
+ */
399
+ for (let page = 1; page <= 5; page++) {
 
400
 
401
+ const endpoint = new URL(
402
+ "https://www.themuse.com/api/public/jobs"
403
+ );
404
 
405
+ endpoint.searchParams.set("page", String(page));
406
 
407
+ if (queryLocation) {
408
+ endpoint.searchParams.append(
409
+ "location",
410
+ queryLocation
411
+ );
412
+ }
413
 
414
+ let response;
415
 
416
+ try {
417
+ response = await fetch(endpoint.toString());
418
+ } catch (error) {
419
+ console.warn("Muse request failed:", error);
420
+ break;
421
+ }
422
 
423
+ if (!response.ok) {
424
+ /*
425
+ * 403 usually means keyless test rate limit.
426
+ */
427
+ if (response.status === 403) {
428
+ break;
429
+ }
430
 
431
+ continue;
432
+ }
433
 
434
+ const data = await response.json();
435
 
436
+ if (!Array.isArray(data.results)) {
437
+ break;
438
+ }
439
 
440
+ if (data.results.length === 0) {
441
+ break;
442
+ }
443
 
444
+ for (const raw of data.results) {
445
 
446
+ const normalized = normalizeMuseJob(raw);
447
 
448
+ if (!normalized.url) {
449
+ continue;
450
+ }
451
 
452
+ if (!seenUrls.has(normalized.url)) {
453
+ seenUrls.add(normalized.url);
454
+ jobs.push(normalized);
455
+ }
456
+ }
457
 
458
+ if (
459
+ data.page_count &&
460
+ page >= Number(data.page_count)
461
+ ) {
462
+ break;
463
+ }
464
+ }
465
+ }
466
 
467
+ return jobs;
468
+ }
469
 
 
 
 
 
 
 
470
 
471
+ function buildMuseLocationQueries(location, plan) {
472
 
473
+ if (plan.remoteOnly) {
474
+ return ["Flexible / Remote"];
475
+ }
476
 
477
+ if (isBroadUSLocation(location)) {
478
+ /*
479
+ * Empty query lets us read current listings and then
480
+ * JobAlign keeps only US locations locally.
481
+ */
482
+ return [""];
483
+ }
484
 
485
+ if (isBroadEuropeLocation(location)) {
486
+ return [""];
487
+ }
488
 
489
+ const values = [location.trim()];
 
 
 
490
 
491
+ const stateCode = detectUSStateCode(location);
492
+ const stateName = detectUSStateName(location);
493
 
494
+ if (stateName && !values.includes(stateName)) {
495
+ values.push(stateName);
496
+ }
497
 
498
+ if (stateCode && !values.includes(stateCode)) {
499
+ values.push(stateCode);
500
+ }
 
 
501
 
502
+ return Array.from(new Set(values));
503
+ }
504
 
 
 
505
 
506
+ function normalizeMuseJob(job) {
507
 
508
+ const locations =
509
+ Array.isArray(job.locations)
510
+ ? job.locations
511
+ .map(function (item) {
512
+ return item.name;
513
+ })
514
+ .filter(Boolean)
515
+ : [];
516
 
517
+ const categories =
518
+ Array.isArray(job.categories)
519
+ ? job.categories
520
+ .map(function (item) {
521
+ return item.name;
522
+ })
523
+ .filter(Boolean)
524
+ : [];
525
 
526
+ const levels =
527
+ Array.isArray(job.levels)
528
+ ? job.levels
529
+ .map(function (item) {
530
+ return item.name;
531
+ })
532
+ .filter(Boolean)
533
+ : [];
534
 
535
+ return {
536
+ title: job.name || "",
537
+ company_name:
538
+ job.company && job.company.name
539
+ ? job.company.name
540
+ : "",
541
+ location: locations.join(" · "),
542
+ description: job.contents || "",
543
+ url:
544
+ job.refs && job.refs.landing_page
545
+ ? job.refs.landing_page
546
+ : "",
547
+ remote:
548
+ locations.some(function (value) {
549
+ return normalizeSimple(value).includes("remote");
550
+ }),
551
+ tags: categories.concat(levels),
552
+ source: "The Muse"
553
+ };
554
+ }
 
 
 
 
555
 
556
 
557
+ /* =========================================================
558
+ JOBICY
559
+ REMOTE GEOGRAPHIC JOBS
560
+ ========================================================= */
561
 
562
+ async function fetchJobicyJobs(keyword, geo) {
563
 
564
+ const endpoint = new URL(
565
+ "https://jobicy.com/api/v2/remote-jobs"
566
+ );
567
 
568
+ endpoint.searchParams.set("count", "200");
569
+ endpoint.searchParams.set("tag", keyword);
570
 
571
+ if (geo) {
572
+ endpoint.searchParams.set("geo", geo);
573
+ }
574
 
575
+ const response = await fetch(endpoint.toString());
 
 
 
576
 
577
+ if (!response.ok) {
578
+ throw new Error(
579
+ "Jobicy returned HTTP " +
580
+ response.status
581
+ );
582
+ }
583
 
584
+ const data = await response.json();
585
+ const rawJobs =
586
+ Array.isArray(data.jobs)
587
+ ? data.jobs
588
+ : [];
589
 
590
+ return rawJobs.map(function (job) {
591
+
592
+ return {
593
+ title: job.jobTitle || "",
594
+ company_name: job.companyName || "",
595
+ location: job.jobGeo || "Remote",
596
+ description:
597
+ job.jobDescription ||
598
+ job.jobExcerpt ||
599
+ "",
600
+ url: job.url || "",
601
+ remote: true,
602
+ tags:
603
+ []
604
+ .concat(job.jobIndustry || [])
605
+ .concat(job.jobType || [])
606
+ .concat(
607
+ job.jobLevel
608
+ ? [job.jobLevel]
609
+ : []
610
+ ),
611
+ source: "Jobicy"
612
+ };
613
+ });
614
+ }
615
 
 
616
 
617
+ /* =========================================================
618
+ REMOTE OK
619
+ ========================================================= */
620
 
621
+ async function fetchRemoteOKJobs() {
 
622
 
623
+ const response = await fetch(
624
+ "https://remoteok.com/api"
625
+ );
626
 
627
+ if (!response.ok) {
628
+ throw new Error(
629
+ "Remote OK returned HTTP " +
630
+ response.status
631
+ );
632
+ }
633
 
634
+ const data = await response.json();
635
 
636
+ if (!Array.isArray(data)) {
637
+ return [];
638
  }
639
+
640
+ return data
641
+ .filter(function (job) {
642
+ return (
643
+ job &&
644
+ (
645
+ job.position ||
646
+ job.company
647
+ )
648
+ );
649
+ })
650
+ .map(function (job) {
651
+
652
+ return {
653
+ title: job.position || "",
654
+ company_name: job.company || "",
655
+ location: job.location || "Remote",
656
+ description: job.description || "",
657
+ url: job.url || "",
658
+ remote: true,
659
+ tags:
660
+ Array.isArray(job.tags)
661
+ ? job.tags
662
+ : [],
663
+ source: "Remote OK"
664
+ };
665
+ });
666
  }
667
 
668
 
669
+ /* =========================================================
670
+ ROLE MATCHING
671
+ ========================================================= */
672
 
673
+ function calculateRoleScore(job, keyword) {
 
 
674
 
675
+ const title = normalizeSimple(job.title);
676
+ const description = normalizeSimple(
677
+ stripHTML(job.description || "")
678
+ );
 
679
 
680
+ const search = normalizeSimple(keyword);
681
 
682
+ const ignored = new Set([
683
+ "and",
684
+ "the",
685
+ "for",
686
+ "with",
687
+ "remote",
688
+ "hybrid"
689
+ ]);
 
690
 
691
+ const words =
692
+ search
693
+ .split(" ")
694
+ .filter(function (word) {
695
+ return (
696
+ word.length > 2 &&
697
+ !ignored.has(word)
698
+ );
699
+ });
700
 
701
+ if (!words.length) {
702
+ return 0;
703
+ }
 
 
704
 
705
+ let score = 0;
706
+ let titleMatches = 0;
 
707
 
708
+ if (title.includes(search)) {
709
+ score += 180;
710
+ }
711
 
712
+ words.forEach(function (word) {
 
 
 
 
 
 
 
 
713
 
714
+ if (title.includes(word)) {
715
+ titleMatches++;
716
+ score += 55;
717
+ }
718
 
719
+ if (description.includes(word)) {
720
+ score += 3;
721
+ }
722
+ });
723
 
724
+ /*
725
+ * Avoid "Influencer Marketing Manager"
726
+ * appearing for "Product Manager".
727
+ */
728
+ if (
729
+ words.length === 2 &&
730
+ titleMatches < 2
731
+ ) {
732
+ return 0;
733
  }
734
 
735
+ if (words.length >= 3) {
736
 
737
+ const requiredMatches =
738
+ Math.ceil(
739
+ words.length * 0.6
740
+ );
741
 
742
+ if (titleMatches < requiredMatches) {
743
+ return 0;
744
+ }
745
  }
746
 
 
747
  if (
748
+ words.length === 1 &&
749
+ titleMatches === 0
750
  ) {
751
+ return 0;
 
 
 
752
  }
753
 
754
+ return score;
755
+ }
756
 
 
 
 
 
757
 
758
+ /* =========================================================
759
+ GENERIC LOCATION MATCHING
760
+ ========================================================= */
761
 
762
+ function locationMatches(job, requestedLocation) {
763
+
764
+ const requested = normalizeLocationForMatch(
765
+ requestedLocation
 
 
 
 
 
 
766
  );
 
767
 
768
+ const actual = normalizeLocationForMatch(
769
+ job.location || ""
770
+ );
771
 
772
+ /*
773
+ * REMOTE
774
+ */
775
+ if (requested.includes("remote")) {
776
+ return Boolean(job.remote);
777
+ }
778
 
779
+ /*
780
+ * UNITED STATES / USA / US
781
+ */
782
+ if (isBroadUSLocation(requestedLocation)) {
783
+
784
+ return (
785
+ looksLikeUSJobLocation(job.location) ||
786
+ (
787
+ job.remote &&
788
+ normalizeSimple(job.location)
789
+ .includes("usa")
790
+ )
791
+ );
792
+ }
793
 
794
+ /*
795
+ * EUROPE
796
+ */
797
+ if (isBroadEuropeLocation(requestedLocation)) {
798
+
799
+ return (
800
+ looksLikeEuropeLocation(job.location) ||
801
+ (
802
+ job.remote &&
803
+ normalizeSimple(job.location)
804
+ .includes("europe")
805
+ )
806
+ );
807
+ }
808
 
809
+ /*
810
+ * US STATE
811
+ * User may type:
812
+ * Utah
813
+ * UT
814
+ * California
815
+ * CA
816
+ */
817
+ const requestedState =
818
+ detectUSStateCode(requestedLocation);
819
 
820
+ if (requestedState) {
821
 
822
+ if (
823
+ locationContainsState(
824
+ job.location,
825
+ requestedState
826
+ )
827
+ ) {
828
+ return true;
829
+ }
830
 
831
+ const stateName =
832
+ stateNameFromCode(
833
+ requestedState
834
+ );
835
 
836
+ if (
837
+ stateName &&
838
+ actual.includes(
839
+ normalizeLocationForMatch(
840
+ stateName
841
+ )
842
+ )
843
+ ) {
844
+ return true;
845
+ }
846
 
847
+ /*
848
+ * If the user typed a city + state,
849
+ * state alone is not enough.
850
+ */
851
+ const requestedCity =
852
+ extractRequestedCity(
853
+ requestedLocation
854
  );
855
 
856
+ if (requestedCity) {
857
+
858
+ return (
859
+ actual.includes(
860
+ normalizeLocationForMatch(
861
+ requestedCity
862
+ )
863
+ ) &&
864
+ (
865
+ locationContainsState(
866
+ job.location,
867
+ requestedState
868
+ ) ||
869
+ actual.includes(
870
+ normalizeLocationForMatch(
871
+ stateNameFromCode(
872
+ requestedState
873
+ )
874
+ )
875
+ )
876
+ )
877
+ );
878
+ }
879
 
880
+ return false;
881
+ }
882
 
883
+ /*
884
+ * GENERIC CITY / REGION / COUNTRY
885
+ *
886
+ * Whatever the user typed must actually be
887
+ * represented in the returned job location.
888
+ */
889
+ if (!requested || !actual) {
890
+ return false;
891
+ }
892
 
893
+ if (actual.includes(requested)) {
894
+ return true;
895
+ }
896
 
897
+ const requestedTokens =
898
+ getLocationTokens(requested);
 
899
 
900
+ if (!requestedTokens.length) {
901
+ return false;
902
+ }
903
 
904
+ return requestedTokens.every(function (token) {
905
+ return actual.includes(token);
906
+ });
907
+ }
908
 
 
 
 
909
 
910
+ function calculateLocationScore(job, requestedLocation) {
 
 
 
911
 
912
+ if (!locationMatches(job, requestedLocation)) {
913
+ return 0;
914
+ }
915
 
916
+ const requested =
917
+ normalizeLocationForMatch(
918
+ requestedLocation
919
+ );
920
 
921
+ const actual =
922
+ normalizeLocationForMatch(
923
+ job.location || ""
924
+ );
925
 
926
+ if (actual === requested) {
927
+ return 300;
928
+ }
929
 
930
+ if (actual.includes(requested)) {
931
+ return 250;
932
+ }
933
 
934
+ const requestedState =
935
+ detectUSStateCode(
936
+ requestedLocation
937
+ );
938
 
939
  if (
940
+ requestedState &&
941
+ locationContainsState(
942
+ job.location,
943
+ requestedState
944
+ )
945
  ) {
946
+ return 200;
947
+ }
948
 
949
+ if (job.remote) {
950
+ return 150;
951
+ }
952
 
953
+ return 180;
954
+ }
955
 
 
956
 
957
+ /* =========================================================
958
+ RENDER JOBS
959
+ ========================================================= */
960
 
961
+ function renderJobs(keyword, location) {
962
 
963
+ if (currentMatches.length === 0) {
964
 
965
+ resultsBox.innerHTML = `
966
+ <div class="empty-state">
967
+ <div>
968
+ No matching
969
+ <strong>${escapeHTML(keyword)}</strong>
970
+ jobs were found for
971
+ <strong>${escapeHTML(location)}</strong>.
972
  <br><br>
973
+ JobAlign will not substitute jobs from an
974
+ unrelated location.
 
 
 
 
 
975
  <br><br>
976
+ Try the state, country, nearby city, or Remote.
 
 
977
  </div>
 
978
  </div>
979
  `;
980
 
981
  return;
982
  }
983
 
 
984
  const cards =
985
  currentMatches
986
+ .map(function (job, index) {
987
+ return createJobCard(
988
+ job,
989
+ index
990
+ );
991
+ })
 
 
 
992
  .join("");
993
 
 
994
  resultsBox.innerHTML = `
995
+ <div style="margin-bottom:18px;">
996
+ <strong style="font-size:18px;">
997
+ ${currentMatches.length} matching jobs
 
 
 
 
 
 
 
998
  </strong>
999
 
 
1000
  <div style="
1001
  color:#777;
1002
+ margin-top:6px;
1003
  font-size:12px;
1004
  ">
1005
+ ${escapeHTML(keyword)}
1006
+ ·
1007
+ ${escapeHTML(location)}
1008
  </div>
 
1009
  </div>
1010
 
 
1011
  <div style="
1012
  display:grid;
1013
  gap:12px;
1014
  ">
 
1015
  ${cards}
 
1016
  </div>
1017
+ `;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1018
 
1019
+ resultsBox
1020
+ .querySelectorAll(".select-job-btn")
1021
+ .forEach(function (button) {
1022
 
1023
+ button.addEventListener(
1024
+ "click",
1025
+ function () {
1026
 
1027
+ const index =
1028
+ Number(
1029
+ button.dataset.index
1030
+ );
1031
 
1032
+ fillSelectedJob(
1033
+ currentMatches[index]
1034
+ );
1035
+ }
1036
+ );
1037
+ });
1038
+ }
1039
 
 
 
 
 
 
 
 
1040
 
1041
+ function createJobCard(job, index) {
1042
 
1043
  const description =
1044
  stripHTML(
1045
  job.description || ""
1046
  );
1047
 
 
1048
  const excerpt =
1049
+ description.length > 300
1050
  ? description.substring(
1051
  0,
1052
+ 300
1053
  ) + "..."
1054
  : description;
1055
 
 
1056
  const tags =
1057
  Array.isArray(job.tags)
1058
  ? job.tags.slice(0, 5)
1059
  : [];
1060
 
1061
+ const tagHTML =
 
1062
  tags
1063
+ .map(function (tag) {
1064
+ return `
1065
+ <span style="
1066
+ border:1px solid #292929;
1067
+ border-radius:999px;
1068
+ padding:5px 9px;
1069
+ font-size:11px;
1070
+ color:#aaa;
1071
+ ">
1072
+ ${escapeHTML(tag)}
1073
+ </span>
1074
+ `;
1075
+ })
 
 
 
 
1076
  .join("");
1077
 
 
1078
  return `
 
1079
  <div style="
1080
  padding:20px;
1081
  border:1px solid #2b2b2b;
 
1103
  letter-spacing:1px;
1104
  margin-bottom:7px;
1105
  ">
1106
+ ${escapeHTML(
1107
+ job.company_name ||
1108
+ "Company"
1109
+ )}
1110
  </div>
1111
 
 
1112
  <strong style="
1113
  display:block;
1114
  font-size:18px;
1115
  margin-bottom:8px;
1116
  ">
1117
+ ${escapeHTML(job.title)}
1118
  </strong>
1119
 
 
1120
  <div style="
1121
  color:#999;
1122
  font-size:13px;
1123
  margin-bottom:12px;
1124
  ">
1125
+ ${escapeHTML(
1126
+ job.location ||
1127
+ (
1128
+ job.remote
1129
+ ? "Remote"
1130
+ : "Location not listed"
1131
+ )
1132
+ )}
1133
  </div>
1134
 
 
1135
  <p style="
1136
  color:#888;
1137
  line-height:1.6;
 
1140
  ${escapeHTML(excerpt)}
1141
  </p>
1142
 
 
1143
  ${
1144
  tags.length
1145
  ? `
 
1149
  gap:6px;
1150
  margin-top:14px;
1151
  ">
1152
+ ${tagHTML}
1153
  </div>
1154
  `
1155
  : ""
1156
  }
1157
 
1158
+ <div style="
1159
+ color:#555;
1160
+ font-size:10px;
1161
+ margin-top:13px;
1162
+ ">
1163
+ Source:
1164
+ ${escapeHTML(job.source)}
1165
+ </div>
1166
 
1167
+ </div>
1168
 
1169
  <button
1170
  class="primary-btn select-job-btn"
 
1175
  </button>
1176
 
1177
  </div>
 
1178
  </div>
1179
  `;
1180
  }
1181
 
1182
 
1183
+ /* =========================================================
 
1184
  SELECT JOB
1185
+ ========================================================= */
1186
 
1187
  function fillSelectedJob(job) {
1188
 
1189
  if (!job) {
1190
+ alert("Unable to load this job.");
 
 
 
 
1191
  return;
1192
  }
1193
 
1194
+ selectedJob = job;
 
 
 
1195
 
1196
  selectedJobTitle.value =
1197
  job.title || "";
1198
 
 
1199
  selectedCompany.value =
1200
  job.company_name || "";
1201
 
 
1202
  selectedLocation.value =
1203
  job.location ||
1204
  (
 
1207
  : ""
1208
  );
1209
 
 
1210
  jobDescription.value =
1211
  stripHTML(
1212
  job.description || ""
1213
  );
1214
 
 
1215
  jobUrlInput.value =
1216
  job.url || "";
1217
 
 
1218
  resetAnalysis();
1219
 
 
1220
  generationStatus.innerHTML = `
 
1221
  <div class="status-dot"></div>
 
1222
  <span class="success-text">
 
1223
  Selected:
1224
+ ${escapeHTML(job.title || "")}
 
 
 
1225
  at
1226
+ ${escapeHTML(job.company_name || "")}
 
 
 
 
1227
  </span>
1228
  `;
1229
 
 
1230
  analysisResults.innerHTML = `
 
1231
  <div class="empty-state">
 
1232
  <div>
 
1233
  Job loaded successfully.
 
1234
  <br><br>
 
1235
  Add your master resume and click
 
1236
  <strong>
1237
  Analyze Selected Job
1238
  </strong>.
 
1239
  </div>
 
1240
  </div>
1241
  `;
1242
 
 
1243
  selectedJobCard.scrollIntoView({
1244
  behavior: "smooth",
1245
  block: "start"
 
1247
  }
1248
 
1249
 
1250
+ /* =========================================================
1251
+ ORIGINAL JOB
1252
+ ========================================================= */
 
1253
 
1254
  openOriginalJobBtn.addEventListener(
1255
  "click",
 
1258
  const url =
1259
  jobUrlInput.value.trim();
1260
 
 
1261
  if (!url) {
1262
+ alert("Select a job first.");
 
 
 
 
1263
  return;
1264
  }
1265
 
 
1266
  window.open(
1267
  url,
1268
  "_blank",
 
1272
  );
1273
 
1274
 
1275
+ /* =========================================================
1276
+ RESUME UPLOAD + SAVE
1277
+ ========================================================= */
1278
 
1279
+ resumeFile.addEventListener(
1280
+ "change",
1281
+ async function () {
 
 
 
 
 
 
 
 
 
 
 
 
1282
 
1283
+ const file =
1284
+ resumeFile.files[0];
 
1285
 
1286
+ if (!file) {
1287
  return;
1288
  }
1289
 
1290
+ const extension =
1291
+ file.name
1292
+ .split(".")
1293
+ .pop()
1294
+ .toLowerCase();
 
1295
 
1296
  resumeStatus.innerHTML = `
 
1297
  <div class="status-dot"></div>
1298
+ <span>
1299
+ Reading
1300
+ ${escapeHTML(file.name)}...
1301
  </span>
1302
  `;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1303
 
1304
+ try {
 
 
1305
 
1306
+ if (extension === "txt") {
1307
 
1308
+ const content =
1309
+ await file.text();
 
1310
 
1311
+ saveExtractedResume(
1312
+ content,
1313
+ file.name
1314
  );
1315
+
1316
+ return;
1317
  }
1318
 
1319
+ if (extension === "docx") {
1320
 
1321
+ if (
1322
+ typeof mammoth ===
1323
+ "undefined"
1324
+ ) {
1325
+ throw new Error(
1326
+ "DOCX reader did not load. Refresh the page and try again."
1327
+ );
1328
+ }
1329
 
1330
+ const arrayBuffer =
1331
+ await file.arrayBuffer();
1332
 
1333
+ const result =
1334
+ await mammoth.extractRawText({
1335
+ arrayBuffer: arrayBuffer
1336
+ });
 
1337
 
1338
+ const content =
1339
+ result.value.trim();
1340
 
1341
+ if (content.length < 100) {
1342
+ throw new Error(
1343
+ "Very little resume text was found in this DOCX."
1344
+ );
1345
+ }
1346
 
1347
+ saveExtractedResume(
1348
+ content,
1349
+ file.name
1350
+ );
1351
 
1352
+ return;
1353
+ }
 
1354
 
1355
+ if (extension === "pdf") {
1356
  throw new Error(
1357
+ "PDF reading is not enabled yet. Upload DOCX or TXT."
1358
  );
1359
  }
1360
 
1361
+ throw new Error(
1362
+ "Use a DOCX or TXT resume."
 
 
1363
  );
1364
 
1365
+ } catch (error) {
 
 
 
 
 
 
1366
 
1367
+ console.error(error);
1368
 
1369
  resumeStatus.innerHTML = `
 
1370
  <div class="status-dot"></div>
1371
+ <span class="danger-text">
1372
+ Could not read resume:
1373
+ ${escapeHTML(error.message)}
 
 
 
1374
  </span>
1375
  `;
 
 
1376
  }
1377
+ }
1378
+ );
1379
 
1380
 
1381
+ function saveExtractedResume(
1382
+ content,
1383
+ fileName
1384
+ ) {
1385
 
1386
+ const clean =
1387
+ content
1388
+ .replace(/\r/g, "")
1389
+ .replace(/\n{3,}/g, "\n\n")
1390
+ .trim();
1391
 
1392
+ resumeText.value = clean;
1393
 
1394
+ localStorage.setItem(
1395
+ "jobalign_master_resume",
1396
+ clean
1397
+ );
1398
+
1399
+ localStorage.setItem(
1400
+ "jobalign_master_resume_filename",
1401
+ fileName
1402
+ );
1403
+
1404
+ resumeStatus.innerHTML = `
1405
+ <div class="status-dot"></div>
1406
+ <span class="success-text">
1407
+ ${escapeHTML(fileName)}
1408
+ loaded and saved successfully
1409
+ </span>
1410
+ `;
1411
+ }
1412
 
 
1413
 
1414
+ saveResumeBtn.addEventListener(
1415
+ "click",
1416
+ function () {
1417
 
1418
+ const resume =
1419
+ resumeText.value.trim();
1420
 
1421
+ if (resume.length < 100) {
1422
+ alert(
1423
+ "Paste your complete master resume first."
1424
+ );
1425
  return;
1426
  }
1427
 
1428
+ localStorage.setItem(
1429
+ "jobalign_master_resume",
1430
+ resume
1431
  );
1432
 
 
 
 
 
 
 
1433
  resumeStatus.innerHTML = `
 
1434
  <div class="status-dot"></div>
1435
+ <span class="success-text">
1436
+ Master resume saved in this browser
 
 
 
 
1437
  </span>
1438
  `;
1439
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1440
  );
1441
 
1442
 
1443
+ /* =========================================================
1444
+ ATS ANALYSIS
1445
+ ========================================================= */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1446
 
1447
  const skills = [
 
1448
  "python",
1449
  "sql",
1450
  "java",
 
1547
  ];
1548
 
1549
 
 
 
 
 
 
1550
  analyzeJobBtn.addEventListener(
1551
  "click",
1552
  analyzeJob
 
1556
  function analyzeJob() {
1557
 
1558
  const jd =
1559
+ jobDescription.value.toLowerCase();
 
 
 
1560
 
1561
  const resume =
1562
+ resumeText.value.toLowerCase();
 
 
 
 
 
 
 
1563
 
1564
+ if (jd.length < 100) {
1565
  alert(
1566
  "Search and select a job first."
1567
  );
 
1568
  return;
1569
  }
1570
 
1571
+ if (resume.length < 100) {
 
 
 
 
1572
  alert(
1573
  "Add your master resume first."
1574
  );
 
1575
  return;
1576
  }
1577
 
1578
+ const required =
1579
+ skills.filter(function (skill) {
1580
+ return jd.includes(skill);
1581
+ });
1582
+
1583
+ const matched =
1584
+ required.filter(function (skill) {
1585
+ return resume.includes(skill);
1586
+ });
1587
 
1588
+ const gaps =
1589
+ required.filter(function (skill) {
1590
+ return !resume.includes(skill);
1591
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1592
 
1593
  const coverage =
1594
  required.length
1595
  ? Math.round(
1596
+ (
1597
+ matched.length /
1598
+ required.length
1599
+ ) * 100
1600
  )
1601
  : 50;
1602
 
 
1603
  const calculatedAts =
1604
  Math.min(
1605
  97,
 
1609
  )
1610
  );
1611
 
 
1612
  atsScore.textContent =
1613
  calculatedAts + "%";
1614
 
 
1615
  keywordScore.textContent =
1616
  coverage + "%";
1617
 
 
1618
  matchedSkills.textContent =
1619
  matched.length;
1620
 
 
1621
  missingSkills.textContent =
1622
  gaps.length;
1623
 
 
1624
  analysisResults.innerHTML = `
 
1625
  <div>
 
1626
  <strong>
1627
  Matching experience
1628
  </strong>
1629
 
 
1630
  <p style="
1631
  color:#aaa;
1632
  margin-top:8px;
1633
  line-height:1.7;
1634
  ">
 
1635
  ${
1636
  matched.length
1637
  ? escapeHTML(
 
1639
  )
1640
  : "No major keyword matches detected."
1641
  }
 
1642
  </p>
 
1643
  </div>
1644
 
1645
+ <div style="margin-top:20px;">
 
 
 
 
1646
  <strong>
1647
  Job priorities not currently visible
1648
  </strong>
1649
 
 
1650
  <p style="
1651
  color:#aaa;
1652
  margin-top:8px;
1653
  line-height:1.7;
1654
  ">
 
1655
  ${
1656
  gaps.length
1657
  ? escapeHTML(
 
1659
  )
1660
  : "No obvious technical keyword gaps detected."
1661
  }
 
1662
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1663
  </div>
1664
  `;
1665
  }
1666
 
1667
 
1668
+ /* =========================================================
1669
+ AI RESUME GENERATION
1670
+ ========================================================= */
 
1671
 
1672
  generateResumeBtn.addEventListener(
1673
  "click",
1674
+ async function () {
1675
 
1676
  const jd =
1677
  jobDescription.value.trim();
1678
 
 
1679
  const resume =
1680
  resumeText.value.trim();
1681
 
1682
+ const jobTitle =
1683
+ selectedJobTitle.value.trim();
1684
 
1685
+ const company =
1686
+ selectedCompany.value.trim();
 
1687
 
1688
+ const location =
1689
+ selectedLocation.value.trim();
1690
+
1691
+ if (jd.length < 100) {
1692
  alert(
1693
+ "Search for and select a job first."
1694
  );
 
1695
  return;
1696
  }
1697
 
1698
+ if (resume.length < 100) {
 
 
 
 
1699
  alert(
1700
  "Add your master resume first."
1701
  );
 
1702
  return;
1703
  }
1704
 
1705
+ generateResumeBtn.disabled = true;
1706
+ generateResumeBtn.textContent =
1707
+ "Generating Resume...";
1708
 
1709
+ resumeOutput.textContent =
1710
+ `Preparing JobAlign AI...
 
1711
 
1712
+ Target Role:
1713
+ ${jobTitle}
1714
 
1715
+ Company:
1716
+ ${company}
1717
 
1718
+ The first run may take longer because the local AI model must load in your browser.`;
 
1719
 
1720
+ try {
1721
 
1722
+ let attempts = 0;
 
1723
 
1724
+ while (
1725
+ !window.JobAlignAI &&
1726
+ attempts < 150
1727
+ ) {
1728
 
1729
+ await new Promise(
1730
+ function (resolve) {
1731
+ setTimeout(
1732
+ resolve,
1733
+ 100
1734
+ );
1735
+ }
1736
+ );
1737
 
1738
+ attempts++;
1739
+ }
1740
 
1741
+ if (!window.JobAlignAI) {
1742
+ throw new Error(
1743
+ "The local AI engine did not load. Refresh the page and try again."
1744
+ );
1745
+ }
1746
 
1747
+ const rewrittenResume =
1748
+ await window.JobAlignAI
1749
+ .generateResume({
1750
+ resume: resume,
1751
+ jobDescription: jd,
1752
+ jobTitle: jobTitle,
1753
+ company: company,
1754
+ location: location
1755
+ });
1756
+
1757
+ resumeOutput.textContent =
1758
+ rewrittenResume;
1759
+
1760
+ localStorage.setItem(
1761
+ "jobalign_last_generated_resume",
1762
+ rewrittenResume
1763
+ );
1764
 
1765
+ generationStatus.innerHTML = `
1766
+ <div class="status-dot"></div>
1767
+ <span class="success-text">
1768
+ Resume generated for
1769
+ ${escapeHTML(jobTitle)}
1770
+ at
1771
+ ${escapeHTML(company)}
1772
+ </span>
1773
+ `;
1774
 
1775
+ interviewCheck.innerHTML = `
1776
+ <div>
1777
+ <strong>
1778
+ Targeted resume generated.
1779
+ </strong>
1780
 
1781
+ <p style="
1782
+ color:#aaa;
1783
+ margin-top:10px;
1784
+ line-height:1.7;
1785
+ ">
1786
+ Review every technical claim
1787
+ before submitting.
1788
+ </p>
1789
+ </div>
1790
+ `;
1791
 
1792
+ } catch (error) {
1793
 
1794
+ console.error(
1795
+ "JobAlign generation error:",
1796
+ error
1797
+ );
1798
 
1799
+ generationStatus.innerHTML = `
1800
+ <div class="status-dot"></div>
1801
+ <span class="danger-text">
1802
+ Resume generation failed:
1803
+ ${escapeHTML(error.message)}
1804
+ </span>
1805
+ `;
1806
 
1807
+ resumeOutput.textContent =
1808
+ `JobAlign could not generate the resume.
1809
 
1810
+ Error:
1811
+ ${error.message}`;
1812
 
1813
+ } finally {
 
1814
 
1815
+ generateResumeBtn.disabled =
1816
+ false;
1817
 
1818
+ generateResumeBtn.textContent =
1819
+ "Generate Resume For This Job";
1820
+ }
 
 
 
 
 
1821
  }
1822
  );
1823
 
1824
 
1825
+ /* =========================================================
 
1826
  COPY
1827
+ ========================================================= */
1828
 
1829
  copyResumeBtn.addEventListener(
1830
  "click",
 
1833
  const text =
1834
  resumeOutput.innerText.trim();
1835
 
 
1836
  if (
1837
  !text ||
1838
  text ===
1839
  "Your job-specific resume will appear here."
1840
  ) {
 
1841
  alert(
1842
+ "Generate a resume first."
1843
  );
 
1844
  return;
1845
  }
1846
 
 
1847
  try {
1848
 
1849
  await navigator
1850
  .clipboard
1851
+ .writeText(text);
 
 
 
1852
 
1853
  copyResumeBtn.textContent =
1854
  "Copied";
1855
 
 
1856
  setTimeout(
1857
  function () {
 
1858
  copyResumeBtn.textContent =
1859
  "Copy Resume";
 
1860
  },
1861
  1500
1862
  );
 
1871
  );
1872
 
1873
 
1874
+ /* =========================================================
 
1875
  DOWNLOAD
1876
+ ========================================================= */
1877
 
1878
  downloadResumeBtn.addEventListener(
1879
  "click",
 
1882
  const text =
1883
  resumeOutput.innerText.trim();
1884
 
 
1885
  if (
1886
  !text ||
1887
  text ===
1888
  "Your job-specific resume will appear here."
1889
  ) {
 
1890
  alert(
1891
+ "Generate a resume first."
1892
  );
 
1893
  return;
1894
  }
1895
 
 
1896
  const blob =
1897
  new Blob(
1898
  [text],
 
1902
  }
1903
  );
1904
 
 
1905
  const downloadUrl =
1906
+ URL.createObjectURL(blob);
 
 
 
1907
 
1908
  const link =
1909
+ document.createElement("a");
 
 
1910
 
1911
+ link.href = downloadUrl;
1912
 
1913
+ link.download =
1914
  safeFileName(
1915
  selectedCompany.value ||
1916
  "Company"
1917
+ ) +
1918
+ "_" +
 
 
1919
  safeFileName(
1920
  selectedJobTitle.value ||
1921
  "Resume"
1922
+ ) +
1923
+ "_Resume.txt";
1924
+
1925
+ link.click();
1926
+
1927
+ URL.revokeObjectURL(
1928
+ downloadUrl
1929
+ );
1930
+ }
1931
+ );
1932
+
1933
+
1934
+ /* =========================================================
1935
+ LOCATION HELPERS
1936
+ ========================================================= */
1937
+
1938
+ function normalizeLocationForMatch(value) {
1939
+
1940
+ return String(value || "")
1941
+ .toLowerCase()
1942
+ .replace(/\busa\b/g, "united states")
1943
+ .replace(/\bu\.s\.a\.\b/g, "united states")
1944
+ .replace(/\bu\.s\.\b/g, "united states")
1945
+ .replace(/[^a-z0-9\s]/g, " ")
1946
+ .replace(/\s+/g, " ")
1947
+ .trim();
1948
+ }
1949
+
1950
+
1951
+ function getLocationTokens(location) {
1952
+
1953
+ const ignored = new Set([
1954
+ "the",
1955
+ "of",
1956
+ "area",
1957
+ "metro",
1958
+ "region"
1959
+ ]);
1960
+
1961
+ return String(location || "")
1962
+ .split(" ")
1963
+ .filter(function (word) {
1964
+ return (
1965
+ word.length > 1 &&
1966
+ !ignored.has(word)
1967
  );
1968
+ });
1969
+ }
1970
 
1971
 
1972
+ function detectUSStateCode(location) {
 
1973
 
1974
+ const normalized =
1975
+ normalizeSimple(location);
1976
 
1977
+ for (
1978
+ const [stateName, code]
1979
+ of Object.entries(US_STATES)
1980
+ ) {
1981
+ if (
1982
+ normalized === stateName ||
1983
+ normalized.includes(
1984
+ stateName
1985
+ )
1986
+ ) {
1987
+ return code;
1988
+ }
1989
+ }
1990
 
1991
+ const upper =
1992
+ String(location || "")
1993
+ .toUpperCase();
1994
 
1995
+ for (const code of US_STATE_CODES) {
1996
+
1997
+ const pattern =
1998
+ new RegExp(
1999
+ "(^|[,\\s])" +
2000
+ code +
2001
+ "($|[,\\s])"
2002
+ );
2003
 
2004
+ if (pattern.test(upper)) {
2005
+ return code;
2006
+ }
2007
+ }
2008
 
2009
+ return "";
2010
+ }
2011
+
2012
+
2013
+ function detectUSStateName(location) {
2014
+
2015
+ const code =
2016
+ detectUSStateCode(location);
2017
+
2018
+ if (!code) {
2019
+ return "";
2020
+ }
2021
+
2022
+ return stateNameFromCode(code);
2023
+ }
2024
+
2025
+
2026
+ function stateNameFromCode(code) {
2027
+
2028
+ const match =
2029
+ Object.entries(US_STATES)
2030
+ .find(function (entry) {
2031
+ return entry[1] === code;
2032
+ });
2033
+
2034
+ return match
2035
+ ? match[0]
2036
+ : "";
2037
+ }
2038
+
2039
+
2040
+ function extractRequestedCity(location) {
2041
+
2042
+ const raw =
2043
+ String(location || "")
2044
+ .trim();
2045
+
2046
+ const stateCode =
2047
+ detectUSStateCode(raw);
2048
+
2049
+ const stateName =
2050
+ detectUSStateName(raw);
2051
+
2052
+ let city =
2053
+ raw
2054
+ .replace(
2055
+ new RegExp(
2056
+ "\\b" +
2057
+ escapeRegExp(
2058
+ stateCode
2059
+ ) +
2060
+ "\\b",
2061
+ "i"
2062
+ ),
2063
+ ""
2064
+ )
2065
+ .replace(
2066
+ new RegExp(
2067
+ "\\b" +
2068
+ escapeRegExp(
2069
+ stateName
2070
+ ) +
2071
+ "\\b",
2072
+ "i"
2073
+ ),
2074
+ ""
2075
+ )
2076
+ .replace(
2077
+ /united states|usa|u\.s\.a\.|u\.s\./gi,
2078
+ ""
2079
+ )
2080
+ .replace(/,/g, " ")
2081
+ .replace(/\s+/g, " ")
2082
+ .trim();
2083
+
2084
+ if (
2085
+ normalizeSimple(city) ===
2086
+ normalizeSimple(stateName)
2087
+ ) {
2088
+ return "";
2089
+ }
2090
+
2091
+ return city;
2092
+ }
2093
+
2094
+
2095
+ function locationContainsState(
2096
+ location,
2097
+ stateCode
2098
+ ) {
2099
+
2100
+ const upper =
2101
+ String(location || "")
2102
+ .toUpperCase();
2103
+
2104
+ const pattern =
2105
+ new RegExp(
2106
+ "(^|[,\\s])" +
2107
+ stateCode +
2108
+ "($|[,\\s])"
2109
  );
2110
+
2111
+ return pattern.test(upper);
2112
+ }
2113
+
2114
+
2115
+ function looksLikeUSLocation(location) {
2116
+
2117
+ const normalized =
2118
+ normalizeSimple(location);
2119
+
2120
+ if (
2121
+ [
2122
+ "us",
2123
+ "usa",
2124
+ "united states",
2125
+ "united states of america"
2126
+ ].includes(normalized)
2127
+ ) {
2128
+ return true;
2129
  }
 
2130
 
2131
+ return Boolean(
2132
+ detectUSStateCode(location)
2133
+ );
2134
+ }
2135
+
2136
+
2137
+ function looksLikeUSJobLocation(location) {
2138
+
2139
+ if (
2140
+ looksLikeUSLocation(location)
2141
+ ) {
2142
+ return true;
2143
+ }
2144
+
2145
+ const normalized =
2146
+ normalizeSimple(location);
2147
+
2148
+ return (
2149
+ normalized.includes(
2150
+ "united states"
2151
+ ) ||
2152
+ normalized.includes("usa")
2153
+ );
2154
+ }
2155
+
2156
+
2157
+ function isBroadUSLocation(location) {
2158
+
2159
+ return [
2160
+ "us",
2161
+ "usa",
2162
+ "united states",
2163
+ "united states of america"
2164
+ ].includes(
2165
+ normalizeSimple(location)
2166
+ );
2167
+ }
2168
+
2169
+
2170
+ function looksLikeEuropeLocation(location) {
2171
+
2172
+ const value =
2173
+ normalizeSimple(location);
2174
+
2175
+ const terms = [
2176
+ "europe",
2177
+ "germany",
2178
+ "france",
2179
+ "netherlands",
2180
+ "sweden",
2181
+ "switzerland",
2182
+ "ireland",
2183
+ "spain",
2184
+ "italy",
2185
+ "portugal",
2186
+ "poland",
2187
+ "denmark",
2188
+ "norway",
2189
+ "finland",
2190
+ "austria",
2191
+ "belgium",
2192
+ "united kingdom",
2193
+ "uk"
2194
+ ];
2195
+
2196
+ return terms.some(function (term) {
2197
+ return value.includes(term);
2198
+ });
2199
+ }
2200
+
2201
+
2202
+ function isBroadEuropeLocation(location) {
2203
+
2204
+ return (
2205
+ normalizeSimple(location) ===
2206
+ "europe"
2207
+ );
2208
+ }
2209
+
2210
+
2211
+ /* =========================================================
2212
+ GENERAL HELPERS
2213
+ ========================================================= */
2214
+
2215
+ function dedupeJobs(jobs) {
2216
+
2217
+ const seen = new Set();
2218
+
2219
+ return jobs.filter(function (job) {
2220
+
2221
+ const key =
2222
+ normalizeSimple(job.title) +
2223
+ "|" +
2224
+ normalizeSimple(
2225
+ job.company_name
2226
+ ) +
2227
+ "|" +
2228
+ normalizeSimple(
2229
+ job.location
2230
+ );
2231
+
2232
+ if (seen.has(key)) {
2233
+ return false;
2234
+ }
2235
+
2236
+ seen.add(key);
2237
 
2238
+ return true;
2239
+ });
2240
+ }
2241
 
 
 
 
2242
 
2243
  function stripHTML(html) {
2244
 
2245
  const element =
2246
+ document.createElement("div");
 
 
 
2247
 
2248
  element.innerHTML =
2249
+ String(html || "");
 
2250
 
2251
  return (
2252
  element.textContent ||
2253
  element.innerText ||
2254
  ""
2255
  )
2256
+ .replace(/\s+/g, " ")
2257
+ .trim();
2258
+ }
2259
+
2260
+
2261
+ function normalizeSimple(value) {
2262
+
2263
+ return String(value || "")
2264
+ .toLowerCase()
2265
  .replace(
2266
+ /[^a-z0-9+#.]+/g,
2267
  " "
2268
  )
2269
+ .replace(/\s+/g, " ")
2270
  .trim();
2271
  }
2272
 
 
2274
  function escapeHTML(value) {
2275
 
2276
  const element =
2277
+ document.createElement("div");
 
 
 
2278
 
2279
  element.textContent =
2280
+ String(value || "");
 
 
 
2281
 
2282
  return element.innerHTML;
2283
  }
2284
 
2285
 
2286
+ function escapeRegExp(value) {
2287
+
2288
+ return String(value || "")
2289
+ .replace(
2290
+ /[.*+?^${}()|[\]\\]/g,
2291
+ "\\$&"
2292
+ );
2293
+ }
2294
+
2295
+
2296
  function safeFileName(value) {
2297
 
2298
+ return String(value || "")
2299
  .replace(
2300
  /[^a-z0-9]+/gi,
2301
  "_"
 
2309
 
2310
  function resetAnalysis() {
2311
 
2312
+ atsScore.textContent = "--";
2313
+ keywordScore.textContent = "--";
2314
+ matchedSkills.textContent = "--";
2315
+ missingSkills.textContent = "--";
 
 
 
 
 
 
 
 
 
 
2316
  }
2317
 
2318
+ });
2319
+ '''
2320
+
2321
+ path = Path("/mnt/data/app.js")
2322
+ path.write_text(app_js, encoding="utf-8")
2323
+ print(f"Created {path} with {len(app_js.splitlines())} lines.")