Resize Image On "Open image in new tab"

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

当前为 2017-11-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Resize Image On "Open image in new tab"
  3. // @name:zh-cn 右键在新标签中打开图片时显示最优化图像质量
  4. // @version 0.5.30
  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. // @grant GM_xmlhttpRequest
  9. // @grant GM_download
  10. // @match http://*.googleusercontent.com/*
  11. // @match https://*.googleusercontent.com/*
  12. // @match http://*.media.tumblr.com/*
  13. // @match https://*.media.tumblr.com/*
  14. // @match http://secure.static.tumblr.com/*
  15. // @match https://secure.static.tumblr.com/*
  16. // @match http://*.bp.blogspot.com/*
  17. // @match https://*.bp.blogspot.com/*
  18. // @match http://*.sinaimg.cn/*
  19. // @match https://*.sinaimg.cn/*
  20. // @match http://*.sinaimg.com/*
  21. // @match https://*.sinaimg.com/*
  22. // @match http://*.twimg.com/*
  23. // @match https://*.twimg.com/*
  24. // @match http://*.zhimg.com/*
  25. // @match https://*.zhimg.com/*
  26. // @match http://*.douban.com/view/*
  27. // @match https://*.douban.com/view/*
  28. // @match http://*.doubanio.com/view/*
  29. // @match https://*.doubanio.com/view/*
  30. // @match http://imgsrc.baidu.com/*
  31. // @match https://imgsrc.baidu.com/*
  32. // @match http://imgsrc.bdimg.com/*
  33. // @match https://imgsrc.bdimg.com/*
  34. // @match http://*.hiphotos.baidu.com/*
  35. // @match https://*.hiphotos.baidu.com/*
  36. // @match http://*.hiphotos.bdimg.com/*
  37. // @match https://*.hiphotos.bdimg.com/*
  38. // @match http://imgsa.baidu.com/*
  39. // @match https://imgsa.baidu.com/*
  40. // @match http://imgsa.bdimg.com/*
  41. // @match https://imgsa.bdimg.com/*
  42. // @match http://images.akamai.steamusercontent.com/*
  43. // @match https://images.akamai.steamusercontent.com/*
  44. // @match http://steamuserimages-a.akamaihd.net/*
  45. // @match https://steamuserimages-a.akamaihd.net/*
  46. // @match http://*.artstation.com/*
  47. // @match https://*.artstation.com/*
  48. // @match http://i.ytimg.com/*
  49. // @match https://i.ytimg.com/*
  50. // @match http://*.ggpht.com/*
  51. // @match https://*.ggpht.com/*
  52. // @match http://*.pinimg.com/*
  53. // @match https://*.pinimg.com/*
  54. // @match http://*.hdslb.com/*
  55. // @match https://*.hdslb.com/*
  56. // @namespace https://greasyfork.org/users/2646
  57. // @contributionURL http://clso.tk/donate/
  58. // @contributionAmount 6.66
  59. // @copyright 2014-2017, CLE
  60. // ==/UserScript==
  61.  
  62. var url = document.location.toString();
  63. var m = null;
  64.  
  65. function getQueryParams(qs) {
  66. //by http://stackoverflow.com/a/1099670
  67. qs = qs.split('+').join(' ');
  68. var params = {},
  69. tokens,
  70. re = /[?&]?([^=]+)=([^&]*)/g;
  71. while ((tokens = re.exec(qs))) {
  72. params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
  73. }
  74. return params;
  75. }
  76.  
  77. //google
  78. if( (m = url.match(/^(https?:\/\/lh\d+\.googleusercontent\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  79. if(m[2] != "s0") {
  80. document.location = m[1] + "s0" + m[3];
  81. }
  82. }
  83. else if( (m = url.match(/^(https?:\/\/lh\d+\.googleusercontent\.com\/.+=)(.+)(?:\?.+)?$/i)) ) {
  84. if(m[2] != "s0") {
  85. document.location = m[1] + "s0";
  86. }
  87. }
  88. else if( (m = url.match(/^(https?:\/\/\w+\.ggpht\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  89. if(m[2] != "s0") {
  90. document.location = m[1] + "s0" + m[3];
  91. }
  92. }
  93.  
  94. //blogspot
  95. else if( (m = url.match(/^(https?:\/\/\w+\.bp\.blogspot\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  96. if(m[2] != "s0") {
  97. document.location = m[1] + "s0" + m[3];
  98. }
  99. }
  100.  
  101. //youtube
  102. else if( (m = url.match(/^https?:\/\/i\.ytimg.com\/an_webp\/([^\/]+)\/\w+\.(jpg|jpeg|gif|png|bmp|webp)(\?.+)?$/i)) ) {
  103. var ajax = new XMLHttpRequest();
  104. ajax.onreadystatechange=function() {
  105. if(ajax.status==200) {
  106. document.location = "https://i.ytimg.com/vi/" + m[1] + "/maxresdefault.jpg";
  107. }else if(ajax.status==404) {
  108. document.location = "https://i.ytimg.com/vi/" + m[1] + "/hqdefault.jpg";
  109. }
  110. };
  111. ajax.open("HEAD", "https://i.ytimg.com/vi/" + m[1] + "/maxresdefault.jpg", true);
  112. ajax.send();
  113. }
  114. else if( (m = url.match(/^(https?:\/\/i\.ytimg.com\/vi\/[^\/]+\/)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(\?.+)?$/i)) ) {
  115. if(m[2] != "maxresdefault") {
  116. var ajax = new XMLHttpRequest();
  117. ajax.onreadystatechange=function() {
  118. if(ajax.status==200) {
  119. document.location = m[1] + "maxresdefault" + m[3];
  120. }else if(ajax.status==404) {
  121. if(m[5] || m[2] === "mqdefault")
  122. document.location = m[1] + "hqdefault" + m[3];
  123. }
  124. };
  125. ajax.open("HEAD", m[1] + "maxresdefault" + m[3], true);
  126. ajax.send();
  127. }
  128. }
  129. else if( (m = url.match(/^(https?:\/\/\w+\.ggpht\.com\/.+)=(?:[s|w|h])(\d+)(.+)?$/i)) ) {
  130. if( m[2]!="0" ){
  131. document.location = m[1] + "=s0";
  132. }
  133. }
  134.  
  135. //tumblr
  136. else if( (m = url.match(/^(https?:\/\/.+\.tumblr\.com\/[^\/]+_)(\d+)((?:_v\d+)?\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?/i)) ) {
  137. if(m[2]<1280) {
  138. var ajax = new XMLHttpRequest();
  139. ajax.onreadystatechange=function() {
  140. if(ajax.status==200) {
  141. document.location = m[1] + "1280" + m[3];
  142. }
  143. };
  144. ajax.open("HEAD", m[1]+"1280"+m[3], true);
  145. ajax.send();
  146. }
  147. }
  148. else if( (m = url.match(/^(https?):\/\/.+\.tumblr\.com\/(.+_)(\w+)((?:_v\d+)?\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?/i)) ) {
  149. if(m[3]!="raw" ){
  150. /*
  151. //var urlraw = "http://data.tumblr.com/" + m[2] + "raw" + m[4];
  152. var urlraw = m[1] + "://data.tumblr.com/" + m[2] + "raw" + m[4];
  153. document.location = urlraw;
  154. var ajax = new XMLHttpRequest();
  155. ajax.onreadystatechange=function() {
  156. if(ajax.status==200)
  157. document.location = urlraw;
  158. };
  159. ajax.open("HEAD", urlraw, true);
  160. ajax.send();
  161. */
  162. // NEED TEST (cross-domain request)
  163. var urlraw = "https://s3.amazonaws.com/data.tumblr.com/" + m[2] + "raw" + m[4];
  164. //document.location = urlraw;
  165. GM_xmlhttpRequest({
  166. method: "HEAD",
  167. url: urlraw,
  168. onload: function(res) {
  169. if (res.status == 200) {
  170. document.location = urlraw;
  171. }
  172. }
  173. });
  174. }
  175. }
  176.  
  177. //twitter
  178. //else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/(?:[^\/:]+\.(?:jpg|jpeg|gif|png|bmp|webp)))(:\w+)?(?:\?.+)?$/i)) ) {
  179. // if ( m[2]===null || m[2] != ":orig" )
  180. // document.location = m[1] + ":orig";
  181. //}
  182. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/[^\/:]+)\.(jpg|jpeg|gif|png|bmp|webp)(:\w+)?$/i)) ) {
  183. var format = m[2]; if(m[2]=="jpeg") format = "jpg";
  184. document.location = m[1] + "?format=" + format + "&name=orig";
  185. }
  186. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/.+)(\?.+)$/i)) ) {
  187. var pars = getQueryParams(document.location.search);
  188. if(!pars.format || !pars.name) return;
  189. if(pars.name == "orig") return;
  190. document.location = m[1] + "?format=" + pars.format + "&name=orig";
  191. }
  192.  
  193. //Steam (Only user content)
  194. else if( (m = url.match(/^(https?:\/\/(images\.akamai\.steamusercontent\.com|steamuserimages-a\.akamaihd\.net)\/[^\?]+)\?.+$/i)) ){
  195. document.location = m[1];
  196. }
  197.  
  198. //性浪微博
  199. else if( (m = url.match(/^(https?:\/\/(?:(?:ww|wx|ws|tvax|tva)\d+|wxt)\.sinaimg\.(?:cn|com)\/)([\w\.]+)(\/.+)(?:\?.+)?$/i)) ) {
  200. if(m[2] != "large") {
  201. document.location = m[1] + "large" + m[3];
  202. }
  203. }
  204.  
  205. //zhihu
  206. else if( (m = url.match(/^(https?:\/\/.+\.zhimg\.com\/[\w\-]+_)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  207. if(m[2]!="r") {
  208. document.location = m[1] + "r" + m[3];
  209. }
  210. }
  211.  
  212. //douban
  213. else if( (m = url.match(/^(https?:\/\/\w+\.douban(?:io)?\.com\/view\/(?:photo|commodity_story)\/)(\w+)(\/public\/.+\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  214. if(m[2] != "raw"){
  215. var ajax = new XMLHttpRequest();
  216. ajax.onreadystatechange=function() {
  217. if(ajax.status==200) {
  218. document.location = m[1] + "raw" + m[3];
  219. }else if(ajax.status==404) {
  220. if(m[2] != "photo"){
  221. document.location = m[1] + "photo" + m[3];
  222. }
  223. }
  224. };
  225. ajax.open("HEAD", m[1]+"raw"+m[3], true);
  226. ajax.send();
  227. }
  228. }
  229.  
  230. //artstation
  231. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\d{4,}\/)(\w+)(\/[^\/]+)$/i)) ){
  232. if(m[3] != "original"){
  233. var ajax = new XMLHttpRequest();
  234. ajax.onreadystatechange=function() {
  235. if(ajax.status==200) {
  236. document.location = m[1] + "original" + m[4];
  237. }else if(ajax.status==404) {
  238. if(m[3] != "large"){
  239. document.location = m[1] + "large" + m[4];
  240. }
  241. }
  242. };
  243. ajax.open("HEAD", m[1]+"original"+m[3], true);
  244. ajax.send();
  245. }
  246. }
  247. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\w+)(\/[^\/]+)$/i)) ){
  248. //if(m[2] != "original") {
  249. // document.location = m[1] + "original" + m[3];
  250. //}
  251. if(m[2] != "original"){
  252. var ajax = new XMLHttpRequest();
  253. ajax.onreadystatechange=function() {
  254. if(ajax.status==200) {
  255. document.location = m[1] + "original" + m[3];
  256. }else if(ajax.status==404) {
  257. if(m[2] != "large"){
  258. document.location = m[1] + "large" + m[3];
  259. }
  260. }
  261. };
  262. ajax.open("HEAD", m[1]+"original"+m[3], true);
  263. ajax.send();
  264. }
  265. }
  266.  
  267. //pinimg
  268. else if( (m = url.match(/^(https?:\/\/i\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){
  269. if(m[2] != "originals") {
  270. document.location = m[1] + "originals" + m[3];
  271. }
  272. }
  273. else if( (m = url.match(/^(https?:\/\/s-media[\w-]+\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){ //need delete?
  274. if(m[2] != "originals") {
  275. document.location = m[1] + "originals" + m[3];
  276. }
  277. }
  278.  
  279. //bilibili
  280. else if( (m = url.match(/^(https?:\/\/\w+\.hdslb\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))(@|_).+$/i)) ) {
  281. document.location = m[1];
  282. }
  283.  
  284. //百度贴吧(然而对于画质提升什么的并没有什么卵用...)
  285. else if( !(m = url.match(/^https?:\/\/imgsrc\.baidu\.com\/forum\/pic\/item\/.+/i)) ){
  286. if( (m = url.match(/^(https?):\/\/(?:imgsrc|imgsa|\w+\.hiphotos)\.(?:bdimg|baidu)\.com\/(?:forum|album)\/.+\/(\w+\.(?:jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  287. document.location = m[1] + "://imgsrc.baidu.com/forum/pic/item/" + m[2];
  288. }
  289. }