Twitter Remove s Param

Remove the s=... parameter from the page

  1. // ==UserScript==
  2. // @name Twitter Remove s Param
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Remove the s=... parameter from the page
  6. // @author cro
  7. // @match https://*.twitter.com/*
  8. // @match https://*.x.com/*
  9. // @icon https://www.google.com/s2/favicons?domain=twitter.com
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13. /* jshint esversion: 6 */
  14.  
  15. (function() {
  16. 'use strict';
  17. const path_regex = /\/.+\/status\//;
  18.  
  19. let remove_param = function(state)
  20. {
  21. let url = new URL(window.location);
  22. if (url.pathname.match(path_regex))
  23. {
  24. if (url.searchParams.has('s'))
  25. {
  26. url.searchParams.delete('s');
  27. history.replaceState(state, '', url);
  28. history.go();
  29. }
  30. }
  31. };
  32.  
  33. const pushState = history.pushState;
  34.  
  35. // In the event that SPA navigation brings us to a page with the target param, then intercept and replace.
  36. // I think that this may only happen if navigating via mobile.
  37. history.pushState = function()
  38. {
  39. pushState.apply(this, arguments);
  40. remove_param(this.state);
  41. };
  42.  
  43. remove_param(history.state);
  44. })();