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

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

当前为 2018-11-18 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Resize Image On "Open image in new tab"
  3. // @name:zh-CN 右键在新标签中打开图片时显示最优化图像质量
  4. // @version 0.6.4
  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. // @namespace https://greasyfork.org/users/2646
  57. // @contributionURL http://clso.tk/donate/
  58. // @contributionAmount 6.66
  59. // @copyright 2014-2018, 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 disabled raw images now :(
  136. else if( (m = url.match(/^(https?:\/\/\d+\.media\.tumblr\.com\/.*tumblr_\w+_)(\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.  
  149. //twitter
  150. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/[^\/:]+)\.(jpg|jpeg|gif|png|bmp|webp)(:\w+)?$/i)) ) {
  151. var format = m[2]; if(m[2]=="jpeg") format = "jpg";
  152. document.location = m[1] + "?format=" + format + "&name=orig";
  153. }
  154. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/.+)(\?.+)$/i)) ) {
  155. var pars = getQueryParams(document.location.search);
  156. if(!pars.format || !pars.name) return;
  157. if(pars.name == "orig") return;
  158. document.location = m[1] + "?format=" + pars.format + "&name=orig";
  159. }
  160.  
  161. //Steam (Only user content)
  162. else if( (m = url.match(/^(https?:\/\/(images\.akamai\.steamusercontent\.com|steamuserimages-a\.akamaihd\.net)\/[^\?]+)\?.+$/i)) ){
  163. document.location = m[1];
  164. }
  165.  
  166. //性浪微博
  167. else if( (m = url.match(/^(https?:\/\/(?:(?:ww|wx|ws|tvax|tva)\d+|wxt|wt)\.sinaimg\.(?:cn|com)\/)([\w\.]+)(\/.+)(?:\?.+)?$/i)) ) {
  168. if(m[2] != "large") {
  169. document.location = m[1] + "large" + m[3];
  170. }
  171. }
  172.  
  173. //zhihu
  174. else if( (m = url.match(/^(https?:\/\/.+\.zhimg\.com\/)(?:\d+\/)?([\w\-]+_)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  175. if(m[3]!="r") {
  176. document.location = m[1] + m[2] + "r" + m[4];
  177. }
  178. }
  179.  
  180. //douban NEED TEST
  181. else if( (m = url.match(/^(https?:\/\/\w+\.douban(?:io)?\.com\/view\/.+\/)(\w+)(\/public\/.+\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  182. if(m[2] != "r"){
  183. var ajax = new XMLHttpRequest();
  184. ajax.onreadystatechange=function() {
  185. if(ajax.status==200) {
  186. document.location = m[1] + "r" + m[3];
  187. } else if (ajax.status==404){
  188. if(m[2] != "l") document.location = m[1] + "l" + m[3];
  189. }
  190. };
  191. ajax.open("HEAD", m[1] + "r" + m[3], true);
  192. ajax.send();
  193. }
  194. }
  195.  
  196. //artstation
  197. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\d{4,}\/)(\w+)(\/[^\/]+)$/i)) ){
  198. if(m[3] != "original"){
  199. var ajax = new XMLHttpRequest();
  200. ajax.onreadystatechange=function() {
  201. if(ajax.status==200) {
  202. document.location = m[1] + "original" + m[4];
  203. }else if(ajax.status==404) {
  204. if(m[3] != "large"){
  205. document.location = m[1] + "large" + m[4];
  206. }
  207. }
  208. };
  209. ajax.open("HEAD", m[1]+"original"+m[3], true);
  210. ajax.send();
  211. }
  212. }
  213. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\w+)(\/[^\/]+)$/i)) ){
  214. //if(m[2] != "original") {
  215. // document.location = m[1] + "original" + m[3];
  216. //}
  217. if(m[2] != "original"){
  218. var ajax = new XMLHttpRequest();
  219. ajax.onreadystatechange=function() {
  220. if(ajax.status==200) {
  221. document.location = m[1] + "original" + m[3];
  222. }else if(ajax.status==404) {
  223. if(m[2] != "large"){
  224. document.location = m[1] + "large" + m[3];
  225. }
  226. }
  227. };
  228. ajax.open("HEAD", m[1]+"original"+m[3], true);
  229. ajax.send();
  230. }
  231. }
  232.  
  233. //pinimg
  234. else if( (m = url.match(/^(https?:\/\/i\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){
  235. if(m[2] != "originals") {
  236. document.location = m[1] + "originals" + m[3];
  237. }
  238. }
  239. else if( (m = url.match(/^(https?:\/\/s-media[\w-]+\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){ //need delete?
  240. if(m[2] != "originals") {
  241. document.location = m[1] + "originals" + m[3];
  242. }
  243. }
  244.  
  245. //bilibili
  246. else if( (m = url.match(/^(https?:\/\/\w+\.hdslb\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))(@|_).+$/i)) ) {
  247. document.location = m[1];
  248. }
  249.  
  250. //taobao(tmall)
  251. else if( (m = url.match(/^(https?:\/\/(?:img|gma)\.alicdn\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))_.+$/i)) ) {
  252. document.location = m[1];
  253. }
  254.  
  255.  
  256.  
  257. //百度贴吧(然而对于画质提升什么的并没有什么卵用...)
  258. else if( !(m = url.match(/^https?:\/\/imgsrc\.baidu\.com\/forum\/pic\/item\/.+/i)) ){
  259. if( (m = url.match(/^(https?):\/\/(?:imgsrc|imgsa|\w+\.hiphotos)\.(?:bdimg|baidu)\.com\/(?:forum|album)\/.+\/(\w+\.(?:jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  260. document.location = m[1] + "://imgsrc.baidu.com/forum/pic/item/" + m[2];
  261. }
  262. }