Add experimental Pixiv support
This commit is contained in:
parent
289a0a050e
commit
7d5e229317
|
@ -114,11 +114,55 @@ function getBetterUrl(url, callback) {
|
|||
callback(baseurl + '/' + filename);
|
||||
};
|
||||
request.send();
|
||||
} else if(isPixivUrl(url)) {
|
||||
//TODO: Use a content script instead of re-fetching the page
|
||||
|
||||
var pageRequest = new XMLHttpRequest();
|
||||
pageRequest.open('GET', url, true);
|
||||
pageRequest.onload = function () {
|
||||
var regex = /<div class="_layout-thumbnail ui-modal-trigger"><img src="[^"]+img-master\/([^"]+)_master[0-9]+(\.[^"]+)".*>/g;
|
||||
|
||||
var match = regex.exec(pageRequest.responseText);
|
||||
|
||||
var imageUrl = 'http://i3.pixiv.net/img-original/' + match[1] + match[2];
|
||||
|
||||
var imageRequest = new XMLHttpRequest();
|
||||
imageRequest.open('GET', imageUrl, true);
|
||||
imageRequest.setRequestHeader('X-Pixiv-Referer', url);
|
||||
imageRequest.onload = function () {
|
||||
callback(imageUrl);
|
||||
};
|
||||
imageRequest.send();
|
||||
};
|
||||
pageRequest.send();
|
||||
} else {
|
||||
callback(url);
|
||||
}
|
||||
}
|
||||
|
||||
chrome.webRequest.onBeforeSendHeaders.addListener(
|
||||
function(details) {
|
||||
if(details.url.indexOf('pixiv') != -1) {
|
||||
for (var i = 0; i < details.requestHeaders.length; ++i) {
|
||||
if (details.requestHeaders[i].name === 'X-Pixiv-Referer') {
|
||||
var referer = details.requestHeaders[i].value;
|
||||
details.requestHeaders.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
details.requestHeaders.push({
|
||||
name: 'Referer',
|
||||
value: referer
|
||||
});
|
||||
}
|
||||
|
||||
return {requestHeaders: details.requestHeaders};
|
||||
},
|
||||
{urls: ["*://*/*"], types: ["xmlhttprequest"]},
|
||||
["blocking", "requestHeaders"]
|
||||
);
|
||||
|
||||
function cleanExtension(url) {
|
||||
var trailingStrings = ["?", ":orig", ":large", ":small", ":thumb", ":medium"];
|
||||
|
||||
|
@ -135,6 +179,10 @@ function isInstagramUrl(url) {
|
|||
return url.indexOf('instagram.com/p') != -1;
|
||||
}
|
||||
|
||||
function isPixivUrl(url) {
|
||||
return url.indexOf('pixiv.net/member_illust.php') != -1;
|
||||
}
|
||||
|
||||
function isCoolUrl(url, callback) {
|
||||
url = url.toLowerCase();
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
"storage",
|
||||
"http://*/*",
|
||||
"https://*/*",
|
||||
"bookmarks"
|
||||
"bookmarks",
|
||||
"webRequest",
|
||||
"webRequestBlocking"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
|
||||
<!--
|
||||
TODO:
|
||||
* Add pixiv support
|
||||
* Add progress/status messages
|
||||
* Add imageboard thread archival support
|
||||
* Add booru support
|
||||
|
|
Loading…
Reference in New Issue