Created
February 15, 2017 18:30
-
-
Save fortserious/70a3080530d92dc59476fa764d2d7313 to your computer and use it in GitHub Desktop.
twitter trumpify
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 trumpify | |
// @namespace http://rossdoran.com | |
// @version 0.1 | |
// @description adjusts the aesthetics of donald trump's twitter timeline to match his level of intellectual expression | |
// @match https://twitter.com/* | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js | |
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js | |
// @copyright 2014 ross doran | |
// ==/UserScript== | |
// todo: remove hyperlinks, they ruin the otherwise quite comfortable suspension of disbelief that a presidential candidate might actually be writing these tweets out on construction paper | |
// - perhaps turn links/quotes into 'stickers'? | |
// - we can start with a simple white rounded rectangle box and a nice black font on top | |
// - can branch out to colors or sparkles maybe | |
// we should change the way links quotes work. | |
// form an array of indexes of links and quotes. | |
// the first is an array of quotes. it ties quote pairs together and then adds an endquote at the end if there is an odd number. | |
// then the next is an array of links. it searches for "http" and then looks for the next space, or calls it the end if there is no next space | |
// each of these spans are recorded as what they are | |
// todo: does donald trump ever reply to someone without putting a period in front? does he ever converse with people like human beings? i cannot test this edge case because i have not seen it happen, and perhaps never will | |
// todo: check retweets | |
// todo: package into chrome extension | |
var bg = ["#FFEF6C","#A4B1FF","#70B772","#B77085","#FDE9F4","#8AADA2","#FFCDA6"]; | |
var rainbow = ["red","orange","blue","purple","green","darkyellow","lightblue","lightgreen","lightred"]; | |
var colorIt = function(s){ | |
var s2 = ""; | |
for (var i = 0; i < s.length; i++) { | |
// do moz/webkittransforms for scale, rotate, translate. randomize values for each | |
var transforms = ""; | |
var reverse = 1; | |
var angleCeiling = 30; | |
var angle = Math.floor(angleCeiling / 2) - Math.floor(Math.random() * angleCeiling); | |
var tx = Math.floor(Math.random() * 5); | |
var ty = Math.floor(Math.random() * 10); | |
if (Math.floor(Math.random() * 140) < 2) | |
reverse *= -1; | |
var transforms = "-moz-transform: scale(" + reverse + ", 1) rotate(" + angle + "deg) translate(" + tx + "px," + ty + "px);" + | |
"-webkit-transform: scale(" + reverse + ", 1) rotate(" + angle + "deg) translate(" + tx + "px," + ty + "px); -o-transform: scale(" + reverse + ", 1) rotate(" + angle + "deg) translate(" + tx + "px," + ty + "px);" + | |
"-ms-transform: scale(" + reverse + ", 1) rotate(" + angle + "deg) translate(" + tx + "px," + ty + "px); transform: scale(" + reverse + ", 1) rotate(" + angle + "deg) translate(" + tx + "px," + ty + "px);" + | |
"display: inline-block;"; | |
s2 += "<span style=\"color:" + rainbow[Math.floor(Math.random() * rainbow.length)] + "; " + transforms + "\">" + s.substr(i, 1) + "</span>"; | |
} | |
return s2; | |
} | |
function trumpify (jNode) { | |
if (jNode.parent().data()['screenName']) | |
{ | |
var tweetParent = jNode.parent(); | |
// console.log(jNode.text()); | |
console.log("rt? " + screenNameCheck); | |
} | |
else | |
var tweetParent = jNode.parent().parent(); | |
var screenNameCheck = tweetParent.data()['screenName']; | |
if (screenNameCheck == 'realDonaldTrump') | |
{ | |
var t = jNode.text(); | |
var d = ""; | |
var q = ""; | |
if (t) // if tweet starts with '"', remove 'smart' quotes and de-trumpify the inner text (trump uses quotes when replying so this greatly aids in legibility) | |
{ | |
t = t.replace( /\u2018|\u2019|\u201A|\uFFFD/g, "'" ); | |
t = t.replace( /\u201c|\u201d|\u201e/g, '"' ); | |
var firstQ = t.indexOf('"'); | |
if (firstQ != -1) // there is at least one quotation mark | |
{ | |
// console.log("quotes detected"); | |
var lastQ = t.lastIndexOf('"'); | |
if (firstQ == lastQ) // this ridiculous test case means that donald trump forgot to end his quote with quotation marks, which he does a lot, like way more than you would expect | |
{ | |
q = t; | |
t = ""; | |
} | |
else if (lastQ != -1) // if there is a quote, leave it out of the formatting. this will break if there are multiple quotes/scare quotes used but honestly who cares. if the answer is you, feel free to fix it | |
{ | |
d = t.substring(lastQ + 1); | |
q = t.substring(firstQ, lastQ + 1); | |
t = t.substring(0, firstQ); | |
} | |
} | |
} | |
// console.log(t + "| & THEN |" + d); | |
var firstSpan = "<span style='line-height: 120% !important; color: blue; font-size: 40px !important; font-family: pastel; src: url(http://fortserious.thecarcadero.com/crayon/pastel.ttf) format (\"truetype\");'>"; | |
jNode.html(firstSpan + colorIt(t) + "</span>" + q + firstSpan + colorIt(d) + "</span>"); | |
if (t.length > 1) | |
{ | |
var bgc = bg[Math.floor(Math.random() * (bg.length - 1))]; | |
if (jNode) | |
{ | |
jNode.attr('style','padding: 7px;background-color: ' + bgc + ';'); | |
} | |
} | |
} | |
} | |
waitForKeyElements (".js-tweet-text", trumpify); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment