Resize Image On "Open image in new tab" v2

Support: Google(blogspot YouTube)\Tumblr\Twitter\Steam(Only user content)\ArtStation\Pinimg\Weibo\Reddit (And more...

  1. // ==UserScript==
  2. // @name Resize Image On "Open image in new tab" v2
  3. // @name:zh-CN 右键在新标签中打开图片时显示最优化图像质量 v2
  4. // @version 0.6.10
  5. // @description Support: Google(blogspot YouTube)\Tumblr\Twitter\Steam(Only user content)\ArtStation\Pinimg\Weibo\Reddit (And more...
  6. // @description:zh-CN 支持:谷歌(blogspot YouTube)、Tumblr、推特、Steam、新浪微博、知乎、豆瓣、百度贴吧、淘宝(天猫)、ArtStation、Pinimg、Reddit 等
  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. // @exclude https://*.douban.com/view/ark_article_cover/*
  31. // @exclude https://*.doubanio.com/view/ark_article_cover/*
  32. // @match http://imgsrc.baidu.com/*
  33. // @match https://imgsrc.baidu.com/*
  34. // @match http://imgsa.baidu.com/*
  35. // @match https://imgsa.baidu.com/*
  36. // @match http://*.hiphotos.baidu.com/*
  37. // @match https://*.hiphotos.baidu.com/*
  38. // @match http://*.bdimg.com/*
  39. // @match https://*.bdimg.com/*
  40. // @match http://tiebapic.baidu.com/*
  41. // @match https://tiebapic.baidu.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. // @match http://*.alicdn.com/*
  57. // @match https://*.alicdn.com/*
  58. // @match http://*.360buyimg.com/*
  59. // @match https://*.360buyimg.com/*
  60. // @match http://*.riotpixels.net/*
  61. // @match https://*.riotpixels.net/*
  62. // @match https://preview.redd.it/*
  63. // @match https://*.akamaized.net/imagecache/*
  64. // @match https://mmbiz.qpic.cn/*
  65. // @namespace https://greasyfork.org/users/1345275
  66. // @contributionURL https://blog.251.sh/aff-and-donate
  67. // @contributionAmount 2.51
  68. // @copyright https://clso.fun/
  69. // @copyright https://251.sh/
  70. // @license MIT
  71. // ==/UserScript==
  72.  
  73. var url = document.location.toString();
  74. var m = null;
  75.  
  76. function getQueryParams(qs) {
  77. //by http://stackoverflow.com/a/1099670
  78. qs = qs.split('+').join(' ');
  79. var params = {},
  80. tokens,
  81. re = /[?&]?([^=]+)=([^&]*)/g;
  82. while ((tokens = re.exec(qs))) {
  83. params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
  84. }
  85. return params;
  86. }
  87.  
  88. //google
  89. if( (m = url.match(/^(https?:\/\/lh\d+\.googleusercontent\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  90. if(m[2] != "s0") {
  91. document.location = m[1] + "s0" + m[3];
  92. }
  93. }
  94. else if( (m = url.match(/^(https?:\/\/lh\d+\.googleusercontent\.com\/.+=)(.+)(?:\?.+)?$/i)) ) {
  95. if(m[2] != "s0") {
  96. document.location = m[1] + "s0";
  97. }
  98. }
  99. else if( (m = url.match(/^(https?:\/\/\w+\.ggpht\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  100. if(m[2] != "s0") {
  101. document.location = m[1] + "s0" + m[3];
  102. }
  103. }
  104. // 2024-08-04 New YouTube Design
  105. else if( (m = url.match(/^(https?:\/\/yt\d+\.googleusercontent\.com\/.+?=)(w\d+-fcrop64=)(.+)$/i)) ) {
  106. if(m[2] && m[2].includes("w1707-fcrop64")) {
  107. m[2] = "w9999";
  108. document.location = m[1] + m[2];
  109. }
  110. }
  111.  
  112. //blogspot
  113. else if( (m = url.match(/^(https?:\/\/\w+\.bp\.blogspot\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  114. if(m[2] != "s0") {
  115. document.location = m[1] + "s0" + m[3];
  116. }
  117. }
  118.  
  119. //youtube
  120. else if( (m = url.match(/^https?:\/\/i\.ytimg.com\/an_webp\/([^\/]+)\/\w+\.(jpg|jpeg|gif|png|bmp|webp)(\?.+)?$/i)) ) {
  121. var ajax = new XMLHttpRequest();
  122. ajax.onreadystatechange=function() {
  123. if(ajax.status==200) {
  124. document.location = "https://i.ytimg.com/vi/" + m[1] + "/maxresdefault.jpg";
  125. }else if(ajax.status==404) {
  126. document.location = "https://i.ytimg.com/vi/" + m[1] + "/hqdefault.jpg";
  127. }
  128. };
  129. ajax.open("HEAD", "https://i.ytimg.com/vi/" + m[1] + "/maxresdefault.jpg", true);
  130. ajax.send();
  131. }
  132. else if( (m = url.match(/^(https?:\/\/i\.ytimg.com\/vi\/[^\/]+\/)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(\?.+)?$/i)) ) {
  133. if(m[2] != "maxresdefault") {
  134. var ajax = new XMLHttpRequest();
  135. ajax.onreadystatechange=function() {
  136. if(ajax.status==200) {
  137. document.location = m[1] + "maxresdefault" + m[3];
  138. }else if(ajax.status==404) {
  139. if(m[5] || m[2] === "mqdefault")
  140. document.location = m[1] + "hqdefault" + m[3];
  141. }
  142. };
  143. ajax.open("HEAD", m[1] + "maxresdefault" + m[3], true);
  144. ajax.send();
  145. }
  146. }
  147. else if( (m = url.match(/^(https?:\/\/\w+\.ggpht\.com\/.+)=(?:[s|w|h])(\d+)(.+)?$/i)) ) {
  148. if( m[2]!="0" ){
  149. document.location = m[1] + "=s0";
  150. }
  151. }
  152.  
  153. //tumblr
  154. else if( (m = url.match(/^(https?:\/\/\d+\.media\.tumblr\.com\/.*tumblr_\w+_)(\d+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ) {
  155. if(m[2]<1280) {
  156. var ajax = new XMLHttpRequest();
  157. ajax.onreadystatechange=function() {
  158. if(ajax.status==200) {
  159. document.location = m[1] + "1280" + m[3];
  160. }
  161. };
  162. ajax.open("HEAD", m[1]+"1280"+m[3], true);
  163. ajax.send();
  164. }
  165. }
  166.  
  167. //twitter
  168. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/[^\/:]+)\.(jpg|jpeg|gif|png|bmp|webp)(:\w+)?$/i)) ) {
  169. var format = m[2]; if(m[2]=="jpeg") format = "jpg";
  170. document.location = m[1] + "?format=" + format + "&name=orig";
  171. }
  172. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/.+)(\?.+)$/i)) ) {
  173. var pars = getQueryParams(document.location.search);
  174. if(!pars.format || !pars.name) return;
  175. if(pars.name == "orig") return;
  176. document.location = m[1] + "?format=" + pars.format + "&name=orig";
  177. }
  178.  
  179. //Steam (Only user content)
  180. else if( (m = url.match(/^(https?:\/\/(images\.akamai\.steamusercontent\.com|steamuserimages-a\.akamaihd\.net)\/[^\?]+)\?.+$/i)) ){
  181. document.location = m[1];
  182. }
  183.  
  184. //性浪微博
  185. else if( (m = url.match(/^(https?:\/\/(?:(?:ww|wx|ws|tvax|tva)\d+|wxt|wt)\.sinaimg\.(?:cn|com)\/)([\w\.]+)(\/.+)(?:\?.+)?$/i)) ) {
  186. if(m[2] != "large") {
  187. document.location = m[1] + "large" + m[3];
  188. }
  189. }
  190.  
  191. //zhihu
  192. else if( (m = url.match(/^(https?:\/\/.+\.zhimg\.com\/)(?:\d+\/)?([\w\-]+_)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  193. if(m[3]!="r") {
  194. document.location = m[1] + m[2] + "r" + m[4];
  195. }
  196. }
  197.  
  198. //douban NEED TEST
  199. else if( (m = url.match(/^(https?:\/\/\w+\.douban(?:io)?\.com\/view\/.+\/)(\w+)(\/public\/.+\.)(jpg|jpeg|gif|png|bmp|webp)(?:\?.+)?$/i)) ){
  200. if (m[2] != "r" && m[2] != "raw" && m[2] != "r_ratio_poster" && m[2] != "l") {
  201. var FuckDB = function(url){
  202. var ajax = new XMLHttpRequest();
  203. ajax.open("HEAD", url, false);
  204. ajax.send();
  205. if(ajax.status==200){
  206. var imgfsize = Number( ajax.getResponseHeader("Content-Length") );
  207. if(imgfsize > 0) {
  208. document.location = url;
  209. return true;
  210. }
  211. }
  212. return false;
  213. };
  214.  
  215. if( FuckDB(m[1]+"r"+m[3]+m[4]) ){}
  216. else if( FuckDB(m[1]+"raw"+m[3]+m[4]) ){}
  217. else if( FuckDB(m[1]+"r_ratio_poster"+m[3]+m[4]) ){}
  218. else if( FuckDB(m[1]+"l"+m[3]+m[4]) ){}
  219. else if( m[4]=="webp" ){
  220. m[4] = "jpg";
  221. if( FuckDB(m[1]+"r"+m[3]+m[4]) ){}
  222. else if( FuckDB(m[1]+"raw"+m[3]+m[4]) ){}
  223. else if( FuckDB(m[1]+"r_ratio_poster"+m[3]+m[4]) ){}
  224. else if( FuckDB(m[1]+"l"+m[3]+m[4]) ){}
  225. }
  226. }
  227. }
  228.  
  229. //artstation
  230. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\d{4,}\/)(\w+)(\/[^\/]+)$/i)) ){
  231. if(m[3] != "original"){
  232. var ajax = new XMLHttpRequest();
  233. ajax.onreadystatechange=function() {
  234. if(ajax.status==200) {
  235. document.location = m[1] + "original" + m[4];
  236. }else if(ajax.status==404) {
  237. if(m[3] != "large"){
  238. document.location = m[1] + "large" + m[4];
  239. }
  240. }
  241. };
  242. ajax.open("HEAD", m[1]+"original"+m[3], true);
  243. ajax.send();
  244. }
  245. }
  246. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\w+)(\/[^\/]+)$/i)) ){
  247. //if(m[2] != "original") {
  248. // document.location = m[1] + "original" + m[3];
  249. //}
  250. if(m[2] != "original"){
  251. var ajax = new XMLHttpRequest();
  252. ajax.onreadystatechange=function() {
  253. if(ajax.status==200) {
  254. document.location = m[1] + "original" + m[3];
  255. }else if(ajax.status==404) {
  256. if(m[2] != "large"){
  257. document.location = m[1] + "large" + m[3];
  258. }
  259. }
  260. };
  261. ajax.open("HEAD", m[1]+"original"+m[3], true);
  262. ajax.send();
  263. }
  264. }
  265.  
  266. //pinimg
  267. else if( (m = url.match(/^(https?:\/\/i\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){
  268. if(m[2] != "originals") {
  269. document.location = m[1] + "originals" + m[3];
  270. }
  271. }
  272. else if( (m = url.match(/^(https?:\/\/s-media[\w-]+\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){ //need delete?
  273. if(m[2] != "originals") {
  274. document.location = m[1] + "originals" + m[3];
  275. }
  276. }
  277.  
  278. //bilibili
  279. else if( (m = url.match(/^(https?:\/\/\w+\.hdslb\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))(@|_).+$/i)) ) {
  280. document.location = m[1];
  281. }
  282.  
  283. //taobao(tmall)
  284. else if( (m = url.match(/^(https?:\/\/(?:.+?)\.alicdn\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))_.+$/i)) ) {
  285. document.location = m[1];
  286. }
  287.  
  288. //jd
  289. else if( (m = url.match(/^(https?:\/\/(?:img\d+)\.360buyimg\.com\/)((?:.+?)\/(?:.+?))(\/(?:.+?))(\!.+)?$/i)) ) {
  290. if( m[2] != "sku/jfs") {
  291. document.location = m[1]+"sku/jfs"+m[3];
  292. }
  293. }
  294.  
  295. // https://s01.riotpixels.net/data/2a/b2/2ab23684-6cec-41da-9bce-f72c5264353a.jpg.240p.jpg
  296. else if( (m = url.match(/^(https?:\/\/(?:.+?)\.riotpixels\.net\/.+\.(jpg|jpeg|gif|png|bmp|webp))\..+?$/i)) ) {
  297. document.location = m[1];
  298. }
  299.  
  300. // reddit NEED TEST
  301. else if( (m = url.match(/^https?:\/\/preview\.redd\.it\/(.+\.(jpg|jpeg|gif|png|bmp|webp))\?.+?$/i)) ) {
  302. document.location = "https://i.redd.it/"+m[1];
  303. }
  304.  
  305. // akamaized.net/imagecache NEED TEST
  306. else if( (m = url.match(/^(https:\/\/.+\.akamaized\.net\/imagecache\/\d+\/\d+\/\d+\/\d+\/)(\d+)(\/.+)$/i)) ) {
  307. if( m[2] < 1920) document.location = m[1]+"1920"+m[3];
  308. }
  309.  
  310. // 微信公众号 by sbdx
  311. else if((m=url.match(/^(https:\/\/mmbiz\.qpic\.cn\/mmbiz_jpg\/.+?\/)(\d+)(\?wx_fmt=jpeg)/i))) {
  312. if( m[2] != 0) document.location = m[1]+"0"+m[3];
  313. }
  314.  
  315. //百度贴吧(然而对于画质提升什么的并没有什么卵用...)
  316. else if( !(m = url.match(/^https?:\/\/imgsrc\.baidu\.com\/forum\/pic\/item\/.+/i)) ){
  317. if( (m = url.match(/^(https?):\/\/(?:imgsrc|imgsa|\w+\.hiphotos)\.(?:bdimg|baidu)\.com\/(?:forum|album)\/.+\/(\w+\.(?:jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  318. document.location = m[1] + "://imgsrc.baidu.com/forum/pic/item/" + m[2];
  319. }
  320. //if( (m = url.match(/^(https?)(:\/\/(?:imgsrc|imgsa|\w+\.hiphotos|tiebapic)\.(?:bdimg|baidu)\.com\/)(?:forum|album)\/.+\/(\w+\.(?:jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  321. // document.location = m[1] + m[2] + "forum/pic/item/" + m[3];
  322. //}
  323. }