Last active
July 14, 2019 03:25
-
-
Save ryanml/24ffd1fa34ac837b1328bdaa71aebf73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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