Resize Image On "Open image in new tab"

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

2017-11-01 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

  1. // ==UserScript==
  2. // @name Resize Image On "Open image in new tab"
  3. // @name:zh-cn 右键在新标签中打开图片时显示最优化图像质量
  4. // @version 0.5.28
  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://*.sinaimg.com/*
  19. // @match https://*.sinaimg.com/*
  20. // @match http://*.twimg.com/*
  21. // @match https://*.twimg.com/*
  22. // @match http://*.zhimg.com/*
  23. // @match https://*.zhimg.com/*
  24. // @match http://*.douban.com/view/*
  25. // @match https://*.douban.com/view/*
  26. // @match http://*.doubanio.com/view/*
  27. // @match https://*.doubanio.com/view/*
  28. // @match http://imgsrc.baidu.com/*
  29. // @match https://imgsrc.baidu.com/*
  30. // @match http://imgsrc.bdimg.com/*
  31. // @match https://imgsrc.bdimg.com/*
  32. // @match http://*.hiphotos.baidu.com/*
  33. // @match https://*.hiphotos.baidu.com/*
  34. // @match http://*.hiphotos.bdimg.com/*
  35. // @match https://*.hiphotos.bdimg.com/*
  36. // @match http://imgsa.baidu.com/*
  37. // @match https://imgsa.baidu.com/*
  38. // @match http://imgsa.bdimg.com/*
  39. // @match https://imgsa.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. // @namespace https://greasyfork.org/users/2646
  55. // @contributionURL http://clso.tk/donate/
  56. // @contributionAmount 6.66
  57. // @copyright 2014-2017, 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?:\/\/i\.ytimg.com\/vi\/[^\/]+\/)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(\?.+)?$/i)) ) {
  128. if(m[2] != "maxresdefault") {
  129. var ajax = new XMLHttpRequest();
  130. ajax.onreadystatechange=function() {
  131. if(ajax.status==200) {
  132. document.location = m[1] + "maxresdefault" + m[3];
  133. }else if(ajax.status==404) {
  134. if(m[5] || m[2] === "mqdefault")
  135. document.location = m[1] + "hqdefault" + m[3];
  136. }
  137. };
  138. ajax.open("HEAD", m[1] + "maxresdefault" + m[3], true);
  139. ajax.send();
  140. }
  141. }
  142. else if( (m = url.match(/^(https?:\/\/\w+\.ggpht\.com\/.+)=(?:[s|w|h])(\d+)(.+)?$/i)) ) {
  143. if( m[2]!="0" ){
  144. document.location = m[1] + "=s0";
  145. }
  146. }
  147.  
  148. //tumblr
  149. else if( (m = url.match(/^(https?:\/\/.+\.tumblr\.com\/[^\/]+_)(\d+)((?:_v\d+)?\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?/i)) ) {
  150. if(m[2]<1280) {
  151. var ajax = new XMLHttpRequest();
  152. ajax.onreadystatechange=function() {
  153. if(ajax.status==200) {
  154. document.location = m[1] + "1280" + m[3];
  155. }
  156. };
  157. ajax.open("HEAD", m[1]+"1280"+m[3], true);
  158. ajax.send();
  159. }
  160. }
  161. else if( (m = url.match(/^(https?):\/\/.+\.tumblr\.com\/(.+_)(\w+)((?:_v\d+)?\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?/i)) ) {
  162. if(m[3]!="raw" ){
  163. // NEED TEST
  164. //var urlraw = "http://data.tumblr.com/" + m[2] + "raw" + m[4];
  165. var urlraw = m[1] + "://data.tumblr.com/" + m[2] + "raw" + m[4];
  166. document.location = urlraw;
  167. /*
  168. var ajax = new XMLHttpRequest();
  169. ajax.onreadystatechange=function() {
  170. if(ajax.status==200)
  171. document.location = urlraw;
  172. };
  173. ajax.open("GET", urlraw, true);
  174. ajax.send();
  175. */
  176. }
  177. }
  178.  
  179. //twitter (NEED TEST)
  180. //else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/(?:[^\/:]+\.(?:jpg|jpeg|gif|png|bmp|webp)))(:\w+)?(?:\?.+)?$/i)) ) {
  181. // if ( m[2]===null || m[2] != ":orig" )
  182. // document.location = m[1] + ":orig";
  183. //}
  184. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/media\/[^\/:]+)\.(jpg|jpeg|gif|png|bmp|webp)(:\w+)?$/i)) ) {
  185. var format = m[2]; if(m[2]=="jpeg") format = "jpg";
  186. document.location = m[1] + "?format=" + format + "&name=orig";
  187. }
  188. else if( (m = url.match(/^(https?:\/\/\w+\.twimg\.com\/.+)(\?.+)$/i)) ) {
  189. var pars = getQueryParams(document.location.search);
  190. if(!pars.format || !pars.name) return;
  191. if(pars.name == "orig") return;
  192. document.location = m[1] + "?format=" + pars.format + "&name=orig";
  193. }
  194.  
  195. //Steam (Only user content)
  196. else if( (m = url.match(/^(https?:\/\/(images\.akamai\.steamusercontent\.com|steamuserimages-a\.akamaihd\.net)\/[^\?]+)\?.+$/i)) ){
  197. document.location = m[1];
  198. }
  199.  
  200. //性浪微博
  201. else if( (m = url.match(/^(https?:\/\/(?:(?:ww|wx|ws)\d+|wxt)\.sinaimg\.(?:cn|com)\/)([a-zA-Z]\w+)(\/.+)(?:\?.+)?$/i)) ) {
  202. if(m[2] != "large") {
  203. document.location = m[1] + "large" + m[3];
  204. }
  205. }
  206.  
  207. //zhihu
  208. else if( (m = url.match(/^(https?:\/\/.+\.zhimg\.com\/[\w\-]+_)(\w+)(\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  209. if(m[2]!="r") {
  210. document.location = m[1] + "r" + m[3];
  211. }
  212. }
  213.  
  214. //douban
  215. else if( (m = url.match(/^(https?:\/\/\w+\.douban(?:io)?\.com\/view\/(?:photo|commodity_story)\/)(\w+)(\/public\/.+\.(jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  216. if(m[2] != "raw"){
  217. var ajax = new XMLHttpRequest();
  218. ajax.onreadystatechange=function() {
  219. if(ajax.status==200) {
  220. document.location = m[1] + "raw" + m[3];
  221. }else if(ajax.status==404) {
  222. if(m[2] != "photo"){
  223. document.location = m[1] + "photo" + m[3];
  224. }
  225. }
  226. };
  227. ajax.open("GET", m[1]+"raw"+m[3], true);
  228. ajax.send();
  229. }
  230. }
  231.  
  232. //artstation
  233. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\d{4,}\/)(\w+)(\/[^\/]+)$/i)) ){
  234. if(m[3] != "original"){
  235. var ajax = new XMLHttpRequest();
  236. ajax.onreadystatechange=function() {
  237. if(ajax.status==200) {
  238. document.location = m[1] + "original" + m[4];
  239. }else if(ajax.status==404) {
  240. if(m[3] != "large"){
  241. document.location = m[1] + "large" + m[4];
  242. }
  243. }
  244. };
  245. ajax.open("HEAD", m[1]+"original"+m[3], true);
  246. ajax.send();
  247. }
  248. }
  249. else if( (m = url.match(/^(https?:\/\/cdn\w+\.artstation\.com\/.+\/)(\w+)(\/[^\/]+)$/i)) ){
  250. //if(m[2] != "original") {
  251. // document.location = m[1] + "original" + m[3];
  252. //}
  253. if(m[2] != "original"){
  254. var ajax = new XMLHttpRequest();
  255. ajax.onreadystatechange=function() {
  256. if(ajax.status==200) {
  257. document.location = m[1] + "original" + m[3];
  258. }else if(ajax.status==404) {
  259. if(m[2] != "large"){
  260. document.location = m[1] + "large" + m[3];
  261. }
  262. }
  263. };
  264. ajax.open("HEAD", m[1]+"original"+m[3], true);
  265. ajax.send();
  266. }
  267. }
  268.  
  269. //pinimg
  270. else if( (m = url.match(/^(https?:\/\/i\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){
  271. if(m[2] != "originals") {
  272. document.location = m[1] + "originals" + m[3];
  273. }
  274. }
  275. else if( (m = url.match(/^(https?:\/\/s-media[\w-]+\.pinimg\.com\/)(\w+)(\/.+)$/i)) ){ //need delete?
  276. if(m[2] != "originals") {
  277. document.location = m[1] + "originals" + m[3];
  278. }
  279. }
  280.  
  281. //bilibili
  282. else if( (m = url.match(/^(https?:\/\/\w+\.hdslb\.com\/.+\.(jpg|jpeg|gif|png|bmp|webp))(@|_).+$/i)) ) {
  283. document.location = m[1];
  284. }
  285.  
  286. //百度贴吧(然而对于画质提升什么的并没有什么卵用...)
  287. else if( !(m = url.match(/^https?:\/\/imgsrc\.baidu\.com\/forum\/pic\/item\/.+/i)) ){
  288. if( (m = url.match(/^(https?):\/\/(?:imgsrc|imgsa|\w+\.hiphotos)\.(?:bdimg|baidu)\.com\/(?:forum|album)\/.+\/(\w+\.(?:jpg|jpeg|gif|png|bmp|webp))(?:\?.+)?$/i)) ){
  289. document.location = m[1] + "://imgsrc.baidu.com/forum/pic/item/" + m[2];
  290. }
  291. }