Mothra wrote:Upthorn wrote:Was re-thinking my thing and editing my code while you tested. Try
Code: Select all
<script type="text/javascript">
function loadx(data) {
if(typeof data.html !== 'undefined') {
if (isset(data.html)) {
document.write(data.html);
return;
}
document.write('[Error displaying tweet]');
}
</script>
<script type="text/javascript" src="https://api.twitter.com/1/statuses/oembed.json?id={IDENTIFIER}&callback=loadx"></script>
<div class='twitter' onLoad='loadx().html'/></div>
After that I'm out of ideas.
EDIT: AH FUCK I FUCKED IT UP AGAIN. TRY COPY-PASTING ONE LAST TIME IF YOU DIDN'T SEE THIS EDIT BEFORE YOU TRIED!
Tried the post-edit code, but nadda, same issues where it doesn't embed at all.
Reverted back to the O.G. - willing to try others if people want to take more swings at this.
The actual solution is so simple as to make me
furious it took me this long to find:
Code: Select all
<script type="text/javascript">
function loadx(data) {
document.write(data.html);
}
</script>
<script type="text/javascript" src="https://api.twitter.com/1/statuses/oembed.json?id={IDENTIFIER}&callback=loadx&dnt=true" onerror="document.write('[ERROR LOADING TWEET!]')"></script>
Edit: So I figured out early on that the reason Thad's solution didn't work is that loadx(data) is only called when the api actually
loads a tweet. When there is no tweet, the API is
supposed to call the callback with the json blob mazian posted, but it actually just gives an error 400.
So I spent hours trying to figure out how to get tampermonkey userscripts to load external resources without triggering a cross-origin-resource-security violation. Then, when I worked out what function to call and how to get tampermonkey to let me access it, and made my first successful tests of getting the API response, and was finally ready to start trying js to parse it when successful and error out when it failed...
The tampermonkey API simply... stopped making those network requests at all. Even when I reverted to the version of the script that had *just* successfully done it.
Anyway, all of that turned out to be unnecessary work only because I was bad at googling "html detect external script load failure".
How fleeting are all human passions compared with the massive continuity of ducks.