Skip to content

Instantly share code, notes, and snippets.

@andersonbosa
Last active May 6, 2023 02:54
Show Gist options
  • Save andersonbosa/a00f710a841818400a19f5d019c1db9a to your computer and use it in GitHub Desktop.
Save andersonbosa/a00f710a841818400a19f5d019c1db9a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Remove items wich "tilha" on name - olx.com.br
// @namespace Violentmonkey Scripts
// @match https://*.olx.com.br/*
// @author https://linktr.ee/andersonbosa
// ==/UserScript==
/**
* The expression to remove from your search.
*
* @see {@link https://en.wikipedia.org/wiki/Regular_expression} to further information about `regex`
* @see {@link https://regex101.com/} regex playground
*/
const REGEXNAME = /trilha/gi
/**
* Checks if is a valid item to remove.
*
* @params {HTMLElement} item
*/
const isToRemove = item => {
const itemTitle = item.querySelector('h2')
const title = (itemTitle && itemTitle.innerText) || ''
if (!title) {
return
}
const isToRemove = REGEXNAME.test(title)
return isToRemove
}
/**
* Deface the item HTML to empty.
*
* @params {HTMLElement} item
*/
const removeItem = item => {
if (!item) {
return
}
item.innerHTML = ''
}
/**
* Based on heuristics written in the `isToRemove` function, it checks and
* defaces the undesirable item.
*
* @see {isToRemove} to further information about which item is to remove.
*/
function removeItemsFromSearch() {
console.log('------------- removeItemsFromSearch is active -------------')
const items = window.document.querySelectorAll('ul#ad-list > li')
Array.from(items).forEach(item => {
const removable = isToRemove(item)
if (removable) removeItem(item)
})
}
/**
* Start the function after 3 seconds
*/
setTimeout(removeItemsFromSearch, 3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment