Upsize Stand-Alone Images

Proportionally enlarge smaller stand-alone images

  1. // ==UserScript==
  2. // @name Upsize Stand-Alone Images
  3. // @author Jefferson "jscher2000" Scher
  4. // @namespace JeffersonScher
  5. // @version 0.5.2
  6. // @copyright Copyright 2017 Jefferson Scher
  7. // @license BSD-3-Clause
  8. // @description Proportionally enlarge smaller stand-alone images
  9. // @match http*://*/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. var tgt;
  14. function resizeImg(e){
  15. var whratio = tgt.width / tgt.height;
  16. var wnew = window.innerWidth;
  17. var hnew = Math.round(wnew * (1 / whratio));
  18. if (hnew > window.innerHeight){
  19. hnew = window.innerHeight;
  20. wnew = Math.round(hnew * whratio);
  21. }
  22. tgt.width = wnew;
  23. tgt.height = hnew;
  24. }
  25. var resizeTimeout;
  26. function resizeThrottler(){
  27. if(!resizeTimeout){
  28. resizeTimeout = window.setTimeout(function(){resizeTimeout = null; resizeImg();}, 200);
  29. }
  30. }
  31. if (document.querySelector('head').innerHTML.indexOf('TopLevelImageDocument.css') > -1) {
  32. tgt = document.querySelector('body img'); // first image in body
  33. if (tgt.className.indexOf('shrinkToFit') == -1) {
  34. window.addEventListener('resize', resizeThrottler, false);
  35. window.setTimeout(resizeImg, 100);
  36. } else {
  37. // if Firefox is already managing resizing, do nothing
  38. }
  39. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址