I'm embedding a twitter timeline into my website. However my retweets are being displayed there and I don't want them to.
Is there any easy way to turn them off? I can't seem to find any
My search query is from:myaccount
. I also tried from:myaccount -RT
, with no luck. I can hide retweets with a search widget but tweets older than a week are not shown which is unacceptable in my case.
Hiding the tweets via some CSS magic would also be OK. I managed to find out that manually inserting
div.timeline-Tweet--isRetweet { display: none !important; }
in the CSS for the embedded HTML does the trick, but I can't manage to do it programatically.
Click the icon located within the Tweet. From the menu, select Embed Tweet. This will open publish.twitter.com where you can customize the look of the embedded Tweet by clicking set customization options. If the Tweet is a reply to another Tweet, you can check Hide Conversation to hide the original Tweet.
To do it, go to Twitter.com and click on your profile. Click "Following" to see the complete list of users you're following. Find the user for whom you want to hide retweets and click on the silhouette button located just to the left of the Following button. A drop-down menu will open up; select "Turn off Retweets."
It's quite easy. We will use for example caitp88
account for demo you can follow her afterwards if you want tho)
As you can see in her profile, the latest tweet is a Retweet
But we don't want retweets, right?
So we go to search form and type from:caitp88 -RT
Then we create an embed from this search Widget configuration window opens, you just click on create widget
The widget will not contain any retweets
In action:
Don't forget to change caitp88
to your own twitter handle
AND NOTE, THIS IS OFFICIAL, LEGAL SOLUTION
Adaptation from my comments
To go with hacky style injection, simply put following code in script tag. This puts https://platform.twitter.com/widgets.js
script tag to your page so you no longer need it as separate script tag.
// widgets script loading taken from Twitter window.twttr = (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); t._e = []; t.ready = function (f) { t._e.push(f); }; return t; }(document, "script", "twitter-wjs")); twttr.ready(function (twttr) { twttr.events.bind("rendered", function (event) { var widgetFrame = event.target; var retweets = widgetFrame.contentDocument.querySelectorAll('div.timeline-Tweet--isRetweet'); retweets.forEach(function (node) { if (node.parentNode) { // (in)sanity check node.parentNode.style = 'display: none;' // hide entire parent li tag } }) }); });
Remark about it
We take parent node as every div.timeline-Tweet--isRetweet
sits in li
tag which gives you border, so you end up with some strange double border left after hidden retweets. I think that there is no way to reach parent through CSS selectors so we have to do this with a code.
Another remark
Following hack strongly relies on way how contents of the timelines are structured and those may change without the notice from Twitter so you risk here that one day you will wake up with you pants down and retweets back in your timeline ;)
Update
ok here is v2 which listen for updates on ol
... but after writing it I start to understand dr Frankenstein feelings ;)
window.twttr = (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); t._e = []; t.ready = function (f) { t._e.push(f); }; return t; }(document, "script", "twitter-wjs")); twttr.ready(function (twttr) { twttr.events.bind("rendered", function (event) { var frameDoc = event.target.contentDocument; // initially hide retweets var hideRetweets = function () { var retweets = frameDoc.querySelectorAll('div.timeline-Tweet--isRetweet'); retweets.forEach(function (node) { if (node.parentNode && node.parentNode.style !== 'display: none;') { // (in)sanity check node.parentNode.style = 'display: none;' // hide entire parent li tag } }); }; hideRetweets(); // Twitter widget emitts no events on updates so we hook up ourselves to ol element to listen on it for additions of children var watcher = new MutationObserver(function (mutations) { // check whether new tweets arrived var hasNewTweets = mutations.some(function (mutation) { return mutation.addedNodes.length > 0; }); if (hasNewTweets) { hideRetweets(); // rescan all tweets as it is easier } }); watcher.observe(frameDoc.querySelector('ol.timeline-TweetList'), { childList: true }); }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With