Pixiv Lazy plus

provide a direct link to original image ([s] link).

当前为 2014-10-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pixiv Lazy plus
  3. // @namespace pixivlazyplus
  4. // @description provide a direct link to original image ([s] link).
  5. // @version 0.8.6
  6. // @include http://www.pixiv.net/*
  7. // ==/UserScript==
  8. // version 0.8.6 - fix modifying big manga URL in manga page
  9. // version 0.8.5 - fix preloading new manga URL format
  10. // version 0.8.4 - fix detecting URL new format
  11. // version 0.8.3 - fix detecting URL new format
  12. // version 0.8.2 - fix detecting URL new format
  13. // version 0.8.1 - fix detecting ugoira in prev/next
  14. // version 0.8.0 - add ability for downloading ugoira as zip
  15. // version 0.7.9 - fix for no profile image
  16. // version 0.7.8 - fix for spapi return value changes
  17. // version 0.7.7 - change [s] to [M](go directly to manga page) for manga links
  18. // version 0.7.6 - fix prev/next [s] link
  19. // version 0.7.5 - fix new manga page
  20. // version 0.7.4 - fix modified images
  21. // version 0.7.3 - fix missing session ID when it is not the end of cookie
  22. // version 0.7.2 - fix comma in tags breaking parsing logic
  23. // version 0.7.1 - fix iPhone API by supplying session ID
  24. // version 0.7 - work with new sample images with iPhone API, fix old manga
  25. // version 0.6.1 - preload manga images
  26. // version 0.6 - change manga mode to big images
  27. // version 0.5 - remove [b] link, add stylish style class
  28. // version 0.4 - updated to filter new thumbnails
  29. // version 0.3 - fix a bug, hat-tip to syosyo
  30. // version 0.2 - updated on 2008-06-25
  31. var pixivlink_run = 0;
  32. var isNewManga = 1;
  33. var postProcImg = new Array();
  34. var preloadImg = new Array();
  35. var sessID = (/PHPSESSID=[^;]*?(?=;|$)/.exec(document.cookie) || "");
  36.  
  37. String.prototype.splitCSV = function(sep) {
  38. for (var foo = this.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) {
  39. if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') {
  40. if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') {
  41. foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"');
  42. } else if (x) {
  43. foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep));
  44. } else foo = foo.shift().split(sep).concat(foo);
  45. } else foo[x].replace(/""/g, '"');
  46. } return foo;
  47. };
  48.  
  49. function GetImageIDFromLink(imageLink) {
  50. var imgID = 0; // If lower 11319936 it means Manga does not have Big version
  51.  
  52. var re = /\d+([_a-z0-9]+)?\.(jpe?g|gif|png)\??.*$|id=[0-9]+$/;
  53. var s = re.exec(imageLink);
  54. if (s && s.length > 0) {
  55. re = /\d+/;
  56. imgID = re.exec(s[0])[0];
  57. }
  58. return imgID;
  59. }
  60.  
  61. function pixivlink() {
  62. //alert(pixivlink_run);
  63. if (!pixivlink_run) pixivlink_run = 1;
  64. else return;
  65. var Items = document.getElementsByTagName('img');
  66. var rexa = /\?mode\=medium\&illust_id|\?mode\=big\&illust_id/;
  67. var rexb = /source.pixiv.net/;
  68. var rexc = /\/img-inf\//;
  69. var rexd = /\/mobile\//;
  70. var rexe = /\/c\//;
  71. for (var i = 0; i < Items.length; i++) {
  72. var imgR = Items[i];
  73. var aR = imgR.parentNode.parentNode;
  74. var aR2 = imgR.parentNode;
  75. if (rexa.test(aR2.href)) {
  76. aR = aR2;
  77. }
  78. if (rexa.test(aR.href)) {
  79. var imgID = GetImageIDFromLink(imgR.src);
  80. var srcR = imgR.src.replace(/_s\.|_m\.|_100\.|_64x64\./i, ".");
  81. // var hrefR = aR.href.replace(/medium/i, "big");
  82. var tdR = aR.parentNode;
  83. /* var linkB = document.createElement('a');
  84. linkB.href = hrefR;
  85. linkB.target = '_blank';
  86. linkB.style.padding = '0 2px';
  87. linkB.className = '_pxlazy';
  88. linkB.appendChild(document.createTextNode('[b]'));
  89. tdR.appendChild(linkB);*/
  90. // tdR.appendChild(document.createTextNode(' '));
  91. if (!rexb.test(srcR)) {
  92. var linkS = document.createElement('a');
  93. linkS.href = srcR;
  94. linkS.target = '_blank';
  95. linkS.className = '_pxlazy _pxlazy_s';
  96. linkS.setAttribute('id', 'ill_' + imgID);
  97. linkS.appendChild(document.createTextNode('[s]'));
  98. tdR.appendChild(linkS);
  99. if (rexc.test(imgR.src)||rexd.test(imgR.src)||rexe.test(imgR.src)) {
  100. //GM_log("postProcImg.push("+imgID+")"+imgR.src);
  101. postProcImg.push(imgID);
  102. }
  103. }
  104. }
  105. }
  106.  
  107. if (postProcImg.length > 0) {
  108. for (var x = 0; x < postProcImg.length; x++) {
  109. GM_xmlhttpRequest({
  110. url: 'http://spapi.pixiv.net/iphone/illust.php?' + sessID + (sessID ? '&' : '') + 'illust_id=' + postProcImg[x],
  111. method: "GET",
  112. headers: {
  113. Referer: "http://www.pixiv.net"
  114. },
  115. onload: function (response) {
  116. if (response.status == 200) {
  117. var rexb = /source.pixiv.net/;
  118. // var rexU = /\/c\//;
  119. var rexU = /_480mw\./;
  120. var rexe = /\/c\//;
  121. var vals = response.responseText.splitCSV();
  122. /*var vtxt = '';
  123. for(var x=0;x < vals.length;x++)
  124. vtxt=vtxt+x+':'+vals[x]+"\n";
  125. GM_log(vtxt);*/
  126. if (vals.length > 0) {
  127. var slnk, imgID, isRestricted;
  128. isRestricted = rexb.test(vals[6]);
  129. isUgoira = !rexU.test(vals[9]);
  130. if (!isRestricted) {
  131. //GM_log("imgID = vals[0]");
  132. imgID = vals[0];
  133. } else {
  134. //GM_log("GetImageIDFromLink("+response.finalUrl+")");
  135. imgID = GetImageIDFromLink(response.finalUrl);
  136. }
  137. slnk = document.getElementById('ill_' + imgID);
  138. if (slnk) {
  139. var goodSlink;
  140. if (vals[19].length > 0) {
  141. goodSlink = 'http://www.pixiv.net/member_illust.php?mode=manga&illust_id=' + imgID;
  142. slnk.innerHTML = '[M]';
  143. } else {
  144. var re = new RegExp('/' + vals[0] + '_.*$');
  145. if (isUgoira) {// grab zip!
  146. //GM_log("isUgoira");
  147. slnk.innerHTML = '[U]';
  148. goodSlink = vals[9].replace(/c\/\d+x\d+\/img-master/, 'img-zip-ugoira').replace(re, '/' + vals[0] + '_ugoira1920x1080.zip');
  149. } else if (rexe.test(vals[9])) {// new 480mw URL
  150. //GM_log("480mw");
  151. goodSlink = vals[9].replace(/c\/480x960\//, '').replace(/img-master/, 'img-original').replace(re, '/' + vals[0] + '_p0.' + vals[2]);
  152. } else if (!isRestricted && !rexe.test(vals[9])) {// use 480mw instead
  153. //GM_log("480mw");
  154. goodSlink = vals[9].replace(/mobile\//, '').replace(re, '/' + vals[0] + '.' + vals[2]);
  155. } else { //salvage from profile image
  156. //GM_log("salvage");
  157. re = /\/[0-9_]+\..*$/;
  158. goodSlink = vals[29].replace(/mobile\//, '').replace(/profile\//, 'img/').replace(re, '/' + imgID + '.' + vals[2]);
  159. }
  160. }
  161. slnk.href = goodSlink;
  162. slnk.title=vals[12];
  163. slnk.className = '_pxlazy _pxlazy_s _pxlazy_s_new';
  164. }
  165. }
  166. }
  167. }
  168. });
  169. }
  170. }
  171.  
  172. var links = document.getElementsByTagName('a');
  173. var tagslink = /tags\.php\?tag=/;
  174. for (var i = 0; i < links.length; i++) {
  175. if (tagslink.test(links[i].href))
  176. links[i].href = links[i].href.replace("tags.php?tag=", "search.php?s_mode=s_tag_full&word=");
  177. }
  178.  
  179. if (unsafeWindow.pixiv && unsafeWindow.pixiv.context.images) {
  180. isNewManga = (GetImageIDFromLink(unsafeWindow.pixiv.context.images[0]/*[0]*/) >= 11319936);
  181. var rexe = /\/c\//;
  182. //GM_log("isNewManga");
  183. for (var x = 0; x < unsafeWindow.pixiv.context.images.length; x++) {
  184. if (isNewManga) {
  185. if(rexe.test(unsafeWindow.pixiv.context.images[x]))
  186. unsafeWindow.pixiv.context.images[x]/*[0]*/ = unsafeWindow.pixiv.context.images[x]/*[0]*/.replace(/c\/1200x1200\//, '').replace(/img-master/, 'img-original').replace(/_p(\d+).*(\.[a-zA-Z\?\d]+)$/, "_p$1$2");
  187. else
  188. unsafeWindow.pixiv.context.images[x]/*[0]*/ = unsafeWindow.pixiv.context.images[x]/*[0]*/.replace(/_p(\d+\.[a-zA-Z\?\d]+)$/, "_big_p$1");
  189. }
  190. preloadImg.push(new Image());
  191. preloadImg[preloadImg.length - 1].src = unsafeWindow.pixiv.context.images[x]/*[0]*/;
  192. }
  193. //setTimeout(mangaFull,250);
  194. mangaFull();
  195. }
  196. }
  197.  
  198. function mangaFull() {
  199. Items = document.getElementsByTagName('img');
  200. var rexe = /\/c\//;
  201. for (var x = 0; x < Items.length; x++) {
  202. var datasrc = Items[x].getAttribute("data-src");
  203. if (datasrc) {
  204. if(rexe.test(datasrc))
  205. datasrc = datasrc.replace(/c\/1200x1200\//, '').replace(/img-master/, 'img-original').replace(/_p(\d+).*(\.[a-zA-Z\?\d]+)$/, "_p$1$2");
  206. else
  207. datasrc = datasrc.replace(/_p(\d+\.[a-zA-Z\?\d]+)$/, "_big_p$1");
  208. }
  209. Items[x].setAttribute("data-src", datasrc);
  210. if (isNewManga) {
  211. if(datasrc)
  212. Items[x].src = datasrc;
  213. else if(rexe.test(Items[x].src))
  214. Items[x].src = Items[x].src.replace(/c\/1200x1200\//, '').replace(/img-master/, 'img-original').replace(/_p(\d+).*(\.[a-zA-Z\?\d]+)$/, "_p$1$2");
  215. else
  216. Items[x].src = datasrc ? datasrc : Items[x].src.replace(/_p(\d+\.[a-zA-Z\?\d]+)$/, "_big_p$1");
  217. }
  218. }
  219. }
  220.  
  221. window.addEventListener("load", pixivlink, true);