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

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