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