CodeAntidote commited on
Commit
68b99ef
·
verified ·
1 Parent(s): 79b2c11

Extract and save DOCX resumes

Browse files
Files changed (1) hide show
  1. app.js +187 -26
app.js CHANGED
@@ -926,52 +926,138 @@ document.addEventListener("DOMContentLoaded", function () {
926
  TXT UPLOAD
927
  ===================================================== */
928
 
929
- resumeFile.addEventListener(
930
- "change",
931
- async function () {
932
 
933
- const file =
934
- resumeFile.files[0];
 
935
 
 
 
936
 
937
- if (!file) {
938
 
939
- return;
940
- }
 
941
 
942
 
943
- const extension =
944
- file.name
945
- .split(".")
946
- .pop()
947
- .toLowerCase();
948
 
949
 
950
- if (
951
- extension === "txt"
952
- ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
953
 
954
  const content =
955
  await file.text();
956
 
957
 
958
- resumeText.value =
959
- content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
960
 
 
961
 
962
  resumeStatus.innerHTML = `
963
 
964
  <div class="status-dot"></div>
965
 
966
- <span class="success-text">
967
 
968
- ${escapeHTML(file.name)}
969
- loaded
970
 
971
  </span>
972
  `;
973
 
974
- } else {
 
 
 
 
 
 
 
 
975
 
976
  resumeStatus.innerHTML = `
977
 
@@ -979,18 +1065,93 @@ document.addEventListener("DOMContentLoaded", function () {
979
 
980
  <span class="warning-text">
981
 
982
- PDF/DOCX selected.
983
-
984
- Direct PDF/DOCX reading will
985
- be added in a later build step.
986
 
987
  </span>
988
  `;
 
 
989
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
990
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
991
  );
992
 
993
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
994
 
995
  /* =====================================================
996
  ATS SKILL DICTIONARY
 
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
 
 
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