Resize Image On "Open image in new tab"

Support: Google(G+ blogspot YouTube)\Tumblr\Twitter\Steam(Only user content)\weibo.com (And more...

נכון ליום 19-02-2017. ראה הגרסה האחרונה.

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