I often put twitter urls in my inbox and then forget what it was about. Instead of having to open each URL separately, I wrote a little tampermonkey script that embeds the tweet.
// ==UserScript==
// @name Dynalist Tweet preview
// @namespace http://louiskirsch.com/
// @version 0.1
// @description Resolves twitter links and displays them as tweets inline
// @author Louis Kirsch
// @match https://dynalist.io/d/*
// @grant GM.xmlHttpRequest
// @run-at document-idle
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// ==/UserScript==
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "https://platform.twitter.com/widgets.js";
s.async = true;
document.head.append(s);
waitForKeyElements("a.node-link[href^='https://twitter.com/", actionFunction, false);
function actionFunction(links) {
links.each((i, l) => {
var requestUrl = 'https://publish.twitter.com/oembed?omit_script=1&url=' + l.href;
GM.xmlHttpRequest({
method: "GET",
url: requestUrl,
onload: function(response) {
var data = JSON.parse(response.responseText);
$(l).after(data.html);
if (twttr.widgets != undefined) {
twttr.widgets.load();
}
}
});
});
}
9 Likes
This is welcome. I note this has been possible in Roam. When I install the script, it get the plain text from the Twitter post, but not the formatting as in yours. There may be a clash with CSS.
1 Like
I am not entirely sure now what you meant. Roam embeds tweets by default or you run my script in Roam?
in Dynalist?
So this is a tweet in Twitter:

And how it appears when the link is copied into Dynalist with your script.
Itâs still useful, but not embedded.
Hum okay, thatâs odd. Are there any errors in the console?
Iâm not sure if it is relevant, but this is the error message:
Refused to load the font ââ because it violates the following Content Security Policy directive: âdefault-src *â. Note that âfont-srcâ was not explicitly set, so âdefault-srcâ is used as a fallback
Hey @Louis_Kirsch, I tried your script but it doesnât seem to work (Iâm on Firefox). I got error messages on lines 19, 29, 30 :
- eslint : no undef - waitforkeyelements is not defined
- eslint : no undef - â$â is not defined
- eslint : no undef - âtwttr is nor definedâ
Regards
Could this be tweaked to embed other stuff? Like say a YouTube video or a Google sheet table?
Absolutely. Both in principle allow embedding through scripts or iframes.
E.g. google sheets
http://www.bdnyc.org/2012/08/how-to-embed-a-live-google-docs-spreadsheet-into-a-webpage/
But Iâm guessing it wonât work with your script without some tweaking?
Yeah it requires a little bit of javascript knowledge.
Iâm sure Iâm doing something wrong, but I canât get anything to work⌠I installed the Tampermonkey extension in FF and I pasted the code above in a new script. But nothing seems to happen when I paste a Twitter URL in Dynalist⌠Is there something else I should do ? Thx
To be honest I havenât tested it in Firefox but in Chrome. Maybe it has to do with that. Did you refresh the page after adding the script? Are there any errors in the console? Does tamper monkey claim the script is running?
Works for me in Chrome ( Vivaldi)
@Louis_Kirsch Youâre right, it works in Chrome ! I needed to refresh both Twitter and Dynalist though. Iâll try again in FF, and Iâll let you know. Huge thanks, both for QuickDynalist and this script (so useful with Twitter !!!). Cheers.
1 Like
Works in FF as well after all ! GREAT !!! Thanks again.
1 Like