From ee3a9988a29a02b2ea9c29920c7a578b19ebbfba Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Thu, 5 May 2016 17:14:33 +0200 Subject: [PATCH] Fix Pixiv support --- background.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/background.js b/background.js index 5d4e88f..9a29514 100644 --- a/background.js +++ b/background.js @@ -124,15 +124,25 @@ function getBetterUrl(url, callback) { var match = regex.exec(pageRequest.responseText); - var imageUrl = 'http://i3.pixiv.net/img-original/' + match[1] + match[2]; + var imageUrl = 'http://i3.pixiv.net/img-original/' + match[1]; - var imageRequest = new XMLHttpRequest(); - imageRequest.open('GET', imageUrl, true); - imageRequest.setRequestHeader('X-Pixiv-Referer', url); - imageRequest.onload = function () { - callback(imageUrl); + var onload = function (imageRequest, extension) { + if(imageRequest.status == 404 && extension == "jpg") { + makerequest("png"); + } else { + callback(imageUrl + "." + extension); + } }; - imageRequest.send(); + + var makerequest = function(extension) { + var imageRequest = new XMLHttpRequest(); + imageRequest.open('GET', imageUrl + "." + extension, true); + imageRequest.setRequestHeader('X-Pixiv-Referer', url); + imageRequest.onload = function() { onload(imageRequest, extension); }; + imageRequest.send(); + }; + + makerequest("jpg"); }; pageRequest.send(); } else {