Resize Image On "Open image in new tab"

Support: Google(G+ blogspot YouTube)\Tumblr\Twitter\Steam(Only user content)\weibo.com (And more...

当前为 2017-08-27 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Resize Image On "Open image in new tab"
  3. // @name:zh-cn 右键在新标签中打开图片时显示最优化图像质量
  4. // @version 0.5.24
  5. // @description Support: Google(G+ blogspot YouTube)\Tumblr\Twitter\Steam(Only user content)\weibo.com (And more...
  6. // @description:zh-cn 支持:谷歌(G+ blogspot YouTube)、Tumblr、推特、Steam、新浪微博、知乎、豆瓣、百度贴吧
  7. // @run-at document-start
  8. // @match http://*.googleusercontent.com/*
  9. // @match https://*.googleusercontent.com/*
  10. // @match http://*.media.tumblr.com/*
  11. // @match https://*.media.tumblr.com/*
  12. // @match http://secure.static.tumblr.com/*
  13. // @match https://secure.static.tumblr.com/*
  14. // @match http://*.bp.blogspot.com/*
  15. // @match https://*.bp.blogspot.com/*
  16. // @match http://*.sinaimg.cn/*
  17. // @match https://*.sinaimg.cn/*
  18. // @match http://*.twimg.com/*
  19. // @match https://*.twimg.com/*
  20. // @match http://*.zhimg.com/*
  21. // @match https://*.zhimg.com/*
  22. // @match http://*.douban.com/view/*
  23. // @match https://*.douban.com/view/*
  24. // @match http://*.doubanio.com/view/*
  25. // @match https://*.doubanio.com/view/*
  26. // @match http://imgsrc.baidu.com/*
  27. // @match https://imgsrc.baidu.com/*
  28. // @match http://imgsrc.bdimg.com/*
  29. // @match https://imgsrc.bdimg.com/*
  30. // @match http://*.hiphotos.baidu.com/*
  31. // @match https://*.hiphotos.baidu.com/*
  32. // @match http://*.hiphotos.bdimg.com/*
  33. // @match https://*.hiphotos.bdimg.com/*
  34. // @match http://imgsa.baidu.com/*
  35. // @match https://imgsa.baidu.com/*
  36. // @match http://imgsa.bdimg.com/*
  37. // @match https://imgsa.bdimg.com/*
  38. // @match http://images.akamai.steamusercontent.com/*
  39. // @match https://images.akamai.steamusercontent.com/*
  40. // @match http://steamuserimages-a.akamaihd.net/*
  41. // @match https://steamuserimages-a.akamaihd.net/*
  42. // @match http://*.artstation.com/*
  43. // @match https://*.artstation.com/*
  44. // @match http://i.ytimg.com/*
  45. // @match https://i.ytimg.com/*
  46. // @match http://*.ggpht.com/*
  47. // @match https://*.ggpht.com/*
  48. // @match http://*.pinimg.com/*
  49. // @match https://*.pinimg.com/*
  50. // @match http://*.hdslb.com/*
  51. // @match https://*.hdslb.com/*
  52. // @namespace https://greasyfork.org/users/2646
  53. // @contributionURL http://clso.tk/donate/
  54. // @contributionAmount 6.66
  55. // @copyright 2014-2017, CLE
  56. // ==/UserScript==
  57.  
  58. var url = document.location.toString();
  59. var m = null;
  60.  
  61.  
  62.  
  63. //google
  64. if( (m = url.match(/^(https?:\/\/lh\d+\.googleusercontent\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  65. if(m[2] != "s0") {
  66. document.location = m[1] + "s0" + m[3];
  67. }
  68. }
  69. else if( (m = url.match(/^(https?:\/\/lh\d+\.googleusercontent\.com\/.+=)(.+)(?:\?.+)?$/i)) ) {
  70. if(m[2] != "s0") {
  71. document.location = m[1] + "s0";
  72. }
  73. }
  74. else if( (m = url.match(/^(https?:\/\/\w+\.ggpht\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  75. if(m[2] != "s0") {
  76. document.location = m[1] + "s0" + m[3];
  77. }
  78. }
  79.  
  80. //blogspot
  81. else if( (m = url.match(/^(https?:\/\/\w+\.bp\.blogspot\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  82. if(m[2] != "s0") {
  83. document.location = m[1] + "s0" + m[3];
  84. }
  85. }
  86.  
  87. //youtube
  88. else if( (m = url.match(/^https?:\/\/i\.ytimg.com\/an_webp\/([^\/]+)\/\w+\.(jpg|jpeg|gif|png|bmp|webp)(\?.+)?$/i)) ) {
  89. // NEED TEST
  90. var ajax = new XMLHttpRequest();
  91. ajax.onreadystatechange=function() {
  92. if(ajax.status==200) {
  93. document.location = "https://i.ytimg.com/vi/" + m[1] + "/maxresdefault.jpg";
  94. }else if(ajax.status==404) {
  95. document.location = "https://i.ytimg.com/vi/" + m[1] + "/hqdefault.jpg";
  96. }
  97. };
  98. ajax.open("HEAD", "https://i.ytimg.com/vi/" + m[1] + "/maxresdefault.jpg", true);
  99. ajax.send();
  100. }
  101. /*else if( (m = url.match(/^(https?:\/\/i\.ytimg.com\/vi\/[^\/]+\/)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(\?.+)?$/i)) ) {
  102. if(m[2] != "maxresdefault") {
  103. var ajax = new XMLHttpRequest();
  104. ajax.onreadystatechange=function() {
  105. if(ajax.status==200) {
  106. document.location = m[1] + "maxresdefault" + m[3];
  107. }else if(ajax.status==404) {
  108. if(m[5] || m[2] === "mqdefault")
  109. document.location = m[1] + "hqdefault" + m[3];
  110. }
  111. };
  112. ajax.open("HEAD", m[1] + "maxresdefault" + m[3], true);
  113. ajax.send();
  114. }
  115. }*/
  116.  
  117. //tumblr
  118. else if( (m = url.match(/^(https?:\/\/.+\.tumblr\.com\/[^\/]+_)(\d+)((?:_v\d+)?\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?/i)) ) {
  119. if(m[2]<1280) {
  120. var ajax = new XMLHttpRequest();
  121. ajax.onreadystatechange=function() {
  122. if(ajax.status==200) {
  123. document.location = m[1] + "1280" + m[3];
  124. }
  125. };
  126. ajax.open("HEAD", m[1]+"1280"+m[3], true);
  127. ajax.send();
  128. }
  129. }
  130. else if( (m = url.match(/^(https?:\/\/).+(\.tumblr\.com\/.+_)(\w+)((?:_v\d+)?\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?/i)) ) {
  131. if(m[3]!="raw" ){
  132. var urlraw = m[1] + "media" + m[2] + "raw" + m[4];
  133. //document.location = urlraw;
  134. var ajax = new XMLHttpRequest();
  135. ajax.onreadystatechange=function() {
  136. if(ajax.status==200)
  137. document.location = urlraw;
  138. };
  139. ajax.open("HEAD", urlraw, true);
  140. ajax.send();
  141. }
  142. }
  143.  
  144. //twitter
  145. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/(?:[^\/:]+\.(?:jpg|jpeg|gif|png|bmp|webp)))(:\w+)?(?:\?.+)?$/i)) ) {
  146. if ( m[2]===null || m[2] != ":orig" )
  147. document.location = m[1] + ":orig";
  148. }
  149.  
  150. //Steam (Only user content)
  151. else if( (m = url.match(/^(https?:\/\/(images\.akamai\.steamusercontent\.com|steamuserimages-a\.akamaihd\.net)\/[^\?]+)\?.+$/i)) ){
  152. document.location = m[1];
  153. }
  154.  
  155. //性浪微博
  156. else if( (m = url.match(/^(https?:\/\/(?:ww|wx)\d+\.sinaimg\.cn\/)([a-zA-Z]\w+)(\/.+)(?:\?.+)?$/i)) ) {
  157. if(m[2] != "large") {
  158. document.location = m[1] + "large" + m[3];
  159. }
  160. }
  161.  
  162. //zhihu
  163. else if( (m = url.match(/^(https?:\/\/.+\.zhimg\.com\/[\w\-]+_)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  164. if(m[2]!="r") {
  165. document.location = m[1] + "r" + m[3];
  166. }
  167. }
  168.  
  169. //douban
  170. else if( (m = url.match(/^(https?:\/\/\w+\.douban(?:io)?\.com\/view\/(?:photo|commodity_story)\/)(\w+)(\/public\/.+\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  171. if(m[2] != "raw"){
  172. var ajax = new XMLHttpRequest();
  173. ajax.onreadystatechange=function() {
  174. if(ajax.status==200) {
  175. document.location = m[1] + "raw" + m[3];
  176. }else if(ajax.status==404) {
  177. if(m[2] != "photo"){
  178. document.location = m[1] + "photo" + m[3];
  179. }
  180. }
  181. };
  182. ajax.open("GET", m[1]+"raw"+m[3], true);
  183. ajax.send();
  184. }
  185. }
  186.  
  187. //artstation
  188. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\d{4,}\/)(\w+)(\/[^\/]+)$/i)) ){
  189. if(m[3] != "original"){
  190. var ajax = new XMLHttpRequest();
  191. ajax.onreadystatechange=function() {
  192. if(ajax.status==200) {
  193. document.location = m[1] + "original" + m[4];
  194. }else if(ajax.status==404) {
  195. if(m[3] != "large"){
  196. document.location = m[1] + "large" + m[4];
  197. }
  198. }
  199. };
  200. ajax.open("HEAD", m[1]+"original"+m[3], true);
  201. ajax.send();
  202. }
  203. }
  204. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\w+)(\/[^\/]+)$/i)) ){
  205. //if(m[2] != "original") {
  206. // document.location = m[1] + "original" + m[3];
  207. //}
  208. if(m[2] != "original"){
  209. var ajax = new XMLHttpRequest();
  210. ajax.onreadystatechange=function() {
  211. if(ajax.status==200) {
  212. document.location = m[1] + "original" + m[3];
  213. }else if(ajax.status==404) {
  214. if(m[2] != "large"){
  215. document.location = m[1] + "large" + m[3];
  216. }
  217. }
  218. };
  219. ajax.open("HEAD", m[1]+"original"+m[3], true);
  220. ajax.send();
  221. }
  222. }
  223.  
  224. //pinimg
  225. else if( (m = url.match(/^(https?:\/\/s-media[\w-]+\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){
  226. if(m[2] != "originals") {
  227. document.location = m[1] + "originals" + m[3];
  228. }
  229. }
  230.  
  231. //bilibili
  232. else if( (m = url.match(/^(https?:\/\/\w+\.hdslb\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))(@|_).+$/i)) ) {
  233. document.location = m[1];
  234. }
  235.  
  236. //百度贴吧(然而对于画质提升什么的并没有什么卵用...)
  237. else if( !(m = url.match(/^https?:\/\/imgsrc\.baidu\.com\/forum\/pic\/item\/.+/i)) ){
  238. if( (m = url.match(/^(https?):\/\/(?:imgsrc|imgsa|\w+\.hiphotos)\.(?:bdimg|baidu)\.com\/(?:forum|album)\/.+\/(\w+\.(?:jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  239. document.location = m[1] + "://imgsrc.baidu.com/forum/pic/item/" + m[2];
  240. }
  241. }