Wayback Machine Image Fixer

Attempts to fix broken images by replacing them with working timestamps based on JSON results

  1. // ==UserScript==
  2. // @name Wayback Machine Image Fixer
  3. // @namespace DoomTay
  4. // @description Attempts to fix broken images by replacing them with working timestamps based on JSON results
  5. // @include http://web.archive.org/web/*
  6. // @include https://web.archive.org/web/*
  7. // @include http://wayback.archive.org/web/*
  8. // @include https://wayback.archive.org/web/*
  9. // @exclude /\*/
  10. // @exclude *.jpg
  11. // @exclude *.jpeg
  12. // @exclude *.png
  13. // @exclude *.gif
  14. // @exclude *.bmp
  15. // @version 1.6.1
  16. // @grant GM_xmlhttpRequest
  17. // @license GPL-3.0
  18.  
  19. // ==/UserScript==
  20.  
  21. var pics = document.images;
  22. var embeds = document.embeds;
  23. var backgrounds = Array.prototype.filter.call(document.getElementsByTagName("*"),hasBackground);
  24. var allPics = Array.prototype.slice.call(pics).concat(backgrounds, Array.prototype.slice.call(embeds));
  25. var testedURLs = [];
  26. var substitutionTable = {};
  27.  
  28. function hasBackground(value)
  29. {
  30. return (window.getComputedStyle(value) && window.getComputedStyle(value).backgroundImage != "none");
  31. }
  32.  
  33. function specialUses(pic)
  34. {
  35. var imgRef = referenceURL(pic);
  36. var filteredCases = {};
  37. filteredCases.replacements = [];
  38. if(!imgRef)
  39. {
  40. filteredCases.replacements = filteredCases.replacements.concat(imgRef);
  41. return filteredCases;
  42. }
  43. var specialCases = [{domain:"northarc.com/images/unsorted/",replacements:[imgRef.replace("thumb.","tn_"),imgRef.replace("thumb.","")],maxDimensions:{width:100,height:80},tags:"before"},
  44. {domain:"*",replacements:["data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="],condition:imgRef.includes("spacer.gif") || imgRef.includes("blank.gif"),tags:"after"},
  45. {domain:"akamai.net",replacements:[imgRef.replace(/.+akamai\.net\/7\/\d+\/\d+\/[a-z0-9]+\/(.+)/,"http://$1")],tags:"after"},
  46. {domain:"akamaitech.net",replacements:[imgRef.replace(/.+akamaitech\.net\/7\/\d+\/\d+\/[a-z0-9]+\/(.+)/,"http://$1")],tags:"after"},
  47. {domain:"members.tripod.com",replacements:[imgRef.replace(/members\.tripod\.com\/~([^\/]+)\/(.+)/,"$1.tripod.com/$2")],tags:"before"},
  48. {domain:"akebi.sakura.ne.jp",replacements:[imgRef.replace("m.",".")],tags:"after"},
  49. {domain:"maj.com",replacements:[imgRef.replace("maj.com.","majhost.com")],tags:"after"},
  50. {domain:"tinypic.com/",replacements:[imgRef.replace("/i","/oi")],tags:"after"},
  51. {domain:"boyis.com",replacements:[imgRef.replace("images","graphic")],condition:imgRef.includes("/images/small"),tags:"after"},
  52. {domain:"boyis.com",replacements:[imgRef.replace("graphic","images")],condition:imgRef.includes("/graphic/small"),tags:"after"},
  53. {domain:"event.surpara.com",replacements:[imgRef.replace("event","town")],tags:"after"},
  54. {domain:"boyis.com",replacements:[imgRef.replace("photos/coolcg","graphic/small"),imgRef.replace("images/coolcg","graphic/small")],condition:imgRef.includes("photos/coolcg") && imgRef.includes("_s"),tags:"after"},
  55. {domain:"221.253.137.119",replacements:[imgRef.replace("/en/","/ja/")],condition:imgRef.includes("/en/"),tags:"after"},
  56. {domain:"logitech.com",replacements:["http://www.logitech.com/logitech/new6-1.gif"],condition:imgRef.includes("home_header.gif"),tags:"before"},
  57. {domain:"logitech.com",replacements:["http://www.logitech.com/logitech/new6-3.gif"],condition:imgRef.includes("home_footer.gif"),tags:"before"},
  58. {domain:"logitech.com",replacements:["http://www.logitech.com/logitech/prod_row.gif"],condition:imgRef.includes("Images/main_navigator.gif"),tags:"before"},
  59. {domain:"logitech.com",replacements:["http://www.logitech.com/logitech/al1.gif"],condition:imgRef.includes("Images/navigator.gif"),tags:"before"},
  60. {domain:"logitech.com",replacements:["http://www.logitech.com/logitech/msensa.gif"],condition:imgRef.includes("Images/mmsensa.gif"),tags:"before"},
  61. {domain:"miniten.ddo.jp",replacements:[imgRef.replace("ddo.","mydns.")],tags:"after"},
  62. {domain:"iridion2.com",replacements:[imgRef + ".gif"],condition:imgRef.includes("images/avatars") && !imgRef.includes(".gif") && !imgRef.includes(".jpg"),tags:"after"},
  63. {domain:"half-life.com",replacements:[imgRef.replace("half-life.com","half-life2.com")],tags:"after"},
  64. {domain:"micronpc.com",replacements:[imgRef.replace("micronpc.com","mpccorp.com")],tags:"after"},
  65. {domain:"half-life2.com",replacements:[imgRef.replace("half-life2.com","half-life.com")],tags:"after"},
  66. {domain:"*",replacements:["http://www.surpara.com/img/ban/sp.gif","http://www.surpara.com/img/ban/sp2.gif","http://www.surpara.com/img/ban/sp3.gif","http://www.surpara.com/img/ban/sp4.gif","http://www.surpara.com/img/ban/sp5.gif","http://www.surpara.com/img/ban/sp6.gif","http://www.surpara.com/img/ban/sp7.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("surpara.com"),tags:"random,after"},
  67. {domain:"*",replacements:["http://www.gameha.com/gameha_m.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("gameha.com"),tags:"after"},
  68. {domain:"*",replacements:["http://www.oekaki.net/img/bn2_1.gif","http://www.oekaki.net/img/bn2_2.gif","http://www.oekaki.net/img/bn2_3.gif","http://www.oekaki.net/img/bn2_4.gif","http://www.oekaki.net/img/bn2_5.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("oekaki.net"),tags:"random,after"},
  69. {domain:"*",replacements:["http://brandk.net/search/img2/s_bnr_11.jpg","http://brandk.net/search/img2/s_bnr_10.jpg","http://brandk.net/search/img2/s_bnr_08.jpg","http://brandk.net/search/img2/s_bnr_04.jpg","http://brandk.net/search/img2/s_bnr_01.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("brandk.net"),tags:"random,after"},
  70. {domain:"*",replacements:["http://ragsearch.com/bana/banas.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("ragsearch.com"),tags:"after"},
  71. {domain:"minitokyo.net",replacements:[imgRef.replace("thumbs","view")],tags:"after"},
  72. {domain:"*",replacements:["http://celest.pobox.ne.jp/links/imgs/bn88.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("celest.pobox.ne.jp"),tags:"after"},
  73. {domain:"*",replacements:["http://biomediaproject.com/bmp/files/gfx/BIONICLE Web Kit/Masks" + imgRef.substring(imgRef.lastIndexOf("/"))],condition:["akaku_black.gif","akaku_blue.gif","akaku_brown.gif","akaku_green.gif","akaku_red.gif","akaku_white.gif","hau_black.gif","hau_blue.gif","hau_brown.gif","hau_green.gif","hau_red.gif","hau_white.gif","huna_brickyellow.gif","huna_darkgrey.gif","huna_grey.gif","huna_mediumblue.gif","huna_orange.gif","huna_yellowgreen.gif","infected_kanohi_big.jpg","infected_kanohi_small.gif","kakama_black.gif","kakama_blue.gif","kakama_brown.gif","kakama_green.gif","kakama_red.gif","kakama_white.gif","kaukau_black.gif","kaukau_blue.gif","kaukau_brown.gif","kaukau_green.gif","kaukau_red.gif","kaukau_white.gif","komau_brickyellow.gif","komau_darkgrey.gif","komau_grey.gif","komau_mediumblue.gif","komau_orange.gif","komau_yellowgreen.gif","mahiki_brickyellow.gif","mahiki_darkgrey.gif","mahiki_grey.gif","mahiki_mediumblue.gif","mahiki_orange.gif","mahiki_yellowgreen.gif","matatu_brickyellow.gif","matatu_darkgrey.gif","matatu_grey.gif","matatu_mediumblue.gif","matatu_orange.gif","matatu_yellowgreen.gif","miru_black.gif","miru_blue.gif","miru_brown.gif","miru_green.gif","miru_red.gif","miru_white.gif","pakari_black.gif","pakari_blue.gif","pakari_brown.gif","pakari_green.gif","pakari_red.gif","pakari_white.gif","rau_brickyellow.gif","rau_darkgrey.gif","rau_grey.gif","rau_mediumblue.gif","rau_orange.gif","rau_yellowgreen.gif","ruru_brickyellow.gif","ruru_darkgrey.gif","ruru_grey.gif","ruru_mediumblue.gif","ruru_orange.gif","ruru_yellowgreen.gif"].some(elem => imgRef.includes(elem)),tags:"after"},
  74. {domain:"*",replacements:["http://biomediaproject.com/bmp/files/gfx/BIONICLE%20Web%20Kit/Toa" + imgRef.substring(imgRef.lastIndexOf("/"))],condition:["gali_big.gif","Gali_big.jpg","gali_face.jpg","gali_face_transp.gif","gali_small.gif","Gali_small.jpg","kopaka_big.gif","Kopaka_big.jpg","kopaka_face.jpg","kopaka_face_transp.gif","kopaka_small.gif","Kopaka_small.jpg","lewa_big.gif","Lewa_big.jpg","lewa_face.jpg","lewa_face_transp.gif","lewa_small.gif","Lewa_small.jpg","onua_big.gif","Onua_big.jpg","onua_face.jpg","onua_face_transp.gif","onua_small.gif","Onua_small.jpg","pohatu_big.gif","Pohatu_big.jpg","pohatu_face.jpg","pohatu_face_transp.gif","pohatu_small.gif","Pohatu_small.jpg","tahu_big.gif","Tahu_big.jpg","tahu_face.jpg","tahu_face_transp.gif","tahu_small.gif","Tahu_small.jpg"].some(elem => imgRef.includes(elem)),tags:"after"},
  75. {domain:"*",replacements:["http://blue.sakura.ne.jp/~real/images/bana/s-01.gif","http://blue.sakura.ne.jp/~real/images/bana/s-02.gif","http://blue.sakura.ne.jp/~real/images/bana/s-03.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("http://blue.sakura.ne.jp/~real"),tags:"after,random"},
  76. {domain:"*",replacements:["http://www5.kiwi-us.com/~l-leaf/banners.gif","http://www5.kiwi-us.com/~l-leaf/banner01s.jpg","http://www5.kiwi-us.com/~l-leaf/banner02s.gif","http://www5.kiwi-us.com/~l-leaf/banner04s.gif","http://www5.kiwi-us.com/~l-leaf/banner06s.jpg","http://www5.kiwi-us.com/~l-leaf/banner07s.gif","http://www5.kiwi-us.com/~l-leaf/banner08s.jpg","http://www5.kiwi-us.com/~l-leaf/banner09s.gif","http://www5.kiwi-us.com/~l-leaf/banner10s.jpg","http://www5.kiwi-us.com/~l-leaf/banner11s.gif","http://www5.kiwi-us.com/~l-leaf/banner12s.jpg","http://www5.kiwi-us.com/~l-leaf/banner13s.gif","http://www5.kiwi-us.com/~l-leaf/banner14s.jpg","http://www5.kiwi-us.com/~l-leaf/banner15s.gif","http://www5.kiwi-us.com/~l-leaf/banner16s.gif","http://www5.kiwi-us.com/~l-leaf/banner17s.gif","http://www5.kiwi-us.com/~l-leaf/banner19s.gif","http://www5.kiwi-us.com/~l-leaf/banner34s.gif","http://www5.kiwi-us.com/~l-leaf/banner35s.gif","http://www5.kiwi-us.com/~l-leaf/banner36s.gif","http://www5.kiwi-us.com/~l-leaf/banner38s.gif","http://www5.kiwi-us.com/~l-leaf/banner41s.gif","http://www5.kiwi-us.com/~l-leaf/banner44s.gif","http://www5.kiwi-us.com/~l-leaf/banner00s.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("http://www5.kiwi-us.com/~l-leaf"),tags:"after,random"},
  77. {domain:"*",replacements:["http://www.sea-links.ne.jp/banner/minicon.gif","http://www.sea-links.ne.jp/banner/static/minicon_miu1.gif","http://www.sea-links.ne.jp/banner/static/minicon_miu2.gif","http://www.sea-links.ne.jp/banner/static/minicon_miu3.gif","http://www.sea-links.ne.jp/banner/static/minicon_miu4.gif","http://www.sea-links.ne.jp/banner/static/minicon_miu5.gif","http://www.sea-links.ne.jp/banner/static/minicon.gif","http://www.sea-links.ne.jp/banner/static/minicon2.gif","http://www.sea-links.ne.jp/banner/static/boy_s.jpg","http://www.sea-links.ne.jp/banner/prince/minicon.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("www.sea-links.ne.jp"),tags:"after,random"},
  78. {domain:"*",replacements:["http://www.interq.or.jp/red/pocky/cg2/bnavi001s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi003s.jpg","http://www.interq.or.jp/red/pocky/cg2/bnavi004s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi007s.jpg","http://www.interq.or.jp/red/pocky/cg2/bnavi008s.jpg","http://www.interq.or.jp/red/pocky/cg2/bnavi009s.jpg","http://www.interq.or.jp/red/pocky/cg2/bnavi010s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi011s.jpg","http://www.interq.or.jp/red/pocky/cg2/bnavi012s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi013s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi014s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi016s.jpg","http://www.interq.or.jp/red/pocky/cg2/bnavi017s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi018s.jpg","http://www.interq.or.jp/red/pocky/cg2/bnavi019s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi020s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi022s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi024s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi02s.gif","http://www.interq.or.jp/red/pocky/cg2/bnavi04s.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("www.interq.or.jp/red/pocky"),tags:"after,random"},
  79. {domain:"*",replacements:["http://tinami.com/banner/s01.gif","http://tinami.com/banner/s02.gif","http://tinami.com/banner/s03.gif","http://tinami.com/banner/s04.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("tinami.com"),tags:"after,random"},
  80. {domain:"*",replacements:["http://home.puni.to/net/8831.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("puni.to"),tags:"after"},
  81. {domain:"*",replacements:["http://closedsky.com/graphic/meguribs.jpg","http://www.meguri.net/banner/maya.jpg","http://meguri.net/banner/meguri-mini1.gif","http://meguri.net/banner/meguri-mini3.gif","http://www.meguri.net/banner/meguri-mini5.gif","http://meguri.net/banner/meguri-mini7.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("meguri.net"),tags:"after,random"},
  82. {domain:"*",replacements:["http://www.multiez.com/multi/banner/ban2_s.gif","http://www.multiez.com:80/banner/multi_br02.gif","http://www.multiez.com/multi/banner/multi_br04.gif","http://www.multiez.com/multi/banner/multi_br06.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("multiez.com"),tags:"after,random"},
  83. {domain:"*",replacements:["http://www.apache.org/icons" + imgRef.substring(imgRef.lastIndexOf("/"))],condition:document.body.textContent.includes("Apache/"),tags:"after"},
  84. {domain:"*",replacements:["http://www.amaterasu.jp/banner/mini_banner.gif","http://www.amaterasu.jp/banner/mini_banner20.gif","http://mimina.sakura.ne.jp/amaterasu/banner/mini_banner21.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("amaterasu.jp"),tags:"after,random"},
  85. {domain:"*",replacements:["http://www.lovehina.to/~hina/8831naru.jpg","http://www.lovehina.to/~hina/8831shinobu.jpg","http://www.lovehina.to/~hina/8831motoko.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("lovehina.to/~hina"),tags:"after,random"},
  86. {domain:"*",replacements:["http://www4.nasuinfo.or.jp/~kouichi/Link/buaner1.9.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("nasuinfo.or.jp/~kouichi"),tags:"after"},
  87. {domain:"*",replacements:["http://itarunsearch.com/img/banner/itarun001_mini.jpg","http://itarunsearch.com/img/banner/itarun002_mini.jpg","http://itarunsearch.com/img/banner/itarun006_mini.jpg","http://itarunsearch.com/img/banner/itarun_c_mini.jpg","http://itarunsearch.com/img/banner/itarun_mii_mini.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("itarunsearch.com"),tags:"after,random"},
  88. {domain:"*",replacements:["http://foxhunt.cx/tallyho0.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("foxhunt.cx/tallyho"),tags:"after"},
  89. {domain:"*",replacements:["http://earth.endless.ne.jp/users/hibiki/banan.jpg","http://earth.endless.ne.jp/users/hibiki/ban1.jpg","http://earth.endless.ne.jp/users/hibiki/banan1.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("earth.endless.ne.jp/users/hibiki"),tags:"after,random"},
  90. {domain:"*",replacements:["http://www.st-argo.co.jp/animap/banner/animap03.gif","http://www.st-argo.co.jp/animap/banner/animap04.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("st-argo.co.jp/animap"),tags:"after,random"},
  91. {domain:"*",replacements:["http://www95.sakura.ne.jp/~b-search/bn/mini.gif","http://www95.sakura.ne.jp/~b-search/bn/mini_01.gif","http://www95.sakura.ne.jp/~b-search/bn/mini_02.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("www95.sakura.ne.jp/~b-search"),tags:"after,random"},
  92. {domain:"*",replacements:["http://www.auxo.org/kaleidoscope/image/kaleidobana2.jpg","http://www.auxo.org/kaleidoscope/image/kaleidobana2.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("auxo.org/kaleidoscope"),tags:"after,random"},
  93. {domain:"*",replacements:["http://sispulink.g-com.ne.jp/bn/sisterlink_m.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("sispulink.g-com.ne.jp"),tags:"after"},
  94. {domain:"*",replacements:["http://www2.ocn.ne.jp/~all8324/bana_top/01_88.jpg","http://www2.ocn.ne.jp/~all8324/bana_/88_02.jpg","http://www2.ocn.ne.jp/~all8324/bana_/88_03.gif","http://www2.ocn.ne.jp/~all8324/bana_/88_04.jpg","http://www2.ocn.ne.jp/~all8324/bana_/88_05.gif","http://www2.ocn.ne.jp/~all8324/bana_/88_06.JPG","http://www2.ocn.ne.jp/~all8324/bana_/88_07.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("www2.ocn.ne.jp/~all8324"),tags:"after,random"},
  95. {domain:"*",replacements:["http://orange.webdos.net/~irasuto/hina/bana88_01.gif","http://orange.webdos.net/~irasuto/bana_/09-88_31.jpg","http://orange.webdos.net/~irasuto/bana_/01-88_31.gif","http://orange.webdos.net/~irasuto/bana_/02-88_31.gif","http://orange.webdos.net/~irasuto/bana_/03-88_31.gif","http://orange.webdos.net/~irasuto/bana_/04-88_31.gif","http://orange.webdos.net/~irasuto/bana_/05-88_31.gif","http://orange.webdos.net/~irasuto/bana_/06-88_31.gif","http://orange.webdos.net/~irasuto/bana_/07-88_31.jpg","http://orange.webdos.net/~irasuto/bana_/08-88_31.gif","http://orange.webdos.net/~irasuto/bana_/10-88_31.jpg","http://orange.webdos.net/~irasuto/bana_2/12_88.jpg","http://orange.webdos.net/~irasuto/bana_2/13_88.jpg","http://orange.webdos.net/~irasuto/bana_2/14_88.gif","http://orange.webdos.net/~irasuto/bana_2/15_88.GIF","http://orange.webdos.net/~irasuto/bana_2/16_88.JPG"],condition:pic.width == 88 && pic.height == 31 && linksTo("orange.webdos.net/~irasuto"),tags:"after,random"},
  96. {domain:"*",replacements:["http://wn.31rsm.ne.jp/~anikomi/anibana2.gif","http://wn.31rsm.ne.jp/~anikomi/anikomi-mini.gif","http://wn.31rsm.ne.jp/~anikomi/ani_m.jpg","http://wn.31rsm.ne.jp/~anikomi/anikomi88bana.jpg","http://wn.31rsm.ne.jp/~anikomi/bn-s..gif","http://wn.31rsm.ne.jp/~anikomi/anikomi_b2.gif","http://wn.31rsm.ne.jp/~anikomi/banner2.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("wn.31rsm.ne.jp/~anikomi"),tags:"after,random"},
  97. {domain:"*",replacements:["http://wataru66.ktplan.ne.jp/jpg/fullmediabanar_1.gif","http://wataru66.ktplan.ne.jp/jpg/fms09.gif","http://wataru66.ktplan.ne.jp/jpg/fms10.gif","http://wataru66.ktplan.ne.jp/jpg/fms_88_31.gif","http://wataru66.ktplan.ne.jp/jpg/illust/fms11b.jpg","http://wataru66.ktplan.ne.jp/jpg/illust/fms12b.jpg","http://wataru66.ktplan.ne.jp/jpg/illust/fms13b.gif","http://wataru66.ktplan.ne.jp/jpg/illust/fms14b.jpg","http://wataru66.ktplan.ne.jp/jpg/illust/fms15b.gif","http://wataru66.ktplan.ne.jp/jpg/illust/fms16b.jpg","http://wataru66.ktplan.ne.jp/jpg/illust/fms17b.gif","http://wataru66.ktplan.ne.jp/jpg/illust/fms21b.jpg","http://wataru66.ktplan.ne.jp/jpg/illust/fms22b.gif","http://wataru66.ktplan.ne.jp/jpg/illust/fms23b.jpg","http://wataru66.ktplan.ne.jp/jpg/illust/fms25b.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("wataru66.ktplan.ne.jp"),tags:"after,random"},
  98. {domain:"*",replacements:["http://www.silver-forest.com/bh-search/g/88-31.gif","http://www.silver-forest.com/bh-search/g/88-31a.gif","http://www.silver-forest.com/bh-search/g/88-31b.gif","http://www.silver-forest.com/bh-search/g/88-31c.gif","http://www.silver-forest.com/bh-search/g/88-31e.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("silver-forest.com"),tags:"after,random"},
  99. {domain:"*",replacements:["http://www.k-books.co.jp/k-books.gif"],condition:pic.width == 200 && pic.height == 40 && linksTo("k-books.co.jp"),tags:"after"},
  100. {domain:"*",replacements:["http://www2m.biglobe.ne.jp/~msdos/ban_cgps.png"],condition:pic.width == 88 && pic.height == 31 && (linksTo("prettycg.com") || linksTo("www2m.biglobe.ne.jp/~msdos")),tags:"after"},
  101. {domain:"*",replacements:["http://www.oisan.jp/bana/ban105.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("oisan.jp/search"),tags:"after"},
  102. {domain:"*",replacements:["http://moechara.com/moemoe/mmsbm.png"],condition:pic.width == 88 && pic.height == 31 && (linksTo("moechara.com") || linksTo("character.moemoe.to")),tags:"after"},
  103. {domain:"*",replacements:["http://www.e-r1.com/image/e-r_banner/e-r_mini2.jpg"],condition:pic.width == 88 && pic.height == 31 && linksTo("e-r1.com"),tags:"after"},
  104. {domain:"*",replacements:["http://gamemichi.com/image/g_ban88_31.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("gamemichi.com"),tags:"after"},
  105. {domain:"*",replacements:["http://www.toranoana.jp/icon/tora_bn.gif"],condition:pic.width == 200 && pic.height == 40 && linksTo("toranoana.jp"),tags:"after"},
  106. {domain:"*",replacements:["http://www.dgsearch.com/image/bana88.gif"],condition:pic.width == 88 && pic.height == 31 && linksTo("dgsearch.com"),tags:"after"},
  107. {domain:"*",replacements:["http://www2.melonbooks.co.jp/img/banner.gif","http://www2.melonbooks.co.jp/img/banner2.gif","http://www2.melonbooks.co.jp/img/banner3.gif","http://www2.melonbooks.co.jp/img/banner4.gif"],condition:pic.width == 200 && pic.height == 40 && linksTo("shop.melonbooks.co.jp"),tags:"after,random"},
  108. {domain:"questarian.com",replacements:[imgRef.replace(/im\d+\//i,"images/")],tags:"after"}];
  109. var tagScan = ["before","between","after"];
  110. for(var t = 0; t < 3; t++)
  111. {
  112. if(t == 1) filteredCases.replacements = filteredCases.replacements.concat(imgRef);
  113. else
  114. {
  115. for(var c = 0; c < specialCases.length; c++)
  116. {
  117. var additionalCondition = specialCases[c].condition !== undefined ? specialCases[c].condition : true;
  118. if((imgRef.includes(specialCases[c].domain) || specialCases[c].domain == "*") && additionalCondition && specialCases[c].tags.includes(tagScan[t]))
  119. {
  120. if(specialCases[c].tags.includes("random")) filteredCases.replacements = filteredCases.replacements.concat(specialCases[c].replacements[Math.floor(Math.random() * specialCases[c].replacements.length)]);
  121. else filteredCases.replacements = filteredCases.replacements.concat(specialCases[c].replacements);
  122. if(specialCases[c].maxDimensions) filteredCases.maxDimensions = specialCases[c].maxDimensions;
  123. }
  124. }
  125. }
  126. }
  127. return filteredCases;
  128.  
  129. function linksTo(url)
  130. {
  131. return pic.parentNode.nodeName == "A" && pic.parentNode.href && decodeURI(pic.parentNode.href).includes(url);
  132. }
  133. }
  134.  
  135. var timestamp = /web\/(\d{1,14})/.exec(window.location.href)[1];
  136.  
  137. function testURL(url)
  138. {
  139. var promise = new Promise(function(resolve,reject) {
  140. GM_xmlhttpRequest({
  141. url: url,
  142. method: "HEAD",
  143. onload: function(response) {
  144. resolve(response);
  145. }
  146. });
  147. });
  148. return promise;
  149. }
  150.  
  151. function promiseFirst(array, condition)
  152. {
  153. return Promise.all(array).then(value => value.find(condition));
  154. }
  155.  
  156. function replaceImage(target, altURLs)
  157. {
  158. var possibleUses = specialUses(target);
  159. var URLGuesses = [];
  160. if(altURLs && altURLs.length > 0) URLGuesses = altURLs;
  161. else if(possibleUses.replacements.length > 0) URLGuesses = possibleUses.replacements;
  162. else URLGuesses = [referenceURL(target)];
  163.  
  164. var testSet = [];
  165.  
  166. for(var p = 0; p < URLGuesses.length; p++)
  167. {
  168. if(!URLGuesses[p]) testSet[p] = Promise.resolve(null);
  169. else if(URLGuesses[p].includes("http")) testSet[p] = APITest(URLGuesses[p]);
  170. else if(URLGuesses[p].startsWith("data:"))
  171. {
  172. testSet[p] = Promise.resolve(URLGuesses[p]);
  173. break;
  174. }
  175. }
  176.  
  177. promiseFirst(testSet,result => result != null).then(function(result) {
  178. var similarPics = allPics.filter(pic => referenceURL(target) == referenceURL(pic));
  179. for(var s = 0; s < similarPics.length; s++)
  180. {
  181. if(result !== undefined)
  182. {
  183. substitutionTable[referenceURL(target).replace(":80","")] = result;
  184. if(possibleUses.maxDimensions) switchWithResize(result, similarPics[s], possibleUses.maxDimensions.width, possibleUses.maxDimensions.height);
  185. else changeImage(result, similarPics[s]);
  186. }
  187. //Try and "expose" image links that are unclickable due to the image not loading
  188. else if(similarPics[s].alt === "" && similarPics[s].width === 0 && similarPics[s].parentNode.nodeName === "A" && similarPics[s].src)
  189. {
  190. similarPics[s].width = 24;
  191. similarPics[s].height = 24;
  192. //"Changing" the source is pretty hacky, but it's the only way I can think of to turn "invisible" image links into something clickable
  193. similarPics[s].src = similarPics[s].src;
  194. }
  195. }
  196. return;
  197. });
  198.  
  199. function APITest(replacement)
  200. {
  201. var subPromise = new Promise(function(resolve,reject) {
  202. var originalURL = replacement.substring(replacement.indexOf("/http") + 1);
  203.  
  204. APIReq(originalURL,timestamp).then(function(response)
  205. {
  206. if(response.archived_snapshots.closest !== undefined)
  207. {
  208. //Evidently an additional layer of examination is needed to make absolutely sure we have an actual image
  209. processResult(response.archived_snapshots.closest.url);
  210. }
  211. else
  212. {
  213. //Sometimes an API result will turn up blank unless the timestamp parameter were removed
  214. APIReq(originalURL).then(function(secondResponse)
  215. {
  216. if(secondResponse.archived_snapshots.closest !== undefined)
  217. {
  218. //Evidently an additional layer of examination is needed to make absolutely sure we have an actual image
  219. processResult(secondResponse.archived_snapshots.closest.url);
  220. }
  221. else resolve(null);
  222. })
  223. }
  224. })
  225.  
  226. function processResult(url)
  227. {
  228. testURL(url.replace("/http","im_/http")).then(function(secondResp) {
  229. if(!secondResp.responseHeaders.toLowerCase().includes("content-type: text/html")) resolve(secondResp.finalUrl);
  230. else return testURL("/web/1im_/" + originalURL).then(function(lastResort) {
  231. if(!lastResort.responseHeaders.toLowerCase().includes("content-type: text/html")) resolve(lastResort.finalUrl);
  232. else resolve(null);
  233. });
  234. })
  235. }
  236.  
  237. }).catch(function(e) { console.log(e); });
  238. return subPromise;
  239.  
  240. function APIReq(startingURL,timestamp)
  241. {
  242. var compiledURL = "http://archive.org/wayback/available?url=" + encodeURIComponent(startingURL);
  243. if(timestamp) compiledURL += "&timestamp=" + timestamp;
  244.  
  245. return new Promise(function(resolve,reject) {
  246. GM_xmlhttpRequest({
  247. url: compiledURL,
  248. method: "GET",
  249. responseType: "json",
  250. headers: {"Accept": "application/json"},
  251. onload: function(response) {
  252. if(response.status == 503) resolve(APIReq(startingURL,timestamp));
  253. else resolve(response.response);
  254. }
  255. });
  256. })
  257. }
  258. }
  259.  
  260. function switchWithResize(url, target, width, height)
  261. {
  262. var oldDimensions = {width:width, height: height};
  263. changeImage(url, target);
  264. target.onload = function() {
  265. var aspectRatio = target.naturalWidth / target.naturalHeight;
  266. if(target.naturalWidth >= target.naturalHeight)
  267. {
  268. target.width = oldDimensions.width;
  269. target.height = oldDimensions.width / aspectRatio;
  270. }
  271. else if(target.naturalWidth <= target.naturalHeight)
  272. {
  273. target.height = oldDimensions.height;
  274. target.width = oldDimensions.height * aspectRatio;
  275. }
  276. };
  277. }
  278. }
  279.  
  280. function changeImage(url, target)
  281. {
  282. if(!url.includes("im_")) url = url.replace("/http","im_/http");
  283. url = url.replace("http://web.archive.org","");
  284. if(target.src) target.src = url;
  285. else if(target.background) target.background = url;
  286. else if(window.getComputedStyle(target).backgroundImage != "none") target.style.backgroundImage = window.getComputedStyle(target).backgroundImage.replace(/(url\().+(\))/,"$1" + url + "$2");
  287. }
  288.  
  289. function referenceURL(target)
  290. {
  291. if(target._wm_src) return target._wm_src;
  292. else if(target.src) return target.src;
  293. else if(window.getComputedStyle(target).backgroundImage != "none") return window.getComputedStyle(target).backgroundImage.slice(5,-2);
  294. }
  295.  
  296. function evaluateImage(pic)
  297. {
  298. var imgRef = referenceURL(pic);
  299.  
  300. if(substitutionTable.hasOwnProperty(imgRef))
  301. {
  302. pic.src = substitutionTable[imgRef];
  303. return;
  304. }
  305.  
  306. if(testedURLs.indexOf(imgRef) > -1) return;
  307.  
  308. testedURLs.push(imgRef);
  309.  
  310. GM_xmlhttpRequest({
  311. url: imgRef,
  312. method: "GET",
  313. onload: function(response) {
  314. //Going off of response code is unreliable. Sometimes an image will return a status code of 200 even though it would redirect to an error page should you view the image directly, so we're looking at content type instead
  315. if(response.responseHeaders.toLowerCase().includes("content-type: text/html") || response.responseHeaders.toLowerCase().includes("content-type: text/plain") || (response.responseText && response.responseText.toUpperCase().includes("<BODY>")))
  316. {
  317. //This might be a case where if you were visit the image directly, you would be redirected elsewhere. This attempts to catch that and replace the pic's src with where it would take you.
  318. var doc = new DOMParser().parseFromString(response.responseText,"text/html");
  319. if(doc.querySelector(".impatient") && !doc.querySelector(".impatient").firstChild.href.includes("tripod.com/adm/interstitial/remote.jpg"))
  320. {
  321. testURL(doc.querySelector(".impatient").firstChild.href).then(function(response) {
  322. if(!response.responseHeaders.toLowerCase().includes("content-type: text/html"))
  323. {
  324. replaceImage(pic,[response.finalUrl]);
  325. }
  326. else
  327. {
  328. replaceImage(pic);
  329. }
  330. });
  331. }
  332. else
  333. {
  334. replaceImage(pic);
  335. }
  336. }
  337. },
  338. onerror: function() {
  339. replaceImage(pic);
  340. }
  341. });
  342. }
  343.  
  344. for(var i = 0; i < pics.length; i++)
  345. {
  346. //Skip over stuff related to the Wayback Machine toolbar and data URIs
  347. if((document.getElementById("wm-ipp") && document.getElementById("wm-ipp").contains(pics[i])) || pics[i].src.includes("data:")) continue;
  348. if(pics[i].src.startsWith("ttp://")) pics[i].src = "/web/" + timestamp + "/h" + pics[i].src;
  349. if(pics[i].complete && pics[i].naturalWidth == 0) evaluateImage(pics[i]);
  350. pics[i].addEventListener("error", function(e) { evaluateImage(e.target); }, true);
  351. }
  352.  
  353. for(var e = 0; e < embeds.length; e++)
  354. {
  355. evaluateImage(embeds[e]);
  356. }
  357.  
  358. for(var b = 0; b < backgrounds.length; b++)
  359. {
  360. if(document.getElementById("wm-ipp") && document.getElementById("wm-ipp").contains(backgrounds[b])) continue;
  361. if(window.getComputedStyle(backgrounds[b]).backgroundImage == "none") continue;
  362. evaluateImage(backgrounds[b]);
  363. }

QingJ © 2025

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