-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline_script_7.js
More file actions
411 lines (169 loc) · 9.82 KB
/
inline_script_7.js
File metadata and controls
411 lines (169 loc) · 9.82 KB
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
document.addEventListener('DOMContentLoaded', function() {
const jobDescriptionTextarea = document.getElementById('jobDescription');
const jobTitleOutput = document.getElementById('jobTitleOutput');
const booleanOutputTextarea = document.getElementById('booleanOutput');
const generateBtn = document.getElementById('generateBtn');
const copyTitleBtn = document.getElementById('copyTitleBtn');
const copyBooleanBtn = document.getElementById('copyBooleanBtn');
const loadingIndicator = document.getElementById('loadingIndicator');
// Function to format terms with quotes when needed
function formatBooleanTerm(term) {
term = term.trim();
// Skip if empty or just parentheses
if (!term || term === '(' || term === ')') return term;
// Check if term contains special characters or digits
const hasSpecialChars = /[^a-zA-Z\s]/.test(term);
// Check if term contains spaces (multi-word)
const isMultiWord = term.includes(' ');
// Add quotes if multi-word or has special characters
if (isMultiWord || hasSpecialChars) {
// Remove any existing quotes first
term = term.replace(/"/g, '');
return `"${term}"`;
}
return term;
}
// Function to process and format the entire boolean string
function formatBooleanString(booleanStr) {
// First, handle the parentheses content
booleanStr = booleanStr.replace(/\(([^)]+)\)/g, function(match, group) {
const formattedGroup = group.split('OR').map(term => {
return formatBooleanTerm(term);
}).join(' OR ');
return `(${formattedGroup})`;
});
// Then handle terms outside parentheses
const parts = booleanStr.split(/(AND|OR)/);
const formattedParts = parts.map(part => {
if (part === 'AND' || part === 'OR') {
return part;
}
// Skip if already processed (inside parentheses)
if (part.includes('(') || part.includes(')')) {
return part;
}
return formatBooleanTerm(part);
});
return formattedParts.join(' ');
}
// Function to fetch Gemini AI response
async function fetchGeminiResponse(question) {
const apiKey = 'AIzaSyBBNlnMeK1nX7m-WCum4PALM9bEpZXmKKQ';
const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=${apiKey}`;
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
contents: [{
parts: [{ text: question }]
}]
})
});
const data = await response.json();
return data;
}
generateBtn.addEventListener('click', async function() {
const jd = jobDescriptionTextarea.value.trim();
if (!jd) {
alert('Please paste a job description first.');
return;
}
// Show loading indicator
loadingIndicator.style.display = 'block';
jobTitleOutput.value = '';
booleanOutputTextarea.value = '';
generateBtn.disabled = true;
try {
// Enhanced title extraction prompt
const titlePrompt = `Analyze this job description and extract ALL possible job titles that would match this position:
1. First look for explicitly mentioned titles
2. If no titles found, derive from primary skills/technologies
3. Include common variations, abbreviations, and seniority levels
4. Consider industry-standard titles for the mentioned technologies
Return ONLY an OR-separated list in parentheses with no additional text.
Example 1 (explicit title):
("Senior Software Engineer" OR "Software Developer" OR "Application Engineer")
Example 2 (derived from skills):
("Python Developer" OR "Backend Engineer" OR "Django Developer")
Job Description:
${jd}`;
// Enhanced skills extraction prompt
const skillsPrompt = `Create a perfect Boolean search string by:
1. Identifying ALL technical components (languages, frameworks, tools, methodologies)
2. Grouping similar terms with OR (synonyms, versions, alternatives)
3. Combining different categories with AND
4. Formatting rules:
- Multi-word terms: "Data Modeling"
- Special characters/digits: "C#", "COBOL-85"
- Never quote parentheses or operators
Return ONLY the formatted Boolean string with no additional text.
Example Output:
(Java OR "Spring Boot") AND (Microservices OR "Micro services" OR "Micro-services" OR "API Development") AND (Agile OR Scrum)
Job Description:
${jd}
Return ONLY the Boolean search string, nothing else.`;
// Fetch both responses
const [titleResponse, skillsResponse] = await Promise.all([
fetchGeminiResponse(titlePrompt),
fetchGeminiResponse(skillsPrompt)
]);
// Process title response
if (titleResponse.candidates && titleResponse.candidates[0].content.parts[0].text) {
let titleString = titleResponse.candidates[0].content.parts[0].text;
// Format the titles with quotes
titleString = formatBooleanString(titleString);
jobTitleOutput.value = titleString;
} else {
jobTitleOutput.value = "Could not extract job titles";
}
// Process skills response
if (skillsResponse.candidates && skillsResponse.candidates[0].content.parts[0].text) {
let booleanString = skillsResponse.candidates[0].content.parts[0].text;
// Format the boolean string with proper quotes
booleanString = formatBooleanString(booleanString);
// Combine job titles with technical skills if both exist
if (jobTitleOutput.value && !jobTitleOutput.value.includes("Could not extract")) {
booleanString = `${jobTitleOutput.value} AND ${booleanString}`;
}
booleanOutputTextarea.value = booleanString;
} else {
booleanOutputTextarea.value = "Error: Could not generate Boolean search. Please try again.";
}
} catch (error) {
console.error('Error:', error);
booleanOutputTextarea.value = "Error: Failed to process the job description. Please check your API key and try again.";
} finally {
loadingIndicator.style.display = 'none';
generateBtn.disabled = false;
}
});
// Copy functions
function copyToClipboard(text, button) {
navigator.clipboard.writeText(text).then(() => {
const icon = button.querySelector('i');
const originalClass = icon.className;
icon.className = 'fas fa-check';
setTimeout(() => {
icon.className = originalClass;
}, 2000);
}).catch(err => {
console.error('Failed to copy: ', err);
});
}
// Copy job titles
copyTitleBtn.addEventListener('click', function() {
const textToCopy = jobTitleOutput.value;
if (textToCopy && textToCopy !== "Could not extract job titles") {
copyToClipboard(textToCopy, copyTitleBtn);
}
});
// Copy boolean search string
copyBooleanBtn.addEventListener('click', function() {
const textToCopy = booleanOutputTextarea.value;
if (textToCopy && !textToCopy.startsWith("Error:")) {
copyToClipboard(textToCopy, copyBooleanBtn);
}
});
});