Last active
September 8, 2020 01:05
-
-
Save sj26/d550954a0387b717907af9a335f6ce15 to your computer and use it in GitHub Desktop.
Show cards in embedded tweets in campfires etc so you can see the images etc that are being shared
This file contains hidden or 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 basecamp-show-tweet-cards | |
// @description Show cards in embedded tweets so you can see the images etc that your friends are sharing | |
// @author Samuel Cochran <[email protected]> | |
// @license MIT | |
// @version 1 | |
// @match https://bc3-production-assets-cdn.basecamp-static.com/*/embeds/*/chat | |
// @run-at document-end | |
// @homepage https://gist.github.com/sj26/d550954a0387b717907af9a335f6ce15 | |
// @updateURL https://gist.github.com/sj26/d550954a0387b717907af9a335f6ce15/raw/56b1e3e3c8c43444fc78e0f34fb3d409f18e79fe/basecamp-show-tweet-cards.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Basecamp embeds tweets in campfires etc by creating a static html page | |
// capturing the contents of a tweet in a blockquote which is turned into an | |
// iframe on load, and that page is embedded in the chat in an iframe itself. | |
// So here we modify the statically embedded interstitial page to modify the | |
// blockquote before it gets turned into an iframe, or falling back to | |
// modifying the iframe url if we're too late. | |
// <blockquote class="twitter-tweet" data-cards="hidden"> | |
// <p lang="en" dir="ltr">...</p> | |
// — ... (@...) | |
// <a href="https://twitter.com/.../status/1234567891011121314?ref_src=twsrc%5Etfw">...</a> | |
// </blockquote> | |
const blockquote = document.querySelector("blockquote.twitter-tweet") | |
if (blockquote && blockquote.dataset.cards == "hidden") { | |
delete blockquote.dataset.cards | |
return | |
} | |
// <iframe id="twitter-widget-0" | |
// scrolling="no" | |
// frameborder="0" | |
// allowtransparency="true" | |
// allowfullscreen="true" | |
// class="" | |
// style="position: static; visibility: visible; width: 550px; height: 749px; display: block; flex-grow: 1;" | |
// title="Twitter Tweet" | |
// src="https://platform.twitter.com/embed/index.html?dnt=false&embedId=twitter-widget-0&frame=false&hideCard=true&hideThread=false&id=1234567891011121314&lang=en&origin=https%3A%2F%2Fbc3-production-assets-cdn.basecamp-static.com%2F...%2Fembeds%2F...%2Fchat&theme=light&widgetsVersion=219d021%3A1598982042171&width=550px" | |
// data-tweet-id="1234567891011121314"></iframe> | |
const iframe = document.querySelector("iframe") | |
if (iframe) { | |
const url = new URL(iframe.url); | |
if (url.scheme === "https" && url.host === "platform.twitter.com" && url.searchParams.get("hideCard") == "true") { | |
url.searchParams.delete("hideCard") | |
iframe.url = url.toString() | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment