Skip to content

Instantly share code, notes, and snippets.

@dallasread
Last active December 1, 2022 13:01
Show Gist options
  • Save dallasread/4f8f10689f192be9fc8582ebae69c50e to your computer and use it in GitHub Desktop.
Save dallasread/4f8f10689f192be9fc8582ebae69c50e to your computer and use it in GitHub Desktop.
Find a keyword on a page
// ==UserScript==
// @name KeywordFinder
// @version 1
// @grant none
// @match https://news.ycombinator.com/*
// ==/UserScript==
(function(keyword) {
const counter = document.createElement('p')
counter.style.position = 'fixed'
counter.style.top = '0'
counter.style.right = '0'
counter.style.backgroundColor = '#1A5EC6'
counter.style.color = '#fff'
counter.style.fontSize = '18px'
counter.style.padding = '9px'
counter.style.margin = '0'
const occurrences = document.body.innerHTML.match(new RegExp(keyword, 'gi'))
if (occurrences) {
counter.innerText = `${keyword}: ${occurrences.length}`
document.body.appendChild(counter)
}
})('dnsimple')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment