Is there a way to block or remove Twitter ads?
If you have experience with web programming, you can always write a script that automatically hides ads as they appear (you would need JavaScript or a related technology to make this work). Twitter decorates each promoted tweet with a unique class so it really just becomes a matter of:
a) Finding a way to run JavaScript alongside Twitter and
b) Determining what class is used to identify ads.
Here’s a list of classes Twitter uses to decorate a promoted tweet:
- tweet js-stream-tweet
- js-actionable-tweet
- js-profile-popup-actionable
- original-tweet
- js-original-tweet
- promoted-tweet
- has-cards
- has-content
- presented
- scribed
- focus
Of these, promoted-tweet is what you want to manipulate. With jQuery, you can write something like this: $(“.promoted-tweet”).hide();
To run custom JavaScript alongside any website, refer to this Chrome plugin: Custom JavaScript for websites (https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija?hl=en)
- var Frequency = 1000;
- BeginsWith = function(Needle, Haystack)
- {
- return (Haystack.substr(0, Needle.length) == Needle);
- }
- function Closest(Element, Tag, Attribute, AttributeValue)
- {
- Tag = Tag.toUpperCase();
- do
- {
- if (Element.nodeName === Tag && Element.hasAttribute(Attribute) && BeginsWith(AttributeValue, Element.getAttribute(Attribute)))
- {
- return Element;
- }
- }
- while (Element = Element.parentNode);
- return null;
- }
- function HideSponsored()
- {
- var Elements = document.getElementsByClassName("_m8c");
- if (Elements !== null)
- {
- for (var i = 0, Length = Elements.length; i < Length; i++)
- {
- if (Elements[i].tagName == 'A' && Elements[i].innerHTML == 'Sponsored')
- {
- var Parent = Closest(Elements[i], 'div', 'data-referrer', 'hyperfeed_story_id_');
- if (Parent !== null)
- {
- Parent.parentNode.removeChild(Parent);
- }
- }
- }
- }
- }
- setInterval(HideSponsored, Frequency);
- var Frequency = 500;
- function Closest(Element, Tag)
- {
- Tag = Tag.toUpperCase();
- do
- {
- if (Element.nodeName === Tag)
- {
- return Element;
- }
- }
- while (Element = Element.parentNode);
- return null;
- }
- function HidePromotedTweets()
- {
- var Tweets = document.getElementsByClassName("promoted-tweet");
- if (Tweets !== null)
- {
- for (var i = 0, Length = Tweets.length; i < Length; i++)
- {
- if (Tweets[i] !== null)
- {
- var Tweet = Closest(Tweets[i], "li");
- if (Tweet !== null)
- {
- Tweet.parentNode.removeChild(Tweet);
- }
- }
- }
- }
- }
- setInterval(HidePromotedTweets, Frequency);
Note
- Makes sure jQuery is disabled! Enabling it will cause more issues than it solves.
- Facebook algorithm runs once per second; decreasing this may increasingly slow things down.
- Twitter algorithm can run more often as the performance hits aren’t as bad.
Artigos semelhantes
- Is there a way to get the current URL or path from within a Angular2 component? I'm currently using Angular2 rc6.
- Is there any way in c to change the value of a global variable through a function without passing it to the function?
- Is there a way to transfer a playlist from my iPhone onto iTunes on my computer?
- Is there a way to get a Bixby voice assistant on my Galaxy S7 Edge with Android 10 S9+ port ROM?