Skip to content

Instantly share code, notes, and snippets.

@AaronFeledy
Last active January 16, 2024 18:54
Show Gist options
  • Save AaronFeledy/8bb2fe668a1210d8b6e4ac0d8684e3a9 to your computer and use it in GitHub Desktop.
Save AaronFeledy/8bb2fe668a1210d8b6e4ac0d8684e3a9 to your computer and use it in GitHub Desktop.
Highlight LinkedIn Drupal Jobs
// ==UserScript==
// @name LinkedIn Drupal Jobs
// @include https://www.linkedin.com/jobs
// @include https://www.linkedin.com/jobs/*
// @version 1
// @grant none
// ==/UserScript==
const jobsScript = {
searchText: 'Drupal',
debugEnabled: false,
}
// Custom debug function
function debugLog(message, ...optionalParams) {
if (jobsScript.debugEnabled) {
console.log(message, ...optionalParams);
}
}
// Function to search and highlight the text
function searchAndHighlight() {
debugLog('executing searchAndHighlight()');
const selector = '.jobs-search__job-details';
const div = document.querySelector(selector);
if (div) {
debugLog('found details pane. searching for text.');
const searchRegExp = new RegExp(jobsScript.searchText, 'gi');
var jobID;
var jobTitleElement = div.querySelector('.job-details-jobs-unified-top-card__job-title');
var anchorTag = jobTitleElement.querySelector('a');
if (anchorTag) {
var href = anchorTag.getAttribute('href');
// Extract the job ID from the URL
var jobIdMatch = href.match(/\/jobs\/view\/(\d+)/);
if (jobIdMatch && jobIdMatch[1]) {
jobId = jobIdMatch[1];
debugLog("job ID:", jobId);
}
// Find the div with the matching data-job-id
var jobCard = document.querySelector(`div[data-job-id="${jobId}"]`);
}
if (searchRegExp.test(div.innerText)) {
debugLog('found match for search text');
jobTitleElement.style.textDecoration = 'underline overline dotted cyan 3px';
if (jobCard) {
jobCard.style.boxShadow = 'inset -20px 0px 20px -10px rgba(0, 255, 0, 0.6)';
}
} else {
debugLog('no match for search text');
jobTitleElement.style.textDecoration = 'line-through dotted red 3px';
if (jobCard) {
jobCard.style.boxShadow = 'inset -20px 0px 20px -10px rgba(255, 0, 0, 0.6)';
}
}
} else {
debugLog('could not locate', selector);
}
}
debugLog("jobs script loaded");
// Attach the event listener to the document
document.addEventListener('click', function(event) {
// Check if the clicked element or any of its parents is #main
if (event.target.closest('#main')) {
// Handle the click event for #main here
searchAndHighlight();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment