Resize Image On "Open image in new tab"

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

当前为 2017-04-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Resize Image On "Open image in new tab"
  3. // @name:zh-cn 右键在新标签中打开图片时显示最优化图像质量
  4. // @version 0.5.20
  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. // @exclude http://webcache.googleusercontent.com/*
  53. // @exclude https://webcache.googleusercontent.com/*
  54. // @namespace https://greasyfork.org/users/2646
  55. // @contributionURL http://clso.tk/donate/
  56. // @contributionAmount 6.66
  57. // @copyright 2014-2017, CLE
  58. // ==/UserScript==
  59.  
  60. var url = document.location.toString();
  61. var m = null;
  62.  
  63. //google
  64. if( (m = url.match(/^(https?:\/\/\w+\.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?:\/\/\w+\.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\/vi\/[^\/]+\/)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(\?.+)?$/i)) ) {
  89. if(m[2] != "maxresdefault") {
  90. var ajax = new XMLHttpRequest();
  91. ajax.onreadystatechange=function() {
  92. if(ajax.status==200) {
  93. document.location = m[1] + "maxresdefault" + m[3];
  94. }else if(ajax.status==404) {
  95. if(m[5] || m[2] === "mqdefault")
  96. document.location = m[1] + "hqdefault" + m[3]; //need test
  97. }
  98. };
  99. ajax.open("HEAD", m[1] + "maxresdefault" + m[3], true);
  100. ajax.send();
  101. }
  102. }
  103.  
  104. //tumblr
  105. else if( (m = url.match(/^(https?:\/\/.+\.tumblr\.com\/.+_)(\d+)((?:_v\d+)?\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?/i)) ) {
  106. if(m[2]<1280) {
  107. var ajax = new XMLHttpRequest();
  108. ajax.onreadystatechange=function() {
  109. if(ajax.status==200) {
  110. document.location = m[1] + "1280" + m[3];
  111. }
  112. };
  113. ajax.open("HEAD", m[1]+"1280"+m[3], true);
  114. ajax.send();
  115. }
  116. }
  117.  
  118. //twitter
  119. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/(?:[^\/:]+\.(?:jpg|jpeg|gif|png|bmp|webp)))(:\w+)?(?:\?.+)?$/i)) ) {
  120. if ( m[2]===null || m[2] != ":orig" )
  121. document.location = m[1] + ":orig";
  122. }
  123.  
  124. //Steam (Only user content)
  125. else if( (m = url.match(/^(https?:\/\/(images\.akamai\.steamusercontent\.com|steamuserimages-a\.akamaihd\.net)\/[^\?]+)\?.+$/i)) ){
  126. document.location = m[1];
  127. }
  128.  
  129. //性浪微博
  130. else if( (m = url.match(/^(https?:\/\/(?:ww|wx)\d+\.sinaimg\.cn\/)([a-zA-Z]\w+)(\/.+)(?:\?.+)?$/i)) ) {
  131. if(m[2] != "large") {
  132. document.location = m[1] + "large" + m[3];
  133. }
  134. }
  135.  
  136. //zhihu
  137. else if( (m = url.match(/^(https?:\/\/.+\.zhimg\.com\/[\w\-]+_)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  138. if(m[2]!="r") {
  139. document.location = m[1] + "r" + m[3];
  140. }
  141. }
  142.  
  143. //douban
  144. else if( (m = url.match(/^(https?:\/\/\w+\.douban(?:io)?\.com\/view\/(?:photo|commodity_story)\/)(\w+)(\/public\/.+\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  145. if(m[2] != "raw"){
  146. var ajax = new XMLHttpRequest();
  147. ajax.onreadystatechange=function() {
  148. if(ajax.status==200) {
  149. document.location = m[1] + "raw" + m[3];
  150. }else if(ajax.status==404) {
  151. if(m[2] != "photo"){
  152. document.location = m[1] + "photo" + m[3];
  153. }
  154. }
  155. };
  156. ajax.open("GET", m[1]+"raw"+m[3], true);
  157. ajax.send();
  158. }
  159. }
  160.  
  161. //artstation
  162. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\d{4,}\/)(\w+)(\/[^\/]+)$/i)) ){
  163. if(m[3] != "original"){
  164. var ajax = new XMLHttpRequest();
  165. ajax.onreadystatechange=function() {
  166. if(ajax.status==200) {
  167. document.location = m[1] + "original" + m[4];
  168. }else if(ajax.status==404) {
  169. if(m[3] != "large"){
  170. document.location = m[1] + "large" + m[4];
  171. }
  172. }
  173. };
  174. ajax.open("HEAD", m[1]+"original"+m[3], true);
  175. ajax.send();
  176. }
  177. }
  178. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\w+)(\/[^\/]+)$/i)) ){
  179. //if(m[2] != "original") {
  180. // document.location = m[1] + "original" + m[3];
  181. //}
  182. if(m[2] != "original"){
  183. var ajax = new XMLHttpRequest();
  184. ajax.onreadystatechange=function() {
  185. if(ajax.status==200) {
  186. document.location = m[1] + "original" + m[3];
  187. }else if(ajax.status==404) {
  188. if(m[2] != "large"){
  189. document.location = m[1] + "large" + m[3];
  190. }
  191. }
  192. };
  193. ajax.open("HEAD", m[1]+"original"+m[3], true);
  194. ajax.send();
  195. }
  196. }
  197.  
  198. //pinimg
  199. else if( (m = url.match(/^(https?:\/\/s-media[\w-]+\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){
  200. if(m[2] != "originals") {
  201. document.location = m[1] + "originals" + m[3];
  202. }
  203. }
  204.  
  205. //bilibili
  206. else if( (m = url.match(/^(https?:\/\/\w+\.hdslb\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))(@|_).+$/i)) ) {
  207. document.location = m[1];
  208. }
  209.  
  210. //百度贴吧(然而对于画质提升什么的并没有什么卵用...)
  211. else if( !(m = url.match(/^https?:\/\/imgsrc\.baidu\.com\/forum\/pic\/item\/.+/i)) ){
  212. if( (m = url.match(/^(https?):\/\/(?:imgsrc|imgsa|\w+\.hiphotos)\.(?:bdimg|baidu)\.com\/(?:forum|album)\/.+\/(\w+\.(?:jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  213. document.location = m[1] + "://imgsrc.baidu.com/forum/pic/item/" + m[2];
  214. }
  215. }