RES Twitter Fix

Fixes RES Twitter expandos in Firefox

  1. // ==UserScript==
  2. // @name RES Twitter Fix
  3. // @namespace com.res-twitter-fix
  4. // @description Fixes RES Twitter expandos in Firefox
  5. // @match https://*.reddit.com/*
  6. // @run-at document-end
  7. // @grant none
  8. // @version 3.2
  9. // ==/UserScript==
  10.  
  11. "use strict"
  12.  
  13. function injectTwitterScript()
  14. {
  15. // inject twitter script to convert blockquotes into pretty twitter displays
  16. const script = document.createElement( 'script' )
  17. script.src = 'https://platform.twitter.com/widgets.js'
  18. document.body.appendChild( script )
  19. }
  20.  
  21. function fixExpandos()
  22. {
  23. // look for un-rendered twitter expandos and proceed if any are found
  24. console.log( 'looking for expandos' )
  25. const expandos = document.querySelectorAll( '.twitter-tweet:not(.twitter-tweet-rendered' )
  26. if ( expandos.length > 0 )
  27. {
  28. console.log( 'fixing expandos!' )
  29. injectTwitterScript()
  30. }
  31. }
  32.  
  33. function onClick( e )
  34. {
  35. // check if we've clicked an expando button
  36. if ( e.target.className.includes( 'expando-button' ) )
  37. {
  38. // fix expandos on click
  39. fixExpandos()
  40.  
  41. // also attempt to fix auto-expanded expandos...
  42. // perhaps this is not the most reliable way to do it, as there's
  43. // no way to know exactly how long it'll take RES to auto-expand.
  44. // regardless, injecting the script twice does no harm
  45. setTimeout( () => { fixExpandos() }, 1000 )
  46. }
  47. }
  48. document.addEventListener( 'click', onClick, false )