Last active
November 28, 2019 08:56
-
-
Save dstillman/8effa53d6e82f11ee11f8cbc755923ac to your computer and use it in GitHub Desktop.
Thunderbird: Open Message URL
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
// Install https://github.com/jikamens/userChromeJS and save this as chrome/userChrome.js in your TB profile directory | |
window.addEventListener('keydown', function (event) { | |
if (event.metaKey && event.ctrlKey && event.key == 'o') { | |
var loadFirstURLInBody = function (body) { | |
var parser = new DOMParser(); | |
var doc = parser.parseFromString(body, "text/html"); | |
var links = doc.getElementsByTagName('a'); | |
if (links.length) { | |
let uri = Services.io.newURI(links[0].href, null, null); | |
Components.classes["@mozilla.org/uriloader/external-protocol-service;1"] | |
.getService(Components.interfaces.nsIExternalProtocolService) | |
.loadURI(uri) | |
} | |
} | |
var msgHdr = gFolderDisplay.selectedMessage; | |
var folder = msgHdr.folder; | |
if (folder.name == 'Zotero Forums') { | |
FeedMessageHandler.loadWebPage(msgHdr, { browser: true }); | |
} | |
else { | |
MsgHdrToMimeMessage(msgHdr, null, function (msgHdr, msg) { | |
for (var i=0; i<msg.parts.length; i++) { | |
var part = msg.parts[i]; | |
if (part.contentType == 'text/plain') { | |
let matches = part.body.match(/https?:\/\/[^\s$]+/); | |
if (matches) { | |
let uri = Services.io.newURI(matches[0], null, null); | |
Components.classes["@mozilla.org/uriloader/external-protocol-service;1"] | |
.getService(Components.interfaces.nsIExternalProtocolService) | |
.loadURI(uri) | |
return; | |
} | |
} | |
else if (part.contentType == 'text/html') { | |
loadFirstURLInBody(part.body); | |
return; | |
} | |
else if (part.contentType == 'multipart/alternative') { | |
for (var j=0; j<part.parts.length; j++) { | |
var subpart = part.parts[j]; | |
if (subpart.contentType == 'text/html') { | |
loadFirstURLInBody(subpart.body); | |
return; | |
} | |
} | |
} | |
} | |
}, true); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment