Last active
May 26, 2016 08:02
-
-
Save birkestroem/d4be027c53711b24bfeaede1ba954a52 to your computer and use it in GitHub Desktop.
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 Fix Asana broken links | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Fixing Asana again | |
// @author Jesper Birkestrøm | |
// @match https://app.asana.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function debounce(func, wait) { | |
var timeout; | |
return function() { | |
var context = this; | |
var args = arguments; | |
var later = function() { | |
timeout = null; | |
func.apply(context, args); | |
}; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
}; | |
} | |
function fixLinks() { | |
[].forEach.call(document.getElementById('right_pane_container').querySelectorAll('a[rel~=nofollow][rel~=noreferrer]'), function (a) { | |
var mailtoA = a.nextSibling; | |
if (mailtoA && mailtoA.href && /^mailto/i.test(mailtoA.href)) { | |
var correctHref = a.href + mailtoA.href.substring(7); | |
var textElement = mailtoA.nextSibling; | |
if (textElement && textElement.nodeType === Node.TEXT_NODE) { | |
var text = textElement.nodeValue; | |
var firstSpace = text.indexOf(' '); | |
if (firstSpace > 0) { | |
correctHref += text.substring(0, firstSpace); | |
textElement.nodeValue = text.substring(firstSpace); | |
} | |
if (firstSpace === -1) { | |
correctHref += text; | |
textElement.nodeValue = ""; | |
} | |
} | |
a.href = correctHref; | |
a.innerText = correctHref; | |
a.title = correctHref; | |
mailtoA.parentNode.removeChild(mailtoA); | |
} | |
}); | |
} | |
function latchOn() { | |
var rightPane = document.getElementById('right_pane_container'); | |
if (rightPane) { | |
rightPane.addEventListener("DOMSubtreeModified", function(e) { | |
debounce(fixLinks, 100); | |
}, false); | |
fixLinks(); | |
} else { | |
setTimeout(latchOn, 1000); | |
} | |
} | |
latchOn(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment