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

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

当前为 2018-04-21 提交的版本,查看 最新版本

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