Last active
February 23, 2019 18:39
-
-
Save vuori/1abeb28630bb2c91fd0792472ea8c13f to your computer and use it in GitHub Desktop.
Userscript to remove t.co shortening from Tweetdeck outgoing links
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 FixTweetdeckLinks | |
// @namespace http://github.com/vuori | |
// @version 1.0 | |
// @description Removes t.co shortening from Tweetdeck outgoing links | |
// @author vuori | |
// @match https://tweetdeck.twitter.com/* | |
// @homepageURL https://gist.github.com/vuori/1abeb28630bb2c91fd0792472ea8c13f | |
// @updateURL https://gist.githubusercontent.com/vuori/1abeb28630bb2c91fd0792472ea8c13f/raw/FixTweetdeckLinks.js | |
// @grant GM_log | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function cleanNodes(nodes) { | |
for (let elem of nodes) { | |
const fullUrl = elem.dataset.fullUrl; | |
if (!fullUrl) | |
continue; | |
//GM_log(`FixTweetdeckLinks: replacing ${elem.getAttribute('href')} with ${fullUrl}`); | |
// Replace silly t.co link with actual link and delete title which was hiding the shortlink | |
// (and is now identical to href) | |
elem.setAttribute('href', fullUrl); | |
delete elem.dataset.fullUrl; | |
elem.removeAttribute('title'); | |
} | |
} | |
const linkObserver = new MutationObserver((recordList) => { | |
for (let record of recordList) { | |
if (!record.addedNodes) | |
return; | |
for (let elem of record.addedNodes) { | |
if (elem.tagName !== 'ARTICLE') | |
continue; | |
cleanNodes(elem.querySelectorAll('a.url-ext')); | |
} | |
} | |
}); | |
linkObserver.observe(document.body, { childList: true, subtree: true }); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment