Resize Image On "Open image in new tab"

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

当前为 2017-03-16 提交的版本,查看 最新版本

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