/
YDB-MADUp-Pixiv.user.js
67 lines (59 loc) · 2.17 KB
/
YDB-MADUp-Pixiv.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// ==UserScript==
// @name YDB:MADUp - Pixiv
// @version 1.0.0
// @description Simplifies process of image updating and uploading (for Pixiv)
// @author stsyn
// @match *://*/*
// @exclude *://*/api*/json/*
// @exclude *://*/adverts/*
// @require https://github.com/stsyn/GM_fetch/raw/master/GM_fetch.js
// @require https://github.com/stsyn/createElement/raw/component/src/es5.js
// @require https://github.com/stsyn/derpibooruscripts/raw/master/YouBooru/libs/ui/Inputs.js
// @require https://github.com/stsyn/derpibooruscripts/raw/master/YouBooru/libs/api/Basics.js
// @require https://github.com/stsyn/derpibooruscripts/raw/master/YouBooru/libs/YDB-MADUp-common.js
// @downloadURL https://github.com/stsyn/derpibooruscripts/raw/master/YouBooru/YDB-MADUp-Pixiv.user.js
// @updateURL https://github.com/stsyn/derpibooruscripts/raw/master/YouBooru/YDB-MADUp-Pixiv.user.js
// @grant GM.xmlHttpRequest
// ==/UserScript==
(function() {
'use strict';
const imageRequest = (link) => new Promise((resolve, reject) => {
GM.xmlHttpRequest({
method: 'GET',
url: link,
responseType: 'blob',
headers: {
'Referer': 'https://www.pixiv.net/',
},
onload: function(response) {
resolve(response.response);
},
onerror: reject,
ontimeout: reject,
});
});
YDB_MADUp.registerFetcher(
'Pixiv',
str => str.match(/.*\.pixiv\.net\/(.*\/|)artworks\/.*/),
async(url) => {
let content;
try {
const response = await GM.fetch(url, { headers: { referer: 'https://www.pixiv.net/' } });
const text = await response.text();
const match = text.match(/<meta name="preload-data" id="meta-preload-data" content='(.*)'>/)[1];
content = JSON.parse(match);
const artwork = Object.values(content.illust)[0];
const link = artwork.urls.original;
const image = await imageRequest(link);
return {
blob: image,
};
} catch(e) {
alert('Something went wrong. See the console or check deviation page');
console.log(content);
throw e;
}
},
1,
);
})();