Skip to content

Instantly share code, notes, and snippets.

@ryanml
Last active July 14, 2019 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanml/24ffd1fa34ac837b1328bdaa71aebf73 to your computer and use it in GitHub Desktop.
Save ryanml/24ffd1fa34ac837b1328bdaa71aebf73 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Alien Trends
// @namespace https://github.com/ryanml
// @version 0.1
// @description green
// @author You
// @match https://www.facebook.com/*
// @grant none
// ==/UserScript==
(function() {
const debounce = (scrollFunc) => {
let timer = null;
return () => {
if (timer) return;
timer = setTimeout(() => {
scrollFunc.apply(this, arguments)
timer = null
}, 100)
}
}
const findAlienPosts = () => {
let messages = document.querySelectorAll('[data-testid="post_message"]')
if (!messages) return;
for (const message of messages) {
const text = message.textContent.toLowerCase()
if (text.match(/area 51/gi)) {
message.innerHTML = '<p style="color:#39ff14;font-size:30px;">Post about Aliens</p>'
}
}
}
window.addEventListener('load', findAlienPosts)
window.addEventListener('scroll', debounce(findAlienPosts))
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment