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

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

目前为 2016-12-22 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Resize Image On "Open image in new tab"
  3. // @name:zh-cn 右键在新标签中打开图片时显示最优化图像质量
  4. // @version 0.5.13
  5. // @description Support: Google(G+ blogspot YouTube)\Tumblr\Twitter\Steam(Only user content)\weibo.com (And more...
  6. // @description:zh-cn 支持:谷歌(G+ blogspot YouTube)、Tumblr、推特、Steam、新浪微博、知乎、豆瓣、百度贴吧
  7. // @run-at document-start
  8. // @match http://*.googleusercontent.com/*
  9. // @match https://*.googleusercontent.com/*
  10. // @match http://*.media.tumblr.com/*
  11. // @match https://*.media.tumblr.com/*
  12. // @match http://*.bp.blogspot.com/*
  13. // @match https://*.bp.blogspot.com/*
  14. // @match http://*.sinaimg.cn/*
  15. // @match https://*.sinaimg.cn/*
  16. // @match http://*.qpic.cn/*
  17. // @match http://*.twimg.com/*
  18. // @match https://*.twimg.com/*
  19. // @match http://*.zhimg.com/*
  20. // @match https://*.zhimg.com/*
  21. // @match http://*.douban.com/view/*
  22. // @match https://*.douban.com/view/*
  23. // @match http://*.doubanio.com/view/*
  24. // @match https://*.doubanio.com/view/*
  25. // @match http://imgsrc.baidu.com/*
  26. // @match http://imgsrc.bdimg.com/*
  27. // @match http://*.hiphotos.baidu.com/*
  28. // @match http://*.hiphotos.bdimg.com/*
  29. // @match http://images.akamai.steamusercontent.com/*
  30. // @match http://*.artstation.com/*
  31. // @match https://*.artstation.com/*
  32. // @match http://i.ytimg.com/*
  33. // @match https://i.ytimg.com/*
  34. // @match http://*.ggpht.com/*
  35. // @match https://*.ggpht.com/*
  36. // @match http://*.pinimg.com/*
  37. // @match https://*.pinimg.com/*
  38. // @exclude http://webcache.googleusercontent.com/*
  39. // @exclude https://webcache.googleusercontent.com/*
  40. // @namespace https://greasyfork.org/users/2646
  41. // @copyright 2016+, CLE
  42. // ==/UserScript==
  43.  
  44. var url = document.location.toString();
  45. var m = null;
  46.  
  47. //google
  48. if( (m = url.match(/^(https?:\/\/\w+\.googleusercontent\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  49. if(m[2] != "s0") {
  50. document.location = m[1] + "s0" + m[3];
  51. }
  52. }
  53. else if( (m = url.match(/^(https?:\/\/\w+\.googleusercontent\.com\/.+=)(.+)(?:\?.+)?$/i)) ) {
  54. if(m[2] != "s0") {
  55. document.location = m[1] + "s0";
  56. }
  57. }
  58. else if( (m = url.match(/^(https?:\/\/\w+\.ggpht\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  59. if(m[2] != "s0") {
  60. document.location = m[1] + "s0" + m[3];
  61. }
  62. }
  63.  
  64. //blogspot
  65. else if( (m = url.match(/^(https?:\/\/\w+\.bp\.blogspot\.com\/.+\/)([^\/]+)(\/[^\/]+(\.(jpg|jpeg|gif|png|bmp|webp))?)(?:\?.+)?$/i)) ) {
  66. if(m[2] != "s0") {
  67. document.location = m[1] + "s0" + m[3];
  68. }
  69. }
  70.  
  71. //youtube
  72. else if( (m = url.match(/^(https?:\/\/i\.ytimg.com\/vi\/[^\/]+\/)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(\?.+)?$/i)) ) {
  73. if(m[2] != "maxresdefault") {
  74. var ajax = new XMLHttpRequest();
  75. ajax.onreadystatechange=function() {
  76. if(ajax.status==200) {
  77. document.location = m[1] + "maxresdefault" + m[3];
  78. }else if(ajax.status==404) {
  79. if(m[5] || m[2] === "mqdefault")
  80. document.location = m[1] + "hqdefault" + m[3]; //need test
  81. }
  82. };
  83. ajax.open("HEAD", m[1] + "maxresdefault" + m[3], true);
  84. ajax.send();
  85. }
  86. }
  87.  
  88. //tumblr
  89. else if( (m = url.match(/^(https?:\/\/\d+\.media\.tumblr\.com\/.*tumblr_\w+_)(\d+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ) {
  90. if(m[2]<1280) {
  91. var ajax = new XMLHttpRequest();
  92. ajax.onreadystatechange=function() {
  93. if(ajax.status==200) {
  94. document.location = m[1] + "1280" + m[3];
  95. }
  96. };
  97. ajax.open("HEAD", m[1]+"1280"+m[3], true);
  98. ajax.send();
  99. }
  100. }
  101.  
  102. //twitter
  103. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/(?:[^\/:]+\.(?:jpg|jpeg|gif|png|bmp|webp)))(:\w+)?(?:\?.+)?$/i)) ) {
  104. if ( m[2]===null || m[2] != ":orig" )
  105. document.location = m[1] + ":orig";
  106. }
  107.  
  108. //Steam (Only user content)
  109. else if( (m = url.match(/^(http:\/\/images\.akamai\.steamusercontent\.com\/[^\?]+)\?.+$/i)) ){
  110. document.location = m[1];
  111. }
  112.  
  113. //性浪微博
  114. else if( (m = url.match(/^(https?:\/\/(?:ww|wx)\d+\.sinaimg\.cn\/)([a-zA-Z]\w+)(\/.+)(?:\?.+)?$/i)) ) {
  115. if(m[2] != "large") {
  116. document.location = m[1] + "large" + m[3];
  117. }
  118. }
  119.  
  120. //疼逊微博
  121. //注意:腾讯服务器会经常性自动跳转到t100错误服务器,致使本条自动跳转规则失效
  122. //如果您的浏览器经常性出现错误提示,请删除或屏蔽此条规则,等我找到更好的方法跳转之后再更新
  123. //SB腾讯!
  124. else if( (m = url.match(/^(http:\/\/[\w\d]+\.qpic\.cn\/.+\/)(\d+)(?:\?.+)?$/i)) ) {
  125. if(m[2]<2000) {
  126. top.location=m[1] + "2000";
  127. }
  128. /*if(m[2]!=0) {
  129. document.location = m[1] + "0";
  130. }*/
  131. }
  132. /* 测试代码,依然无效...
  133. else if( (m = url.match(/^http:\/\/t(\d+)\.qpic\.cn\/(mblogpic\/\w+\/)(\d+)$/i)) ) {
  134. if(m[1]==100){
  135. document.location = "http://t1.qpic.cn/" + m[2] + "2000";
  136. }else if(m[3]<2000){
  137. document.location = "http://t"+m[1]+".qpic.cn/" + m[2] + "2000";
  138. }
  139. }*/
  140.  
  141. //zhihu
  142. else if( (m = url.match(/^(https?:\/\/.+\.zhimg\.com\/[\w\-]+_)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  143. if(m[2]!="r") {
  144. document.location = m[1] + "r" + m[3];
  145. }
  146. }
  147.  
  148. //douban
  149. else if( (m = url.match(/^(https?:\/\/\w+\.douban(?:io)?\.com\/view\/(?:photo|commodity_story)\/)(\w+)(\/public\/.+\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  150. if(m[2] != "raw"){
  151. var ajax = new XMLHttpRequest();
  152. ajax.onreadystatechange=function() {
  153. if(ajax.status==200) {
  154. document.location = m[1] + "raw" + m[3];
  155. }else if(ajax.status==404) {
  156. if(m[2] != "photo"){
  157. document.location = m[1] + "photo" + m[3];
  158. }
  159. }
  160. };
  161. ajax.open("GET", m[1]+"raw"+m[3], true);
  162. ajax.send();
  163. }
  164. }
  165.  
  166. //artstation
  167. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\w+)(\/[^\/]+)$/i)) ){
  168. if(m[2] != "original") {
  169. document.location = m[1] + "original" + m[3];
  170. }
  171. }
  172.  
  173. //pinimg
  174. else if( (m = url.match(/^(https?:\/\/s-media[\w-]+\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){
  175. if(m[2] != "originals") {
  176. document.location = m[1] + "originals" + m[3];
  177. }
  178. }
  179.  
  180. //百度贴吧(然而对于画质提升什么的并没有什么卵用...)
  181. else if( !(m = url.match(/^http:\/\/imgsrc\.baidu\.com\/forum\/pic\/item\/.+/i)) ){
  182. if( (m = url.match(/^http:\/\/(?:imgsrc|\w+\.hiphotos)\.(?:bdimg|baidu)\.com\/(?:forum|album)\/.+\/(\w+\.(?:jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  183. document.location = "http://imgsrc.baidu.com/forum/pic/item/" + m[1];
  184. }
  185. }