Project Overview
What this project actually is
Bullshit.js is a JavaScript bookmarklet that identifies and highlights specific "bullshit" terms within the text content of a web page.
Tech stack
- JavaScript
- esbuild (for bundling)
- eslint (for linting)
- findandreplacedomtext (library for DOM manipulation)
High-level architecture
The core logic resides in src/replace.js. This file imports a list of terms from src/terms.js. It then uses the findandreplacedomtext library to find occurrences of these terms within the document.body. When a term is found, the revealBullshit function is called to replace the original text with a modified version, wrapped in an <abbr> tag with a red style. The package.json defines build scripts using esbuild to bundle src/replace.js into the bullshit.js file, which is the output for the bookmarklet.
Entry points
src/replace.js: This is the main source file for the bookmarklet's logic. When the bookmarklet is executed, this script is loaded and run in the context of the current web page.bullshit.js: This is the bundled output file. It's the script that is directly included in the bookmarklet'shrefattribute (as seen inindex.html). When the bookmarklet is clicked, this script is fetched and executed, triggering the DOM manipulation defined insrc/replace.js.index.html: This file serves as a landing page that explains what Bullshit.js is and provides the bookmarklet link. It also includes adebug.htmlwhich directly includes thebullshit.jsscript for testing purposes.
Key concepts
src/terms.js: This file contains a large array of regular expressions that define the "bullshit" terms to be detected. Understanding the structure and content of this file is crucial for knowing what the script targets.src/replace.js:bullshitRe: This regular expression is constructed frombullshitTermsand is used to find the target words in the DOM.revealBullshit({text}): This function takes the matched text, applies some simple transformations (e.g., adding "ting" or "ted"), and returns an<abbr>element with a red style and the transformed text as its content. This is how the "bullshit" is visually identified on the page.
findandreplacedomtext: This external library is the workhorse for modifying the DOM. The script uses itsfindAndReplaceDOMTextfunction with thedocument.bodyas the target, thebullshitReas the search pattern, andrevealBullshitas the replacement function.- Bookmarklet Structure (
index.html): Theindex.htmlfile demonstrates how thebullshit.jsscript is intended to be used as a bookmarklet. Thejavascript:(function(){...}())structure shows how to dynamically create and append a script tag to the current page's DOM.
