// ==UserScript==
// @name Pixiv Number of Illusts Icon
// @description Add icon indicates number of illusts into pixiv illust page
// @namespace https://gist.github.com/tkrkt
// @version 0.1
// @match https://www.pixiv.net/member_illust.php*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const isLoaded = () => !!document.querySelector('.work-info .meta') && !!document.querySelector('.works_display');
const waitForLoad = callback => {
if (isLoaded()) {
callback();
} else {
setTimeout(() => waitForLoad(callback), 1000);
}
};
waitForLoad(() => {
const multiple = Array.from(document.querySelectorAll('.work-info .meta li')).filter(li => li.textContent.indexOf('複数枚投稿') >= 0);
if (multiple.length) {
const page = multiple[0].textContent.match(/\d+/)[0];
const style = document.createElement('style');
style.textContent = `
.multiple ._icon-20._icon-files:after {
content: "${page}";
color: gray;
font-size: 10px;
position: absolute;
top: 8px;
left: 8px;
width: 14px;
height: 14px;
line-height: 14px;
text-align: center;
white-space: pre;
}`;
document.head.appendChild(style);
document.querySelector('.multiple ._icon-20._icon-files').style.position = 'relative';
}
});
})();