右键在新标签中打开图片时显示最优化图像质量

支持:谷歌(G+ blogspot YouTube)、Tumblr、推特、Steam、新浪微博、知乎、豆瓣、百度贴吧、淘宝(天猫)、京东、ArtStation、Pinimg 等

目前为 2022-04-25 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Resize Image On "Open image in new tab"
  3. // @name:zh-CN 右键在新标签中打开图片时显示最优化图像质量
  4. // @version 0.6.5
  5. // @description Support: Google(G+ blogspot YouTube)\Tumblr\Twitter\Steam(Only user content)\ArtStation\Pinimg\Weibo (And more...
  6. // @description:zh-CN 支持:谷歌(G+ blogspot YouTube)、Tumblr、推特、Steam、新浪微博、知乎、豆瓣、百度贴吧、淘宝(天猫)、京东、ArtStation、Pinimg 等
  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://images.akamai.steamusercontent.com/*
  41. // @match https://images.akamai.steamusercontent.com/*
  42. // @match http://steamuserimages-a.akamaihd.net/*
  43. // @match https://steamuserimages-a.akamaihd.net/*
  44. // @match http://*.artstation.com/*
  45. // @match https://*.artstation.com/*
  46. // @match http://i.ytimg.com/*
  47. // @match https://i.ytimg.com/*
  48. // @match http://*.ggpht.com/*
  49. // @match https://*.ggpht.com/*
  50. // @match http://*.pinimg.com/*
  51. // @match https://*.pinimg.com/*
  52. // @match http://*.hdslb.com/*
  53. // @match https://*.hdslb.com/*
  54. // @match http://*.alicdn.com/*
  55. // @match https://*.alicdn.com/*
  56. // @match http://*.360buyimg.com/*
  57. // @match https://*.360buyimg.com/*
  58. // @namespace https://greasyfork.org/users/2646
  59. // @contributionURL https://clso.fun/donate/
  60. // @contributionAmount 6.66
  61. // @copyright https://clso.fun/
  62. // @license MIT
  63. // ==/UserScript==
  64.  
  65. var url = document.location.toString();
  66. var m = null;
  67.  
  68. function getQueryParams(qs) {
  69. //by http://stackoverflow.com/a/1099670
  70. qs = qs.split('+').join(' ');
  71. var params = {},
  72. tokens,
  73. re = /[?&]?([^=]+)=([^&]*)/g;
  74. while ((tokens = re.exec(qs))) {
  75. params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
  76. }
  77. return params;
  78. }
  79.  
  80. //google
  81. if( (m = url.match(/^(https?:\/\/lh\d+\.googleusercontent\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  82. if(m[2] != "s0") {
  83. document.location = m[1] + "s0" + m[3];
  84. }
  85. }
  86. else if( (m = url.match(/^(https?:\/\/lh\d+\.googleusercontent\.com\/.+=)(.+)(?:\?.+)?$/i)) ) {
  87. if(m[2] != "s0") {
  88. document.location = m[1] + "s0";
  89. }
  90. }
  91. else if( (m = url.match(/^(https?:\/\/\w+\.ggpht\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  92. if(m[2] != "s0") {
  93. document.location = m[1] + "s0" + m[3];
  94. }
  95. }
  96.  
  97. //blogspot
  98. else if( (m = url.match(/^(https?:\/\/\w+\.bp\.blogspot\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  99. if(m[2] != "s0") {
  100. document.location = m[1] + "s0" + m[3];
  101. }
  102. }
  103.  
  104. //youtube
  105. else if( (m = url.match(/^https?:\/\/i\.ytimg.com\/an_webp\/([^\/]+)\/\w+\.(jpg|jpeg|gif|png|bmp|webp)(\?.+)?$/i)) ) {
  106. var ajax = new XMLHttpRequest();
  107. ajax.onreadystatechange=function() {
  108. if(ajax.status==200) {
  109. document.location = "https://i.ytimg.com/vi/" + m[1] + "/maxresdefault.jpg";
  110. }else if(ajax.status==404) {
  111. document.location = "https://i.ytimg.com/vi/" + m[1] + "/hqdefault.jpg";
  112. }
  113. };
  114. ajax.open("HEAD", "https://i.ytimg.com/vi/" + m[1] + "/maxresdefault.jpg", true);
  115. ajax.send();
  116. }
  117. else if( (m = url.match(/^(https?:\/\/i\.ytimg.com\/vi\/[^\/]+\/)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(\?.+)?$/i)) ) {
  118. if(m[2] != "maxresdefault") {
  119. var ajax = new XMLHttpRequest();
  120. ajax.onreadystatechange=function() {
  121. if(ajax.status==200) {
  122. document.location = m[1] + "maxresdefault" + m[3];
  123. }else if(ajax.status==404) {
  124. if(m[5] || m[2] === "mqdefault")
  125. document.location = m[1] + "hqdefault" + m[3];
  126. }
  127. };
  128. ajax.open("HEAD", m[1] + "maxresdefault" + m[3], true);
  129. ajax.send();
  130. }
  131. }
  132. else if( (m = url.match(/^(https?:\/\/\w+\.ggpht\.com\/.+)=(?:[s|w|h])(\d+)(.+)?$/i)) ) {
  133. if( m[2]!="0" ){
  134. document.location = m[1] + "=s0";
  135. }
  136. }
  137.  
  138. //tumblr disabled raw images now :(
  139. else if( (m = url.match(/^(https?:\/\/\d+\.media\.tumblr\.com\/.*tumblr_\w+_)(\d+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ) {
  140. if(m[2]<1280) {
  141. var ajax = new XMLHttpRequest();
  142. ajax.onreadystatechange=function() {
  143. if(ajax.status==200) {
  144. document.location = m[1] + "1280" + m[3];
  145. }
  146. };
  147. ajax.open("HEAD", m[1]+"1280"+m[3], true);
  148. ajax.send();
  149. }
  150. }
  151.  
  152. //twitter
  153. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/[^\/:]+)\.(jpg|jpeg|gif|png|bmp|webp)(:\w+)?$/i)) ) {
  154. var format = m[2]; if(m[2]=="jpeg") format = "jpg";
  155. document.location = m[1] + "?format=" + format + "&name=orig";
  156. }
  157. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/.+)(\?.+)$/i)) ) {
  158. var pars = getQueryParams(document.location.search);
  159. if(!pars.format || !pars.name) return;
  160. if(pars.name == "orig") return;
  161. document.location = m[1] + "?format=" + pars.format + "&name=orig";
  162. }
  163.  
  164. //Steam (Only user content)
  165. else if( (m = url.match(/^(https?:\/\/(images\.akamai\.steamusercontent\.com|steamuserimages-a\.akamaihd\.net)\/[^\?]+)\?.+$/i)) ){
  166. document.location = m[1];
  167. }
  168.  
  169. //性浪微博
  170. else if( (m = url.match(/^(https?:\/\/(?:(?:ww|wx|ws|tvax|tva)\d+|wxt|wt)\.sinaimg\.(?:cn|com)\/)([\w\.]+)(\/.+)(?:\?.+)?$/i)) ) {
  171. if(m[2] != "large") {
  172. document.location = m[1] + "large" + m[3];
  173. }
  174. }
  175.  
  176. //zhihu
  177. else if( (m = url.match(/^(https?:\/\/.+\.zhimg\.com\/)(?:\d+\/)?([\w\-]+_)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  178. if(m[3]!="r") {
  179. document.location = m[1] + m[2] + "r" + m[4];
  180. }
  181. }
  182.  
  183. //douban NEED TEST
  184. else if( (m = url.match(/^(https?:\/\/\w+\.douban(?:io)?\.com\/view\/.+\/)(\w+)(\/public\/.+\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  185. if(m[2] != "r"){
  186. var ajax = new XMLHttpRequest();
  187. ajax.onreadystatechange=function() {
  188. if(ajax.status==200) {
  189. document.location = m[1] + "r" + m[3];
  190. } else if (ajax.status==404){
  191. if(m[2] != "l") document.location = m[1] + "l" + m[3];
  192. }
  193. };
  194. ajax.open("HEAD", m[1] + "r" + m[3], true);
  195. ajax.send();
  196. }
  197. }
  198.  
  199. //artstation
  200. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\d{4,}\/)(\w+)(\/[^\/]+)$/i)) ){
  201. if(m[3] != "original"){
  202. var ajax = new XMLHttpRequest();
  203. ajax.onreadystatechange=function() {
  204. if(ajax.status==200) {
  205. document.location = m[1] + "original" + m[4];
  206. }else if(ajax.status==404) {
  207. if(m[3] != "large"){
  208. document.location = m[1] + "large" + m[4];
  209. }
  210. }
  211. };
  212. ajax.open("HEAD", m[1]+"original"+m[3], true);
  213. ajax.send();
  214. }
  215. }
  216. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\w+)(\/[^\/]+)$/i)) ){
  217. //if(m[2] != "original") {
  218. // document.location = m[1] + "original" + m[3];
  219. //}
  220. if(m[2] != "original"){
  221. var ajax = new XMLHttpRequest();
  222. ajax.onreadystatechange=function() {
  223. if(ajax.status==200) {
  224. document.location = m[1] + "original" + m[3];
  225. }else if(ajax.status==404) {
  226. if(m[2] != "large"){
  227. document.location = m[1] + "large" + m[3];
  228. }
  229. }
  230. };
  231. ajax.open("HEAD", m[1]+"original"+m[3], true);
  232. ajax.send();
  233. }
  234. }
  235.  
  236. //pinimg
  237. else if( (m = url.match(/^(https?:\/\/i\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){
  238. if(m[2] != "originals") {
  239. document.location = m[1] + "originals" + m[3];
  240. }
  241. }
  242. else if( (m = url.match(/^(https?:\/\/s-media[\w-]+\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){ //need delete?
  243. if(m[2] != "originals") {
  244. document.location = m[1] + "originals" + m[3];
  245. }
  246. }
  247.  
  248. //bilibili
  249. else if( (m = url.match(/^(https?:\/\/\w+\.hdslb\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))(@|_).+$/i)) ) {
  250. document.location = m[1];
  251. }
  252.  
  253. //taobao(tmall)
  254. else if( (m = url.match(/^(https?:\/\/(?:img|gma)\.alicdn\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))_.+$/i)) ) {
  255. document.location = m[1];
  256. }
  257.  
  258. //jd
  259. else if( (m = url.match(/^(https?:\/\/(?:img\d+)\.360buyimg\.com\/)((?:.+?)\/(?:.+?))(\/(?:.+?))(\!.+)?$/i)) ) {
  260. if( m[2] != "sku/jfs") {
  261. document.location = m[1]+"sku/jfs"+m[3];
  262. }
  263. }
  264.  
  265.  
  266. //百度贴吧(然而对于画质提升什么的并没有什么卵用...)
  267. else if( !(m = url.match(/^https?:\/\/imgsrc\.baidu\.com\/forum\/pic\/item\/.+/i)) ){
  268. if( (m = url.match(/^(https?):\/\/(?:imgsrc|imgsa|\w+\.hiphotos)\.(?:bdimg|baidu)\.com\/(?:forum|album)\/.+\/(\w+\.(?:jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  269. document.location = m[1] + "://imgsrc.baidu.com/forum/pic/item/" + m[2];
  270. }
  271. }