Skip to content

Instantly share code, notes, and snippets.

@maxlath
Created January 8, 2014 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxlath/8312937 to your computer and use it in GitHub Desktop.
Save maxlath/8312937 to your computer and use it in GitHub Desktop.
getting over the anoying t.co redirection with the greasemonkey addon [forked from http://userscripts.org/scripts/show/160938]
// ==UserScript==
// @name Tweetdeck url expander
// @namespace tweetdeck.twitter.com
// @description getting over the t.co redirection
// @include https://tweetdeck.twitter.com/
// @version 1
// @grant none
// ==/UserScript==
(function (window) {
var document = window.document;
var OneTimeTrigger = function (func, delay) {
var timerCountdown = 0;
return function() {
setTimeout(function() {
timerCountdown -= 1;
if (timerCountdown == 0) {
func();
}
}, delay);
timerCountdown += 1;
};
};
var expandAllLink = function () {
var expandedUrl;
Array.prototype.forEach.call(document.querySelectorAll("a.url-ext:not(.url-ext-expanded)"),
function (node) {
if (/^http(?:s)?:\/\/t\.co\/[0-9A-Za-z]+$/g.test(node.href)) {
expandedUrl = node.getAttribute("data-full-url");
if (expandedUrl) {
node.href = expandedUrl;
}
node.className += " url-ext-expanded";
}
});
};
var trigger = OneTimeTrigger(expandAllLink, 100);
var MutationObserver = window.MutationObserver ? window.MutationObserver : window.WebKitMutationObserver;
if (typeof MutationObserver !== "undefined") {
var observer = new MutationObserver(trigger);
observer.observe(document, { childList: true, subtree: true });
}
else {
document.addEventListener("DOMNodeInserted", trigger, false);
document.addEventListener("DOMSubtreeModified", trigger, false);
}
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment