Show and reload broken images

The name explained it

目前為 2014-05-23 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Show and reload broken images
  3. // @description The name explained it
  4. // @namespace eight04.blogspot.com
  5. // @include http://*
  6. // @include https://*
  7. // @version 2.0
  8. // @grant GM_addStyle
  9. // ==/UserScript==
  10.  
  11. (function(){
  12. GM_addStyle(
  13. "img{-moz-force-broken-image-icon:1;}"
  14. );
  15. // var imgs=document.images;
  16. /*
  17. function checkBroken(img){
  18. // return window.getComputedStyle(img).MozForceBrokenImageIcon * 1;
  19. if(img.classList.contains("loaded")){
  20. return false;
  21. }
  22. if(!img.classList.contains("reloaded")){
  23. img.classList.add("reloaded");
  24. img.addEventListener("load", function(e){
  25. e.target.classList.add("loaded");
  26. }, false);
  27. }
  28. return true;
  29. // return !img.complete || !img.naturalWidth ||
  30. // (img.width == 24 && img.naturalWidth != img.width);
  31. }
  32. */
  33.  
  34. function load(d){
  35. d.src += "#";
  36. }
  37.  
  38. function reloadImg(){
  39. var imagesFailed = document.querySelectorAll("img:-moz-broken");
  40. var images = document.images;
  41. for(let image of images){
  42. if(!image.complete){
  43. image.classList.add("failed");
  44. }else{
  45. image.classList.remove("failed");
  46. }
  47. }
  48. for(let image of imagesFailed){
  49. image.classList.add("failed");
  50. }
  51. for(let image of images){
  52. if(image.classList.contains("failed") && image.src){
  53. load(image);
  54. }
  55. }
  56. }
  57.  
  58. function getKey(e){
  59. if(e.keyCode==82 && e.altKey)
  60. reloadImg();
  61. }
  62.  
  63. document.addEventListener("keyup",getKey,false);
  64.  
  65. })();