Created
December 31, 2014 15:40
-
-
Save Isuru-Nanayakkara/f9dbccdc9dd3c3977109 to your computer and use it in GitHub Desktop.
Satirical script. Prepend අපෙ හාමුදුරුවනේ to the beginning of every tweet by @PresRajapaksa. Works only on Firefox with Greasemonkey addon installed.
This file contains hidden or 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 අපෙ හාමුදුරුවනේ | |
// @include https://twitter.com/* | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js | |
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js | |
// @grant GM_addStyle | |
// @icon https://pbs.twimg.com/profile_images/541867053351583744/rcxem8NU_400x400.jpeg | |
// @noframes | |
// ==/UserScript== | |
var tweetSelector = "p.js-tweet-text"; | |
function fireMainCode () { | |
/*--- Only fire on desired pages. This fires on: | |
twitter.com/PresRajapaksa* | |
twitter.com/PresRajapaksa/status/* | |
*/ | |
if (/^\/PresRajapaksa(\/status\/)?/.test (location.pathname) ) { | |
if ( ! this.WFKE_fired) { | |
waitForKeyElements (tweetSelector, prependToTweet); | |
this.WFKE_fired = true; | |
} | |
} | |
else { | |
//--- Undesired page, shut off waitForKeyElements | |
if (this.WFKE_fired) { | |
this.WFKE_fired = null; | |
var controlObj = waitForKeyElements.controlObj || {}; | |
var controlKey = tweetSelector.replace (/[^\w]/g, "_"); | |
var timeControl = controlObj [controlKey]; | |
if (timeControl) { | |
clearInterval (timeControl); | |
delete controlObj [controlKey] | |
} | |
} | |
} | |
} | |
fireMainCode (); | |
function prependToTweet (jNode) { | |
var altDoneFlag = jNode.attr ("data-altdoneflag"); | |
if ( ! altDoneFlag) { | |
jNode.prepend ("අපෙ හාමුදුරුවනේ ") | |
.attr ("data-altdoneflag", "yes"); | |
} | |
} | |
/*--- Twitter uses some pretty screwy AJAX to "change" pages, but it at least | |
changes the title. So listen for that to (re) trigger waitForKeyElements. | |
*/ | |
var myObserver = new MutationObserver (titleChangeDetector); | |
var obsConfig = { | |
//-- Subtree needed. | |
childList: true, characterData: true, subtree: true | |
}; | |
myObserver.observe (document, obsConfig); | |
function titleChangeDetector (mutationRecords) { | |
mutationRecords.forEach ( function (mutation) { | |
//-- Sensible, Firefox | |
if ( mutation.type == "childList" | |
&& mutation.target.nodeName == "TITLE" | |
) { | |
fireMainCode (); | |
} | |
//-- WTF, Chrome | |
else if (mutation.type == "characterData" | |
&& mutation.target.parentNode.nodeName == "TITLE" | |
) { | |
fireMainCode (); | |
} | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment