Greasy Fork 还支持 简体中文。

Pixiv Lazy plus

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

目前為 2018-05-24 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Pixiv Lazy plus
  3. // @namespace pixivlazyplus
  4. // @description provide a direct link to original image ([s] link).
  5. // @version 0.9.0.17
  6. // @include http://www.pixiv.net/*
  7. // @include https://www.pixiv.net/*
  8. // @include https://accounts.pixiv.net/*
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM_xmlhttpRequest
  12. // @grant GM_log
  13. // @grant GM_registerMenuCommand
  14. // ==/UserScript==
  15. // version 0.9.0.17 - fix medium page list after server side version up
  16. // version 0.9.0.16 - fix medium page after server side version up
  17. // version 0.9.0.15 - fix fetching preview urls, add a button for manual generating source links
  18. // version 0.9.0.14 - use data-src and always post-processing
  19. // version 0.9.0.13 - fix OAuth login detection URL, turn pixiv-dic URL into tag-searching URL
  20. // version 0.9.0.12 - try to auto login with tags.php ifreame reloading
  21. // version 0.9.0.11 - fix ranking [s] link attachment
  22. // version 0.9.0.10 - resize images in manga view
  23. // version 0.9.0.9 - fix for elimination of public API me.json
  24. // version 0.9.0.8 - add Auto Login menu item
  25. // version 0.9.0.7 - more fix of cookie issue
  26. // version 0.9.0.6 - fix cookie issue
  27. // version 0.9.0.5 - fix ugoira link again
  28. // version 0.9.0.4 - restore MangaFull function
  29. // version 0.9.0.3 - fix clearing accessToken logic, add function to check if accessToken is still valid
  30. // version 0.9.0.2 - fix ugoira link
  31. // version 0.9.0.1 - disable MangaFull since pixiv checks referer for full size manga pages now.
  32. // version 0.9 - upgrade to OAuth API + Pixiv Public API
  33. // version 0.8.14.1 - fix new medium page layout
  34. // version 0.8.13 - fix image response lazy link position
  35. // version 0.8.12 - fix mypage right side lazy links
  36. // version 0.8.11 - fix double links in medium page
  37. // version 0.8.10 - fix double links in medium page
  38. // version 0.8.9 - append [U] link after canvas
  39. // version 0.8.8 - fix loading big manga URL bug introduced in 0.8.7
  40. // version 0.8.7 - fix loading big manga URL in with PNG format
  41. // version 0.8.6 - fix modifying big manga URL in manga page
  42. // version 0.8.5 - fix preloading new manga URL format
  43. // version 0.8.4 - fix detecting URL new format
  44. // version 0.8.3 - fix detecting URL new format
  45. // version 0.8.2 - fix detecting URL new format
  46. // version 0.8.1 - fix detecting ugoira in prev/next
  47. // version 0.8.0 - add ability for downloading ugoira as zip
  48. // version 0.7.9 - fix for no profile image
  49. // version 0.7.8 - fix for spapi return value changes
  50. // version 0.7.7 - change [s] to [M](go directly to manga page) for manga links
  51. // version 0.7.6 - fix prev/next [s] link
  52. // version 0.7.5 - fix new manga page
  53. // version 0.7.4 - fix modified images
  54. // version 0.7.3 - fix missing session ID when it is not the end of cookie
  55. // version 0.7.2 - fix comma in tags breaking parsing logic
  56. // version 0.7.1 - fix iPhone API by supplying session ID
  57. // version 0.7 - work with new sample images with iPhone API, fix old manga
  58. // version 0.6.1 - preload manga images
  59. // version 0.6 - change manga mode to big images
  60. // version 0.5 - remove [b] link, add stylish style class
  61. // version 0.4 - updated to filter new thumbnails
  62. // version 0.3 - fix a bug, hat-tip to syosyo
  63. // version 0.2 - updated on 2008-06-25
  64. var pixivlink_run = 0;
  65. var pixivlink_reloadRequested = 0;
  66. var isNewManga = 1;
  67. var postProcImg = new Array();
  68. var preloadImg = new Array();
  69. var Imgs = new Array();
  70. var sessID1 = (/PHPSESSID=[0-9a-f]*?(?=;|$)/.exec(document.cookie) || "");
  71. var sessID2 = (/PHPSESSID=[^;]*?(?=;|$)/.exec(document.cookie) || "");
  72. var accessToken = GM_getValue("accessToken","");
  73. var oauthUserName = GM_getValue("userName","");
  74. var oauthPassword = GM_getValue("passWord","");
  75. var autoLogin = GM_getValue("autoLogin",false);
  76. var mangaFormat = 'jpg';
  77. var pixivlink_imgs = 0;
  78.  
  79. /*
  80. String.prototype.splitCSV = function(sep) {
  81. for (var foo = this.split(sep = sep || ","), x = foo.length - 1, tl; x >= 0; x--) {
  82. if (foo[x].replace(/"\s+$/, '"').charAt(foo[x].length - 1) == '"') {
  83. if ((tl = foo[x].replace(/^\s+"/, '"')).length > 1 && tl.charAt(0) == '"') {
  84. foo[x] = foo[x].replace(/^\s*"|"\s*$/g, '').replace(/""/g, '"');
  85. } else if (x) {
  86. foo.splice(x - 1, 2, [foo[x - 1], foo[x]].join(sep));
  87. } else foo = foo.shift().split(sep).concat(foo);
  88. } else foo[x].replace(/""/g, '"');
  89. } return foo;
  90. };*/
  91.  
  92. function _e(id) { return document.getElementById(id); }
  93.  
  94. function getElementsByClassName(matchClass) {
  95. var clselems = new Array();
  96. var elems = document.getElementsByTagName('*'), i;
  97. for (i in elems) {
  98. if((' ' + elems[i].className + ' ').indexOf(' ' + matchClass + ' ')
  99. > -1) {
  100. clselems.push(elems[i]);
  101. }
  102. }
  103. return clselems;
  104. }
  105.  
  106. function createCookie(cookietext,days, domain) {
  107. if (days) {
  108. var date = new Date();
  109. date.setTime(date.getTime()+(days*24*60*60*1000));
  110. var expires = "; expires="+date.toGMTString();
  111. }
  112. else var expires = "";
  113. if (domain) domain = "; domain="+domain;
  114. else domain = "";
  115. document.cookie = cookietext+expires+domain+"; path=/";
  116. }
  117.  
  118. function doOAuth(obj) {
  119. var oauthUser, oauthPass, returnData;
  120. oauthUser = _e("oauthUsername").value;
  121. oauthPass = _e("oauthPassword").value;
  122. createCookie("PHPSESSID=",-1,""); // erase cookie first
  123. createCookie("PHPSESSID=",-1,".pixxiv.net"); // erase cookie first
  124. if(oauthUser && oauthPass) {
  125. GM_setValue("userName",oauthUser);
  126. GM_setValue("passWord",oauthPass);
  127. GM_xmlhttpRequest({
  128. url: 'https://oauth.secure.pixiv.net/auth/token',
  129. method: "POST",
  130. headers: {
  131. Referer: "http://www.pixiv.net",
  132. "Content-Type": "application/x-www-form-urlencoded"
  133. },
  134. data: "username="+oauthUser+"&password="+oauthPass+"&grant_type=password&client_id=bYGKuGVw91e0NMfPGp44euvGt59s&client_secret=HP3RmkgAmEGro0gn1x9ioawQE8WMfvLXDz3ZqxpK",
  135. onload: function (response) {
  136. if (response.status == 200) {
  137. returnData = JSON.parse(response.responseText);
  138. accessToken = returnData.response.access_token;
  139. GM_setValue("accessToken",accessToken);
  140. if(!autoLogin) alert("Login Sucessfully.");
  141. //createCookie(sessID1,0,""); // restore cookie first
  142. createCookie(sessID2,0,".pixiv.net"); // restore cookie first
  143. window.postMessage('refresh', '*'); //location.reload();
  144. } else {
  145. //createCookie(sessID1,0,""); // restore cookie first
  146. createCookie(sessID2,0,".pixiv.net"); // restore cookie first
  147. GM_setValue("autoLogin",false); // clear autologin flag
  148. alert("Login Failed!");
  149. }
  150. }
  151. });
  152. }
  153. }
  154.  
  155. function createOAuthLoginForm() {
  156. var tmp, newHTML = document.createElement ('div');
  157. newHTML.id = 'gmOAuthLoginFrm';
  158. newHTML.style.position='absolute';
  159. newHTML.style.backgroundColor='#fff';
  160. newHTML.style.top='0';
  161. newHTML.style.left='0';
  162. newHTML.style.zIndex='100';
  163. newHTML.appendChild(document.createTextNode('OAuth Login User: '));
  164. tmp = document.createElement ('input');
  165. tmp.id = 'oauthUsername';
  166. tmp.type = 'text';
  167. tmp.value = oauthUserName;
  168. newHTML.appendChild(tmp);
  169. newHTML.appendChild(document.createTextNode('Pass: '));
  170. tmp = document.createElement ('input');
  171. tmp.id = 'oauthPassword';
  172. tmp.type = 'password';
  173. tmp.value = oauthPassword;
  174. newHTML.appendChild(tmp);
  175. tmp = document.createElement ('input');
  176. tmp.id = 'oauthSubmit';
  177. tmp.type = 'button';
  178. tmp.value='Login';
  179. tmp.addEventListener("click", function(e){return doOAuth(e);}, false);
  180. newHTML.appendChild(tmp);
  181.  
  182. document.body.appendChild (newHTML);
  183. if(autoLogin) doOAuth(null);
  184. }
  185.  
  186. function checkTokenValid() {
  187. if(window==window.top) /* I'm NOT in a frame! */ {
  188. window.addEventListener('message', function(e) {
  189. if(e.data=='refresh') {
  190. if(!pixivlink_reloadRequested) {
  191. // GM_log(e.data);
  192. pixivlink_reloadRequested = 1;
  193. setTimeout("location.reload()",2000);
  194. }
  195. }
  196. }, false);
  197. }
  198.  
  199. if(getElementsByClassName('not-logged-in').length || getElementsByClassName('signup-form__submit').length) {
  200. createCookie("PHPSESSID=",-1,""); // erase oauth cookie
  201. GM_log('not logged in');
  202. var hobj;
  203. if(hobj=_e('login_pixiv_id')) hobj.value = oauthUserName;
  204. if(hobj=_e('login_password')) hobj.value = oauthPassword;
  205. /* for old login form */
  206. if(hobj=document.getElementsByName('pixiv_id')) hobj[0].value = oauthUserName;
  207. if(hobj=document.getElementsByName('password')) hobj[0].value = oauthPassword;
  208. /*if(window==window.top && (getElementsByClassName('signup-form__submit--login').length || getElementsByClassName('ui-button _login').length)) {
  209. var tmp, newHTML = document.createElement ('iframe');
  210. newHTML.setAttribute("src", "http://www.pixiv.net/tags.php");
  211. newHTML.id = 'gmAutoLoginFrame';
  212. newHTML.style.position='absolute';
  213. newHTML.style.backgroundColor='#fff';
  214. newHTML.style.top='-2000';
  215. newHTML.style.left='-2000';
  216. newHTML.height='1px';
  217. newHTML.width='1px';
  218. newHTML.style.zIndex='-100';
  219. document.body.appendChild (newHTML);
  220. }*/
  221. if(autoLogin) {
  222.  
  223. autoLogin = false;
  224. var loginForm;
  225. if(hobj=_e('login_password')) {
  226. loginForm = hobj.parentNode;
  227. do {
  228. if(loginForm.nodeName == 'FORM') {
  229. if(window!=window.top) {
  230. if(!pixivlink_reloadRequested) {
  231. pixivlink_reloadRequested = 1;
  232. window.top.postMessage('refresh', '*');
  233. }
  234. }
  235. // GM_log('called refresh! 1');
  236. loginForm.submit();
  237. }
  238. } while(loginForm = loginForm.parentNode);
  239. }
  240.  
  241. /* try old login form as well */
  242. if(hobj=document.getElementsByName('password')) {
  243. GM_log('old login submit');
  244. loginForm = hobj[0].parentNode;
  245. do {
  246. if(loginForm.nodeName == 'FORM') {
  247. if(window!=window.top) {
  248. if(!pixivlink_reloadRequested) {
  249. pixivlink_reloadRequested = 1;
  250. window.top.postMessage('refresh', '*');
  251. }
  252. }
  253. GM_log('called refresh! 2');
  254. loginForm.submit();
  255. break;
  256. }
  257. } while(loginForm = loginForm.parentNode);
  258. }
  259. }
  260. } else {
  261. if(0 /* disabled */ && window!=window.top) /* I'm in a frame! */ {
  262. if(!pixivlink_reloadRequested) {
  263. pixivlink_reloadRequested = 1;
  264. window.top.postMessage('refresh', '*');
  265. }
  266. // GM_log('called refresh! 3');
  267. }
  268. }
  269. GM_xmlhttpRequest({
  270. url: 'https://public-api.secure.pixiv.net/v1/me.json',
  271. method: "GET",
  272. headers: {
  273. Referer: "http://www.pixiv.net",
  274. "Authorization": "Bearer " + accessToken,
  275. "Cookie": sessID1
  276. },
  277. onload: function (response) {
  278. if (response.status == 200) {
  279. //GM_log(response.responseText);
  280. /* var vals = JSON.parse(response.responseText);
  281. if(vals.status == "success") {
  282. }*/
  283. } else /*if (response.status == 400)*/ {
  284. accessToken ="";
  285. GM_setValue("accessToken",accessToken);
  286. createOAuthLoginForm();
  287. }
  288. }
  289. });
  290. }
  291.  
  292. function GetImageIDFromLink(imageLink) {
  293. var imgID = 0; // If lower 11319936 it means Manga does not have Big version
  294.  
  295. var re = /\d+([_a-z0-9]+)?\.(jpe?g|gif|png)\??.*$|id=[0-9]+$/;
  296. var s = re.exec(imageLink);
  297. if (s && s.length > 0) {
  298. re = /\d+/;
  299. imgID = re.exec(s[0])[0];
  300. }
  301. return imgID;
  302. }
  303.  
  304. function pixivlink() {
  305. //alert(pixivlink_run);
  306. if (!pixivlink_run) pixivlink_run = 1;
  307. else return;
  308. checkTokenValid();
  309. var Items = document.getElementsByTagName('img');
  310. var rexa = /\?mode\=(medium|manga)\&illust_id|i\.pximg\.net/;
  311. var rexb = /source.pixiv.net/;
  312. var rexc = /\/img-inf\//;
  313. var rexd = /\/mobile\//;
  314. var rexe = /\/c\//;
  315. for (var i = 0; i < Items.length; i++) {
  316. var imgR = Items[i];
  317. var aR = imgR.parentNode.parentNode;
  318. var aR2 = imgR.parentNode;
  319. var isThumbnail = ((' ' + aR2.className + ' ').indexOf(' _layout-thumbnail ') > -1) //&& ((' ' + aR2.className + ' ').indexOf(' ui-modal-trigger ') > -1)
  320. //GM_log('aR2.className = "'+aR2.className+'", imgR.src='+imgR.src);
  321. //GM_log('isThumbnail = '+isThumbnail);
  322. if (rexa.test(aR2.href)/* || isThumbnail*/) {
  323. aR = aR2;
  324. }
  325. if (rexa.test(aR.href) || isThumbnail) {
  326. if(imgR.hasAttribute("data-src")) {
  327. var imgID = GetImageIDFromLink(imgR.getAttribute("data-src"));
  328. var srcR = imgR.getAttribute("data-src").replace(/_s\.|_m\.|_100\.|_64x64|_master1200\./i, ".");
  329. } else {
  330. var imgID = GetImageIDFromLink(imgR.src);
  331. var srcR = imgR.src.replace(/_s\.|_m\.|_100\.|_64x64|_master1200\./i, ".");
  332. }
  333. srcR = srcR.replace(/\/c\/\d+x\d+(_\d+)?\/img-master\//i, "/img-original/");
  334. // var hrefR = aR.href.replace(/medium/i, "big");
  335. var tdR = aR.parentNode;
  336. //GM_log('srcR = "'+srcR);
  337. /* var linkB = document.createElement('a');
  338. linkB.href = hrefR;
  339. linkB.target = '_blank';
  340. linkB.style.padding = '0 2px';
  341. linkB.className = '_pxlazy';
  342. linkB.appendChild(document.createTextNode('[b]'));
  343. tdR.appendChild(linkB);*/
  344. // tdR.appendChild(document.createTextNode(' '));
  345. if (!rexb.test(srcR) && Imgs.indexOf(imgID) == -1 && !_e('ill_' + imgID)) {
  346. var linkS = document.createElement('a');
  347. linkS.href = srcR;
  348. linkS.target = '_blank';
  349. linkS.className = '_pxlazy _pxlazy_s';
  350. linkS.setAttribute('id', 'ill_' + imgID);
  351. linkS.appendChild(document.createTextNode('[s]'));
  352. if (aR2.tagName.toUpperCase() == 'DIV' && imgR.className.toLowerCase().indexOf('thumbnail') == -1) {
  353. var targetelem = getElementsByClassName('works_display');
  354. if(targetelem.length) {
  355. targetelem[0].appendChild(linkS);
  356. } else {
  357. tdR.appendChild(linkS);
  358. }
  359. } else {
  360. tdR.appendChild(linkS);
  361. }
  362. if (1/*rexc.test(imgR.src)||rexd.test(imgR.src)||rexe.test(imgR.src)*/) {
  363. //GM_log("postProcImg.push("+imgID+")"+imgR.src);
  364. postProcImg.push(imgID);
  365. }
  366. Imgs.push(imgID);
  367. }
  368. }
  369. }
  370.  
  371. var ItemsDiv = document.getElementsByTagName('div');
  372. //GM_log("ItemsDiv.length="+ItemsDiv.length);
  373. for (var i = 0; i < ItemsDiv.length; i++) {
  374. var divR = ItemsDiv[i];
  375. var aR = divR.parentNode.parentNode;
  376. var rexf = /\/img-master\//;
  377. var imgSrc;
  378. try{
  379. imgSrc=divR.style.backgroundImage.substr(5);
  380. imgSrc=imgSrc.substr(0,imgSrc.length-2);
  381. }catch(e) {}
  382. var isThumbnail = ((' ' + divR.className + ' ').indexOf(' lazyloaded ') > -1)
  383. if(isThumbnail || rexf.test(imgSrc)) {
  384. var imgID = GetImageIDFromLink(divR.style.backgroundImage);
  385. var imgSrc=divR.style.backgroundImage.substr(5);
  386. imgSrc=imgSrc.substr(0,imgSrc.length-2);
  387. //GM_log("imgSrc="+imgSrc);
  388. var srcR = imgSrc.replace(/_s\.|_m\.|_100\.|_64x64|_master1200\./i, ".");
  389. if (rexf.test(imgSrc) && !_e('ill_' + imgID)) {
  390. // GM_log("style.backgroundImage="+imgSrc);
  391.  
  392. var linkS = document.createElement('a');
  393. linkS.href = srcR;
  394. linkS.target = '_blank';
  395. linkS.className = '_pxlazy _pxlazy_s';
  396. linkS.setAttribute('id', 'ill_' + imgID);
  397. linkS.appendChild(document.createTextNode('[s]'));
  398.  
  399. if(aR.tagName.toUpperCase() == 'A') aR = aR.parentNode;
  400. aR.appendChild(linkS);
  401. postProcImg.push(imgID);
  402. }
  403. }
  404. }
  405.  
  406. if (postProcImg.length > 0) {
  407. for (var x = 0; x < postProcImg.length; x++) {
  408. if(accessToken) GM_xmlhttpRequest({
  409. url: 'https://public-api.secure.pixiv.net/v1/works/' + postProcImg[x] + '.json?image_sizes=large',
  410. method: "GET",
  411. headers: {
  412. Referer: "http://www.pixiv.net",
  413. "Authorization": "Bearer " + accessToken,
  414. "Cookie": sessID1
  415. },
  416. onload: function (response) {
  417. if (response.status == 200) {
  418. var rexb = /source.pixiv.net/;
  419. // var rexU = /\/c\//;
  420. var rexU = /_ugoira/;
  421. var rexe = /\/c\//;
  422. var vals = JSON.parse(response.responseText);
  423. /*var vtxt = '';
  424. for(var x=0;x < vals.length;x++)
  425. vtxt=vtxt+x+':'+vals[x]+"\n";
  426. GM_log(vtxt);*/
  427. if (vals.status == "success") {
  428. var slnk, imgID, isRestricted;
  429. isRestricted = rexb.test(vals.response[0].image_urls.large);
  430. isUgoira = rexU.test(vals.response[0].image_urls.large);
  431. // if (!isRestricted) {
  432. //GM_log("imgID = vals[0]");
  433. imgID = vals.response[0].id;
  434. /* } else {
  435. //GM_log("GetImageIDFromLink("+response.finalUrl+")");
  436. imgID = GetImageIDFromLink(response.finalUrl);
  437. }*/
  438. slnk = _e('ill_' + imgID);
  439. if (slnk) {
  440. var goodSlink;
  441. if (vals.response[0].is_manga) {
  442. goodSlink = 'http://www.pixiv.net/member_illust.php?mode=manga&illust_id=' + imgID;
  443. slnk.innerHTML = '[M]';
  444. } else {
  445. var re = new RegExp('/' + imgID + '_.*$');
  446. if (isUgoira) {// grab zip!
  447. //GM_log("isUgoira");
  448. slnk.innerHTML = '[U]';
  449. goodSlink = vals.response[0].image_urls.large.replace(/img-original/, 'img-zip-ugoira').replace(re, '/' + imgID + '_ugoira1920x1080.zip');
  450. /* } else if (rexe.test(vals[9])) {// new 480mw URL
  451. //GM_log("480mw");
  452. goodSlink = vals[9].replace(/c\/480x960\//, '').replace(/img-master/, 'img-original').replace(re, '/' + vals[0] + '_p0.' + vals[2]);
  453. } else if (!isRestricted && !rexe.test(vals[9])) {// use 480mw instead
  454. //GM_log("480mw");
  455. goodSlink = vals[9].replace(/mobile\//, '').replace(re, '/' + vals[0] + '.' + vals[2]);
  456. } else { //salvage from profile image
  457. //GM_log("salvage");
  458. re = /\/[0-9_]+\..*$/;
  459. goodSlink = vals[29].replace(/mobile\//, '').replace(/profile\//, 'img/').replace(re, '/' + imgID + '.' + vals[2]);
  460. */
  461. } else {
  462. goodSlink = vals.response[0].image_urls.large;
  463. }
  464. }
  465. slnk.href = goodSlink;
  466. slnk.title=vals.response[0].reuploaded_time;
  467. slnk.className = '_pxlazy _pxlazy_s _pxlazy_s_new';
  468. }
  469. }
  470. } else if (response.status == 400) {
  471. accessToken ="";
  472. GM_setValue("accessToken",accessToken);
  473. }
  474. }
  475. });
  476. }
  477. }
  478.  
  479. /* var links = document.getElementsByTagName('a');
  480. var tagslink = /tags\.php\?tag=/;
  481. for (var i = 0; i < links.length; i++) {
  482. if (tagslink.test(links[i].href))
  483. links[i].href = links[i].href.replace("tags.php?tag=", "search.php?s_mode=s_tag&word=");
  484. }*/
  485.  
  486. if (unsafeWindow.pixiv && unsafeWindow.pixiv.context.images) {
  487. var illustID = GetImageIDFromLink(unsafeWindow.pixiv.context.images[0]/*[0]*/);
  488. isNewManga = (illustID >= 11319936);
  489. //GM_log("illustID="+illustID);
  490. GM_xmlhttpRequest({
  491. url: 'https://public-api.secure.pixiv.net/v1/works/' + illustID + '.json?image_sizes=large',
  492. method: "GET",
  493. headers: {
  494. Referer: "http://www.pixiv.net",
  495. "Authorization": "Bearer " + accessToken,
  496. "Cookie": sessID1
  497. },
  498. onload: function (response) {
  499. if (response.status == 200) {
  500. //GM_log(response.responseText);
  501. var vals = JSON.parse(response.responseText);
  502. var rexe = /\/c\//;
  503. if(vals.status == "success") {
  504. mangaFormat = vals.response[0].metadata.pages[0].image_urls.large.split('.').pop();
  505. //GM_log(mangaFormat);
  506. /*var vtxt = '';
  507. for(var x=0;x < vals.length;x++)
  508. vtxt=vtxt+x+':'+vals[x]+"\n";
  509. GM_log(vtxt);*/
  510. //GM_log("2nd");
  511. /*if (rexe.test(vals[9]))*/ mangaFull();
  512. }
  513. } else if (response.status == 400) {
  514. accessToken ="";
  515. GM_setValue("accessToken",accessToken);
  516. }
  517. }
  518. });
  519. var rexe = /\/c\//;
  520. //GM_log("isNewManga");
  521. //setTimeout(mangaFull,250);
  522. //GM_log("2nd");
  523. // mangaFull();
  524. }
  525. }
  526.  
  527. var vp_w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0)
  528. var vp_h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0)
  529. function resizeImg(obj){
  530. //console.log("resizeImg");
  531. var imgW=obj.width;
  532. var imgH=obj.height;
  533. var imgAR=imgW/imgH;
  534.  
  535. obj.alt = obj.src;
  536.  
  537. /* set min size to 16x16px */
  538. obj.style.minWidth = '16px';
  539. obj.style.minHeight = '16px';
  540.  
  541. if(imgW > vp_w || imgH > vp_h) {
  542. if(imgAR < 1.0) {
  543. obj.height = vp_h*0.95;
  544. obj.width = obj.height*imgAR;
  545. } else {
  546. obj.width = vp_w*0.88;
  547. obj.height = obj.width/imgAR;
  548. }
  549. }
  550. }
  551.  
  552. function mangaFull() {
  553. Items = document.getElementsByTagName('img');
  554. var rexe = /\/img-/;
  555. for (var x = 0; x < unsafeWindow.pixiv.context.images.length; x++) {
  556. if (isNewManga) {
  557. if(rexe.test(unsafeWindow.pixiv.context.images[x]))
  558. 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."+mangaFormat);
  559. else
  560. unsafeWindow.pixiv.context.images[x]/*[0]*/ = unsafeWindow.pixiv.context.images[x]/*[0]*/.replace(/_p(\d+\.[a-zA-Z\?\d]+)$/, "_big_p$1");
  561. }
  562. preloadImg.push(new Image());
  563. preloadImg[preloadImg.length - 1].src = unsafeWindow.pixiv.context.images[x]/*[0]*/;
  564. }
  565.  
  566. for (var x = 0; x < Items.length; x++) {
  567. var datasrc = Items[x].getAttribute("data-src");
  568. if (datasrc) {
  569. //GM_log("original-datasrc="+datasrc+" ,mangaFormat="+mangaFormat);
  570. if(rexe.test(datasrc))
  571. datasrc = datasrc.replace(/c\/1200x1200\//, '').replace(/img-master/, 'img-original').replace(/_p(\d+).*(\.[a-zA-Z\?\d]+)$/, "_p$1."+mangaFormat);
  572. else
  573. datasrc = datasrc.replace(/_p(\d+\.[a-zA-Z\?\d]+)$/, "_big_p$1");
  574. //GM_log("new-datasrc="+datasrc+" ,mangaFormat="+mangaFormat);
  575. }
  576. Items[x].setAttribute("data-src", datasrc);
  577. Items[x].addEventListener('load', function(e) {resizeImg(e.target);},true);
  578. if (isNewManga) {
  579. //GM_log(x+".src="+Items[x].src);
  580. if(datasrc)
  581. Items[x].src = datasrc;
  582. else if(rexe.test(Items[x].src))
  583. Items[x].src = Items[x].src.replace(/c\/1200x1200\//, '').replace(/img-master/, 'img-original').replace(/_p(\d+).*(\.[a-zA-Z\?\d]+)$/, "_p$1$2");
  584. else
  585. Items[x].src = datasrc ? datasrc : Items[x].src.replace(/_p(\d+\.[a-zA-Z\?\d]+)$/, "_big_p$1");
  586. }
  587. }
  588. }
  589.  
  590. if(!autoLogin) {
  591. GM_registerMenuCommand("Enable Auto Login", function(){
  592. GM_setValue("autoLogin",true);
  593. });
  594. } else {
  595. GM_registerMenuCommand("Disable Auto Login", function(){
  596. GM_setValue("autoLogin",false);
  597. });
  598. }
  599. window.addEventListener("load", pixivlink, true);
  600.  
  601. // create button for manually trigger source link generation
  602. tmp = document.createElement ('input');
  603. tmp.id = 'pxlink';
  604. tmp.type = 'button';
  605. tmp.value='P';
  606. tmp.accessKey='x';
  607. tmp.style.position = "fixed";
  608. tmp.style.bottom = "0px";
  609. tmp.style.left = "0px";
  610. tmp.style.backgroundColor="#fdd";
  611.  
  612. tmp.addEventListener("click", function(e){postProcImg = new Array();pixivlink_run = 0;pixivlink();}, false);
  613. document.body.appendChild(tmp);