Skip to content

Instantly share code, notes, and snippets.

@cannibalox
Last active February 16, 2024 05:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cannibalox/e75fe2f2ecc0de08a13025a559e166cd to your computer and use it in GitHub Desktop.
Save cannibalox/e75fe2f2ecc0de08a13025a559e166cd to your computer and use it in GitHub Desktop.
[userscript] logseq twitter embed
// ==UserScript==
// @name ls-twitter-embed
// @namespace https://gist.github.com/cannibalox/e75fe2f2ecc0de08a13025a559e166cd
// @version 0.1
// @description fetch tweets from url
// @author ported to logseq from louis kirsch's dynalist userscript
// @match https://logseq.com/*
// @grant GM.xmlHttpRequest
// @run-at document-end
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// ==/UserScript==
console.info('====== LS-TWITTER-EMBED ======');
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.external-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();
}
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment