Resize Image On "Open image in new tab"

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

目前為 2023-02-12 提交的版本,檢視 最新版本

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