Advertisement
icze4r

Twitter Image :orig Promoter

Mar 6th, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Twitter Image :orig Promoter
  3. // @version 0.4
  4. // @description Automatically promotes twitter image links to :orig, such as from :large.
  5. // @author Cro
  6. // @match https://pbs.twimg.com/media/*
  7. // @grant none
  8. // @namespace https://greasyfork.org/users/10865
  9. // ==/UserScript==
  10. (function () {
  11. "use strict";
  12. var queryVars = function(str) {
  13. return str.replace(/^\?/, '').split('&').map(x => x.split('=')).reduce((a, [k, v]) => { a[k] = v; return a; }, {});
  14. };
  15. // Check if this page contains a single image whose source is also the location.
  16. var image = document.getElementsByTagName('img')[0];
  17. if (image && image.getAttribute('src') == location.href) {
  18. var pathname = location.pathname;
  19. // Check if we already have the orig modifier
  20. if (!pathname.match(/:orig$/)) {
  21. // Trim modifiers.
  22. var idx = pathname.lastIndexOf(':');
  23. if (idx >= 0)
  24. pathname = pathname.substr(0, idx);
  25. // Check if we need to append the file type.
  26. var format = queryVars(location.search).format;
  27. if (format && !location.pathname.endsWith(format))
  28. pathname += '.' + format;
  29. // Add the modifier.
  30. pathname += ':orig';
  31. window.location = pathname;
  32. }
  33. }
  34. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement