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

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