Skip to content

Instantly share code, notes, and snippets.

@joshparkerj
Last active April 25, 2022 19:36
Show Gist options
  • Select an option

  • Save joshparkerj/1be6e2fc1e4f486e684f6a5b0fb25207 to your computer and use it in GitHub Desktop.

Select an option

Save joshparkerj/1be6e2fc1e4f486e684f6a5b0fb25207 to your computer and use it in GitHub Desktop.
apply sarcastic capitalization to the text you select
// ==UserScript==
// @name Sarcastify
// @namespace http://tampermonkey.net/
// @version 0.1
// @description apply sarcastic capitalization to the text you select
// @author Josh Parker
// @source https://github.com/joshparkerj/silly-internet-tricks/blob/main/text-effect/sarcastify.user.js
// @downloadURL https://gist.github.com/joshparkerj/1be6e2fc1e4f486e684f6a5b0fb25207/raw/sarcastify.user.js
// @updateURL https://gist.github.com/joshparkerj/1be6e2fc1e4f486e684f6a5b0fb25207/raw/sarcastify.meta.js
// @match https://www.washingtonpost.com/*
// @match https://www.google.com/*
// @match https://en.wikipedia.org/wiki/*
// @match https://www.tampermonkey.net/*
// @icon https://www.google.com/s2/favicons?domain=washingtonpost.com
// @grant none
// ==/UserScript==
// ==UserScript==
// @name Sarcastify
// @namespace http://tampermonkey.net/
// @version 0.1
// @description apply sarcastic capitalization to the text you select
// @author Josh Parker
// @source https://github.com/joshparkerj/silly-internet-tricks/blob/main/text-effect/sarcastify.user.js
// @downloadURL https://gist.github.com/joshparkerj/1be6e2fc1e4f486e684f6a5b0fb25207/raw/sarcastify.user.js
// @updateURL https://gist.github.com/joshparkerj/1be6e2fc1e4f486e684f6a5b0fb25207/raw/sarcastify.meta.js
// @match https://www.washingtonpost.com/*
// @match https://www.google.com/*
// @match https://en.wikipedia.org/wiki/*
// @match https://www.tampermonkey.net/*
// @icon https://www.google.com/s2/favicons?domain=washingtonpost.com
// @grant none
// ==/UserScript==
(()=>{"use strict";!function(e,t,n){const o=document.querySelector("body > div.josh-text-manips"),s=o||document.createElement("div");s.className="josh-text-manips",s.appendChild(function(e,t,n){const o=document.querySelector("body"),s=document.createElement("button");s.innerText=e;const d=function e({target:d}){const c=d;o.removeEventListener("mousedown",e);const a=c.textContent.split("").map((e=>{const t=document.createElement("span");return t.textContent=e,t}));c.textContent="",a.forEach((e=>c.appendChild(e)));const i=({target:e})=>{"SPAN"===e.tagName&&e.classList.add("selected")};c.addEventListener("mouseover",i);const r=()=>{c.removeEventListener("mouseup",r),c.removeEventListener("mouseover",i);const e=c.textContent,o=[...c.childNodes].map((e=>e.className)),d=o.indexOf("selected"),a=o.lastIndexOf("selected")+1;c.innerHTML="",c.appendChild(new Text(e.slice(0,d)));const p=document.createElement("span");p.className=t,p.appendChild(new Text(e.slice(d,a))),c.appendChild(p),c.appendChild(new Text(e.slice(a))),n(c.querySelector(`span.${t}`)),s.removeAttribute("disabled")};c.addEventListener("mouseup",r)};return s.addEventListener("click",(()=>{s.setAttribute("disabled",!0),o.addEventListener("mousedown",d)})),s}(e,t,n)),o||document.querySelector("body").appendChild(s),document.styleSheets[0].insertRule(".josh-text-manips {position: fixed;background-color: lightgrey;padding: 5px 10px;top: 62px;right: 10px;border-radius: 16px;box-shadow: 2px 2px 1px black;}")}("sarcastify","sarcastic-text",(function(e){const t=e;t.textContent=t.textContent.split("").map((function(e,t){return t%2?e.toLocaleLowerCase():e.toLocaleUpperCase()})).join("")}))})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment