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-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Resize Image On "Open image in new tab"
  3. // @name:zh-cn 右键在新标签中打开图片时显示最优化图像质量
  4. // @version 0.5.22
  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\/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. else if( (m = url.match(/^(https?:\/\/).+(\.tumblr\.com\/.+_)(\w+)((?:_v\d+)?\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?/i)) ) {
  118. if(m[3]!="raw" ){
  119. var urlraw = m[1] + "media" + m[2] + "raw" + m[4];
  120. document.location = urlraw;
  121. /*
  122. var ajax = new XMLHttpRequest();
  123. ajax.onreadystatechange=function() {
  124. if(ajax.status==200)
  125. document.location = urlraw;
  126. };
  127. ajax.open("HEAD", urlraw, true);
  128. ajax.send();
  129. */
  130. }
  131. }
  132.  
  133. //twitter
  134. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/(?:[^\/:]+\.(?:jpg|jpeg|gif|png|bmp|webp)))(:\w+)?(?:\?.+)?$/i)) ) {
  135. if ( m[2]===null || m[2] != ":orig" )
  136. document.location = m[1] + ":orig";
  137. }
  138.  
  139. //Steam (Only user content)
  140. else if( (m = url.match(/^(https?:\/\/(images\.akamai\.steamusercontent\.com|steamuserimages-a\.akamaihd\.net)\/[^\?]+)\?.+$/i)) ){
  141. document.location = m[1];
  142. }
  143.  
  144. //性浪微博
  145. else if( (m = url.match(/^(https?:\/\/(?:ww|wx)\d+\.sinaimg\.cn\/)([a-zA-Z]\w+)(\/.+)(?:\?.+)?$/i)) ) {
  146. if(m[2] != "large") {
  147. document.location = m[1] + "large" + m[3];
  148. }
  149. }
  150.  
  151. //zhihu
  152. else if( (m = url.match(/^(https?:\/\/.+\.zhimg\.com\/[\w\-]+_)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  153. if(m[2]!="r") {
  154. document.location = m[1] + "r" + m[3];
  155. }
  156. }
  157.  
  158. //douban
  159. else if( (m = url.match(/^(https?:\/\/\w+\.douban(?:io)?\.com\/view\/(?:photo|commodity_story)\/)(\w+)(\/public\/.+\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  160. if(m[2] != "raw"){
  161. var ajax = new XMLHttpRequest();
  162. ajax.onreadystatechange=function() {
  163. if(ajax.status==200) {
  164. document.location = m[1] + "raw" + m[3];
  165. }else if(ajax.status==404) {
  166. if(m[2] != "photo"){
  167. document.location = m[1] + "photo" + m[3];
  168. }
  169. }
  170. };
  171. ajax.open("GET", m[1]+"raw"+m[3], true);
  172. ajax.send();
  173. }
  174. }
  175.  
  176. //artstation
  177. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\d{4,}\/)(\w+)(\/[^\/]+)$/i)) ){
  178. if(m[3] != "original"){
  179. var ajax = new XMLHttpRequest();
  180. ajax.onreadystatechange=function() {
  181. if(ajax.status==200) {
  182. document.location = m[1] + "original" + m[4];
  183. }else if(ajax.status==404) {
  184. if(m[3] != "large"){
  185. document.location = m[1] + "large" + m[4];
  186. }
  187. }
  188. };
  189. ajax.open("HEAD", m[1]+"original"+m[3], true);
  190. ajax.send();
  191. }
  192. }
  193. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\w+)(\/[^\/]+)$/i)) ){
  194. //if(m[2] != "original") {
  195. // document.location = m[1] + "original" + m[3];
  196. //}
  197. if(m[2] != "original"){
  198. var ajax = new XMLHttpRequest();
  199. ajax.onreadystatechange=function() {
  200. if(ajax.status==200) {
  201. document.location = m[1] + "original" + m[3];
  202. }else if(ajax.status==404) {
  203. if(m[2] != "large"){
  204. document.location = m[1] + "large" + m[3];
  205. }
  206. }
  207. };
  208. ajax.open("HEAD", m[1]+"original"+m[3], true);
  209. ajax.send();
  210. }
  211. }
  212.  
  213. //pinimg
  214. else if( (m = url.match(/^(https?:\/\/s-media[\w-]+\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){
  215. if(m[2] != "originals") {
  216. document.location = m[1] + "originals" + m[3];
  217. }
  218. }
  219.  
  220. //bilibili
  221. else if( (m = url.match(/^(https?:\/\/\w+\.hdslb\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))(@|_).+$/i)) ) {
  222. document.location = m[1];
  223. }
  224.  
  225. //百度贴吧(然而对于画质提升什么的并没有什么卵用...)
  226. else if( !(m = url.match(/^https?:\/\/imgsrc\.baidu\.com\/forum\/pic\/item\/.+/i)) ){
  227. if( (m = url.match(/^(https?):\/\/(?:imgsrc|imgsa|\w+\.hiphotos)\.(?:bdimg|baidu)\.com\/(?:forum|album)\/.+\/(\w+\.(?:jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  228. document.location = m[1] + "://imgsrc.baidu.com/forum/pic/item/" + m[2];
  229. }
  230. }