QNA > I > Is There A Way To Block Or Remove Twitter Ads?

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)

Facebook

  1. var Frequency = 1000; 
  2.  
  3. BeginsWith = function(Needle, Haystack) 
  4. return (Haystack.substr(0, Needle.length) == Needle); 
  5.  
  6. function Closest(Element, Tag, Attribute, AttributeValue)  
  7. Tag = Tag.toUpperCase(); 
  8. do  
  9. if (Element.nodeName === Tag && Element.hasAttribute(Attribute) && BeginsWith(AttributeValue, Element.getAttribute(Attribute))) 
  10. return Element; 
  11. }  
  12. while (Element = Element.parentNode); 
  13. return null; 
  14.  
  15. function HideSponsored() 
  16. var Elements = document.getElementsByClassName("_m8c"); 
  17. if (Elements !== null) 
  18. for (var i = 0, Length = Elements.length; i < Length; i++) 
  19. if (Elements[i].tagName == 'A' && Elements[i].innerHTML == 'Sponsored') 
  20. var Parent = Closest(Elements[i], 'div', 'data-referrer', 'hyperfeed_story_id_'); 
  21. if (Parent !== null) 
  22. Parent.parentNode.removeChild(Parent); 
  23.  
  24. setInterval(HideSponsored, Frequency); 

Twitter

  1. var Frequency = 500; 
  2.  
  3. function Closest(Element, Tag)  
  4. Tag = Tag.toUpperCase(); 
  5. do  
  6. if (Element.nodeName === Tag) 
  7. return Element; 
  8. }  
  9. while (Element = Element.parentNode); 
  10. return null; 
  11.  
  12. function HidePromotedTweets() 
  13. var Tweets = document.getElementsByClassName("promoted-tweet"); 
  14. if (Tweets !== null) 
  15. for (var i = 0, Length = Tweets.length; i < Length; i++) 
  16. if (Tweets[i] !== null) 
  17. var Tweet = Closest(Tweets[i], "li"); 
  18. if (Tweet !== null) 
  19. Tweet.parentNode.removeChild(Tweet); 
  20.  
  21. 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.

Di Zia Bortzer

Come bloccare gli annunci sul mio Lenovo K8+ :: Come sbarazzarsi di annunci inappropriati sul computer di mia figlia senza installare nulla
Link utili