Skip to content

Instantly share code, notes, and snippets.

@ideabrian
Created December 7, 2023 20:24
Show Gist options
  • Save ideabrian/0e74625b54c9e7979b71aeb5f5af5ba7 to your computer and use it in GitHub Desktop.
Save ideabrian/0e74625b54c9e7979b71aeb5f5af5ba7 to your computer and use it in GitHub Desktop.
Navigate Craigslist.org with this snippet. Paste in the "developer console" to have it available on the page.
document.addEventListener('keydown', function(event) {
// Define the key codes for navigation and activation
const navigateKey = 'ArrowRight'; // Example: Right arrow key for navigation
const activateKey = 'q'; // Use 'q' key for activation
// Handle navigation
if (event.key === navigateKey) {
navigateToNextItem();
}
// Handle activation
if (event.key === activateKey) {
activateCurrentItem();
}
});
let currentItemIndex = -1;
const items = document.querySelectorAll('.cl-search-result');
function navigateToNextItem() {
if (items.length === 0) return;
// Remove highlight from the current item
if (currentItemIndex >= 0 && currentItemIndex < items.length) {
items[currentItemIndex].style.backgroundColor = '';
}
// Move to the next item
currentItemIndex = (currentItemIndex + 1) % items.length;
// Highlight the new current item
items[currentItemIndex].style.backgroundColor = 'yellow';
}
function activateCurrentItem() {
if (items.length === 0 || currentItemIndex < 0 || currentItemIndex >= items.length) return;
// Find and click the button within the current item
const button = items[currentItemIndex].querySelector('button[title="hide posting"]');
if (button) {
button.click();
}
}
// made by @brianball of buildstuff.ai with the help of chatgpt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment