Repository navigation
Expand file tree
/
Copy pathpixiv-filter-followers.js
More file actions
102 lines (93 loc) · 3.38 KB
/
Copy pathpixiv-filter-followers.js
File metadata and controls
102 lines (93 loc) · 3.38 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// ==UserScript==
// @name Pixiv filter followers page for artists and inline illustrations
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Filters the followers pages to only show those who have illustrations, and also previews some illustrations.
// @description:ja フォロワーのページをイラストのある人だけに絞り込み、一部のイラストをプレビューすることができます。
// @author Cro
// @match https://www.pixiv.net/*
// @icon https://www.google.com/s2/favicons?domain=pixiv.net
// @grant none
// @license MIT
// ==/UserScript==
/* jshint esversion: 6 */
(function() {
'use strict';
let users = [];
let last_params = null;
let fetch_users = function()
{
let request = new URL(location);
let user_id = request.pathname.match(/\d+/g)[0];
request.pathname = `/ajax/user/${user_id}/followers`;
let page = 0;
if (request.search.length > 0)
{
page = parseInt(request.search.replace(/\?p=/g, '')) - 1;
}
let params = { offset: page * 24, limit: 24, lang: 'en' };
request.search = new URLSearchParams(params).toString();
fetch(request, { headers: { 'content-type': 'application/json' } })
.then(response => response.json())
.then(function(data)
{
users = data.body.users;
});
};
let get_target = user => document.querySelector(`a[href*="${user.userId}"`);
let add_user_illusts = function(user)
{
let target = get_target(user);
if (target)
{
let search_id = 'cro_img';
let container_parent = target.closest('div').parentNode.parentNode;
let maybe_img_container = container_parent.querySelector(`div [id="${search_id}"]`);
if (!maybe_img_container)
{
let img_container = document.createElement('div');
container_parent.append(img_container);
img_container.style['padding-top'] = '5px';
img_container.id = search_id;
for (let illust of user.illusts.slice(0, 3))
{
let a = document.createElement('a');
a.href = `/artworks/${illust.id}`;
let img = new Image();
img.src = illust.url;
img.style.height = '100px';
img.style.float = 'left';
img.style['padding-inline'] = '5px';
a.append(img);
img_container.append(a);
}
}
}
};
let process_users = function()
{
if (!location.pathname.endsWith("followers"))
{
last_params = null;
return;
}
if (last_params != location.search)
{
last_params = location.search;
fetch_users();
return;
}
for (let user of users)
{
if (user.illusts.length == 0)
{
let node = get_target(user)?.closest('li')?.remove();
}
else
{
add_user_illusts(user);
}
}
};
setInterval(process_users, 250);
})();