Redirect twimg to :orig

Redirect twimg image URLs to enforce name=orig for full-resolution images

  1. // ==UserScript==
  2. // @name Redirect twimg to :orig
  3. // @namespace https://prometheus-systems.co.za/
  4. // @version 0.0.6
  5. // @description Redirect twimg image URLs to enforce name=orig for full-resolution images
  6. // @author rwdcameron
  7. // @license GPLv2
  8. // @supportURL mailto://rwd.cameron@prometheus-systems.co.za?Subject=twimg-resizer
  9. // @match *://pbs.twimg.com/media/*
  10. // @exclude *://pbs.twimg.com/media/*?*name=orig*
  11. // @run-at document-start
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. const params = new URLSearchParams(window.location.search);
  19.  
  20. // If the 'name' variable is already set to 'orig' do nothing
  21. if (params.get('name') === 'orig') return;
  22.  
  23. // Set the 'name' variable to 'orig'
  24. params.set('name', 'orig');
  25.  
  26. const newUrl = window.location.origin + window.location.pathname + '?' + params.toString() + window.location.hash;
  27. window.location.replace(newUrl);
  28. })();