// ==UserScript==
// @name Pixiv Infinite Scroll
// @name:ja Pixiv Infinite Scroll
// @name:zh-CN Pixiv Infinite Scroll
// @name:zh-TW Pixiv Infinite Scroll
// @namespace https://github.com/chimaha/Pixiv-Infinite-Scroll
// @match https://www.pixiv.net/*
// @grant none
// @version 1.3.3
// @author chimaha
// @description Add infinite scroll feature to Pixiv.
// @description:ja Pixivに無限スクロール機能を追加します。
// @description:zh-CN 为 Pixiv 添加无限滚动功能。
// @description:zh-TW 因為Pixiv有無限移動功能。
// @license MIT license
// @icon https://www.pixiv.net/favicon.ico
// @supportURL https://github.com/chimaha/Pixiv-Infinite-Scroll/issues
// @downloadURL none
// ==/UserScript==
/*! Pixiv Infinite Scroll | MIT license | https://github.com/chimaha/Pixiv-Infinite-Scroll/blob/main/LICENSE */
// フォロー中の無限スクロール-----------------------------------------------------------------
function following_process() {
// langの値によって言語を変更する
const setFollowLanguage = [];
const currentLanguage = document.querySelector("html").getAttribute("lang");
switch (currentLanguage) {
case "ja":
setFollowLanguage.push("フォロー中", "フォローする");
break;
case "ko":
setFollowLanguage.push("팔로우 중", "팔로우하기");
break;
case "zh-CN":
setFollowLanguage.push("已关注", "加关注");
break;
case "zh-TW":
setFollowLanguage.push("關注中", "加關注");
break;
default:
setFollowLanguage.push("Following", "Follow");
}
function createElement(userId, userName, userProfileImage, userComment, userFollowing, illustId, illustTitle, illustUrl, illustBookmarkData, illustAlt, illustR18, illustPageCount) {
// フォロー中・フォローするを切り替え
let changeFollowLanguage;
let followClass;
let followStyle = "";
if (userFollowing) {
changeFollowLanguage = setFollowLanguage[0];
followClass = "cnpwVx";
followStyle = 'style="background-color: var(--charcoal-surface3); color: var(--charcoal-text2); font-weight: bold; padding-right: 24px; padding-left: 24px; border-radius: 999999px; height: 40px;"';
} else {
changeFollowLanguage = setFollowLanguage[1];
followClass = "fOWAlD";
}
// ブックマークを切り替え
let bookmarkClass = [];
let bookmarkStyle = [];
for (const checkBookmark of illustBookmarkData) {
if (checkBookmark) {
bookmarkClass.push("bXjFLc");
bookmarkStyle.push('style="color: rgb(255, 64, 96); fill: currentcolor;"');
} else {
bookmarkClass.push("dxYRhf");
}
}
// コメントに特定の記号が入っていた場合にエスケープ
function escapleText(userComment) {
return userComment
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
const escapedComment = escapleText(userComment);
// R18マーク
let r18Element = [];
for (const checkR18 of illustR18) {
if (checkR18 == "R-18") {
r18Element.push('
');
} else {
r18Element.push("");
}
}
// うごくイラスト再生マーク。イラスト枚数表示
let ugoiraElement = [];
let pageCountElement = [];
illustPageCount.forEach((pageCount, i) => {
if (illustAlt[i].slice(-4) == "うごイラ") {
ugoiraElement.push('');
pageCountElement.push("");
} else {
ugoiraElement.push("");
if (pageCount >= 2) {
pageCountElement.push(`
`);
} else {
pageCountElement.push("");
}
}
});
// イラストがない場合は表示しないようにするため、分けて作成する
let illustGroup = "";
for (let i = 0; i < illustId.length; i++) {
illustGroup += `
`;
}
let illustContainer = "";
if (illustId[0]) {
illustContainer = `
`;
}
// "appendElements+="で一括追加にすると、なぜかundefinedが追加され続けるので一つずつ追加
const appendElements = `
`;
document.querySelector(".sc-1y4z60g-4.cqwgCG").insertAdjacentHTML("beforeend", appendElements);
}
// https://www.pixiv.net/ajax/user/*/following?offset=24&limit=24&rest=show
// https://www.pixiv.net/users/*/following?p=2
if (document.querySelectorAll(".sc-1y4z60g-5.iVLXCu").length < 23) { return; }
// URL作成
const matches = window.location.href.match(followingRegex);
let offset;
if (matches[2]) {
offset = (Number(matches[2]) * 24) + (scrollPageCount * 24);
} else {
offset = 24 + (scrollPageCount * 24);
}
scrollPageCount++;
const url = `https://www.pixiv.net/ajax/user/${matches[1]}/following?offset=${offset}&limit=24&rest=show`;
const fetchData = async () => {
const response = await fetch(url);
const json = await response.json();
for (let i = 0; i < Object.keys(json.body.users).length; i++) {
const users = json.body.users[i];
const userId = users.userId;
const userName = users.userName;
const userProfileImage = users.profileImageUrl;
const userComment = users.userComment.slice(0, 98);
const userFollowing = users.following;
const illustId = [];
const illustTitle = [];
const illustUrl = [];
const illustBookmarkData = [];
const illustAlt = [];
const illustR18 = [];
const illustPageCount = [];
for (let j = 0; j < Object.keys(json.body.users[i].illusts).length; j++) {
const illusts = json.body.users[i].illusts[j];
illustId.push(illusts.id);
illustTitle.push(illusts.title);
illustUrl.push(illusts.url);
illustBookmarkData.push(illusts.bookmarkData);
illustAlt.push(illusts.alt);
illustR18.push(illusts.tags[0]);
illustPageCount.push(illusts.pageCount);
}
createElement(userId, userName, userProfileImage, userComment, userFollowing, illustId, illustTitle, illustUrl, illustBookmarkData, illustAlt, illustR18, illustPageCount);
}
};
(async () => {
await fetchData();
bookmarkAddDelete();
followAndUnfollow(setFollowLanguage);
})();
}
// -----------------------------------------------------------------------------------------
// ブックマーク・フォローユーザーの作品・タグ検索の無限スクロール--------------------------------
function bookmarkAndTag_process(checkType, matches) {
function createElement(illustId, illustTitle, illustUrl, userId, userName, illustPageCount, illustBookmarkData, illustAlt, userProfileImage, typeElement, typeClass, illustR18, illustMaskReason) {
// langの値によって言語を変更する
const setDeletedLanguage = [];
const currentLanguage = document.querySelector("html").getAttribute("lang");
switch (currentLanguage) {
case "ja":
setDeletedLanguage.push("R18 / R18G", "作品", "閲覧制限中", "削除済み", "もしくは非公開");
break;
case "ko":
setDeletedLanguage.push("R-18 / R-18G", "작품", "열람 제한 중", "삭제됨", "혹은 비공개");
break;
case "zh-CN":
setDeletedLanguage.push("R-18 / R-18G", "作品", "浏览受限(含成人内容)", "已删除", "或不公开");
break;
case "zh-TW":
setDeletedLanguage.push("R-18 / R-18G", "作品", "瀏覽受限(含成人內容)", "已刪除", "或非公開");
break;
default:
setDeletedLanguage.push("R-18/R-18G", "works", "Restricted (Adult Content)", "Deleted", "or private");
}
// ブックマークを切り替え
let bookmarkClass = "";
let bookmarkStyle = "";
if (illustBookmarkData) {
bookmarkClass = "bXjFLc";
bookmarkStyle = 'style="color: rgb(255, 64, 96); fill: currentcolor;"';
} else {
bookmarkClass = "dxYRhf";
}
// R18マーク
let r18Element = "";
if (illustR18 == "R-18") {
r18Element = `
`;
}
// うごくイラスト再生マーク・イラスト数表示
let ugoiraElement = "";
let pageCountElement = "";
if (illustAlt.slice(-4) == "うごイラ") {
ugoiraElement = '';
} else {
if (illustPageCount > 2) {
pageCountElement = `
`;
}
}
let illustContainer = "";
let userNameContainer = "";
let addBookmarkClass = "";
let illustTitleElement;
if (illustTitle == "-----") {
if (illustMaskReason == "r18" || illustMaskReason == "r18g") {
// R18・R18G
illustContainer = `
${setDeletedLanguage[0]}
${setDeletedLanguage[1]}
`;
illustTitleElement = `${setDeletedLanguage[2]}`
} else {
// 削除・非公開
illustContainer = `
${setDeletedLanguage[3]}
${setDeletedLanguage[4]}
`;
illustTitleElement = `${illustTitle}`
}
} else {
// ノーマル
illustContainer = `

${ugoiraElement}
${r18Element}
${pageCountElement}
`;
userNameContainer = `
`;
illustTitleElement = `${illustTitle}`
addBookmarkClass = " addBookmark"
}
appendElements += `
${typeElement}
${illustTitleElement}
${userNameContainer}
`;
}
let appendElements = "";
if (checkType == "bookmark") {
// ブックマーク
// https://www.pixiv.net/ajax/user/*/illusts/bookmarks?tag=&offset=0&limit=48&rest=show
// https://www.pixiv.net/users/*/bookmarks/artworks?p=2
if (document.querySelectorAll(".sc-9y4be5-2.kFAPOq").length < 48) { return; }
// URL作成
let offset;
if (matches[3]) {
offset = (Number(matches[3]) * 48) + (scrollPageCount * 48);
} else {
offset = 48 + (scrollPageCount * 48);
}
let tag = "";
if (matches[2]) {
tag = matches[2]
}
scrollPageCount++;
const url = `https://www.pixiv.net/ajax/user/${matches[1]}/illusts/bookmarks?tag=${tag}&offset=${offset}&limit=48&rest=show`;
const fetchData = async () => {
const response = await fetch(url);
const json = await response.json();
for (let i = 0; i < Object.keys(json.body.works).length; i++) {
const illust = json.body.works[i];
const illustId = illust.id;
const illustTitle = illust.title;
const illustUrl = illust.url;
const userId = illust.userId;
const userName = illust.userName;
const illustPageCount = illust.pageCount;
const illustBookmarkData = illust.bookmarkData;
const illustAlt = illust.alt;
const userProfileImage = illust.profileImageUrl;
const typeElement = ``;
const typeClass = "";
const illustR18 = illust.tags[0];
const illustMaskReason = illust.maskReason;
createElement(illustId, illustTitle, illustUrl, userId, userName, illustPageCount, illustBookmarkData, illustAlt, userProfileImage, typeElement, typeClass, illustR18, illustMaskReason);
}
document.querySelector(".sc-9y4be5-1.jtUPOE").insertAdjacentHTML("beforeend", appendElements);
};
(async () => {
await fetchData();
bookmarkAddDelete();
})();
} else if (checkType == "follow") {
// フォローユーザーの作品
// https://www.pixiv.net/ajax/follow_latest/illust?p=2&mode=all
// https://www.pixiv.net/bookmark_new_illust.php?p=2
if (document.querySelectorAll(".sc-9y4be5-2.kFAPOq").length < 60) { return; }
// URL作成
let offset;
scrollPageCount++;
if (matches[2]) {
offset = Number(matches[2]) + scrollPageCount;
} else {
offset = 1 + scrollPageCount;
}
let setMode = "";
if (matches[1]) {
setMode = "r18";
} else {
setMode = "all";
}
const url = `https://www.pixiv.net/ajax/follow_latest/illust?p=${offset}&mode=${setMode}`;
const fetchData = async () => {
const response = await fetch(url);
const json = await response.json();
for (let i = 0; i < Object.keys(json.body.thumbnails.illust).length; i++) {
const illust = json.body.thumbnails.illust[i];
const illustId = illust.id;
const illustTitle = illust.title;
const illustUrl = illust.url;
const userId = illust.userId;
const userName = illust.userName;
const illustPageCount = illust.pageCount;
const illustBookmarkData = illust.bookmarkData;
const illustAlt = illust.alt;
const userProfileImage = illust.profileImageUrl;
const typeElement = ``;
const typeClass = "gtm-followlatestpage-thumbnail-link";
const illustR18 = illust.tags[0];
const illustMaskReason = illust.maskReason;
createElement(illustId, illustTitle, illustUrl, userId, userName, illustPageCount, illustBookmarkData, illustAlt, userProfileImage, typeElement, typeClass, illustR18, illustMaskReason);
}
document.querySelector(".sc-9y4be5-1.jtUPOE").insertAdjacentHTML("beforeend", appendElements);
};
(async () => {
await fetchData();
bookmarkAddDelete();
})();
} else if (checkType == "tag") {
// タグ検索
// https://www.pixiv.net/ajax/search/artworks/*?word=*&order=date_d&mode=all&p=1&s_mode=s_tag_full&type=all
// https://www.pixiv.net/tags/*/artworks?p=2
if (document.querySelectorAll(".sc-l7cibp-2.gpVAva").length < 60) { return; }
// URL作成
let offset;
scrollPageCount++;
if (matches[7]) {
offset = Number(matches[7]) + scrollPageCount;
} else {
offset = 1 + scrollPageCount;
}
let setIllustType = "";
let insertIllustType;
if (matches[2] == "manga") {
setIllustType = "type=manga";
insertIllustType = "manga";
} else if (matches[2] == "artworks") {
setIllustType = "type=all";
insertIllustType = "illustManga";
} else if (matches[9] == "illust") {
setIllustType = "type=illust";
insertIllustType = "illust";
} else if (matches[9] == "ugoira") {
setIllustType = "type=ugoira";
insertIllustType = "illust";
} else if (matches[2] == "illustrations") {
setIllustType = "type=illust_and_ugoira";
insertIllustType = "illust";
}
let sinceDate = "";
if (matches[5]) {
sinceDate = `&${matches[5]}`;
}
let untilDate = "";
if (matches[6]) {
untilDate = `&${matches[6]}`;
}
let otherTag = "";
if (matches[10]) {
otherTag = `&${matches[10]}`;
}
let setMode = "";
if (matches[4] == "mode=safe" || matches[4] == "mode=r18") {
setMode = matches[4];
} else {
setMode = "mode=all";
}
let orderDate = "";
if (matches[3] == "order=date") {
orderDate = matches[3];
} else {
orderDate = "order=date_d";
}
let tagMatchMode = "";
if (matches[8] == "s_mode=s_tag" || matches[8] == "s_mode=s_tc") {
tagMatchMode = matches[8];
} else {
tagMatchMode = "s_mode=s_tag_full";
}
const url = `https://www.pixiv.net/ajax/search/${matches[2]}/${matches[1]}?word=${matches[1]}&${orderDate}&${setMode}&p=${offset}&${tagMatchMode}&${setIllustType}${sinceDate}${untilDate}${otherTag}`;
const fetchData = async () => {
const response = await fetch(url);
const json = await response.json();
for (let i = 0; i < Object.keys(json.body[insertIllustType].data).length; i++) {
// jsonファイルに、なぜか必ず1つだけ欠けている部分があるのでスキップする
if (!json.body[insertIllustType].data[i].id) { continue; }
const illust = json.body[insertIllustType].data[i];
const illustId = illust.id;
const illustTitle = illust.title;
const illustUrl = illust.url;
const userId = illust.userId;
const userName = illust.userName;
const illustPageCount = illust.pageCount;
const illustBookmarkData = illust.bookmarkData;
const illustAlt = illust.alt;
const userProfileImage = illust.profileImageUrl;
const typeElement = ``;
const typeClass = "";
const illustR18 = illust.tags[0];
const illustMaskReason = illust.maskReason;
createElement(illustId, illustTitle, illustUrl, userId, userName, illustPageCount, illustBookmarkData, illustAlt, userProfileImage, typeElement, typeClass, illustR18, illustMaskReason);
}
document.querySelector(".sc-l7cibp-1.krFoBL").insertAdjacentHTML("beforeend", appendElements);
};
(async () => {
await fetchData();
bookmarkAddDelete();
})();
}
}
// -----------------------------------------------------------------------------------------
// 新たに追加した要素でのブックマーク・フォロー機能---------------------------------------------
// x-csrf-tokenを取得
const getCsrfToken = async () => {
const response = await fetch(location.origin);
const data = await response.text();
const matchToken = data.match(/"token":"([a-z0-9]+)"/);
return matchToken[1];
};
// ブックマーク追加・削除
function bookmarkAddDelete() {
const buttonGrandElements = document.querySelectorAll(".addBookmark");
for (let i = 0; i < buttonGrandElements.length; i++) {
const buttonElement = buttonGrandElements[i].querySelector(".sc-kgq5hw-0.fgVkZi");
const svgElement = buttonGrandElements[i].querySelector("svg.sc-j89e3c-1");
const getIdElement = buttonGrandElements[i].querySelector("a.sc-d98f2c-0.khjDVZ");
const userId = getIdElement.getAttribute("data-gtm-user-id");
const illustId = getIdElement.getAttribute("data-gtm-value");
buttonGrandElements[i].classList.remove("addBookmark");
buttonElement.addEventListener("click", () => {
if (svgElement.classList.contains("dxYRhf")) {
// ブックマーク追加
(async () => {
try {
buttonElement.setAttribute("disabled", true);
const addBookmarkBody = {
illust_id: illustId,
restrict: 0,
comment: "",
tags: []
};
const url = "https://www.pixiv.net/ajax/illusts/bookmarks/add";
const setCsrfToken = await getCsrfToken();
const response = await fetch(url, {
method: "post",
headers: {
"Accept": "application/json",
"Content-Type": "application/json; charset=utf-8",
"x-csrf-token": setCsrfToken,
},
body: JSON.stringify(addBookmarkBody),
credentials: "same-origin"
});
const json = await response.json();
// ストレージにBookmarkIDを保存
sessionStorage.setItem(illustId, json.body.last_bookmark_id);
if (!response.ok) { throw new Error(); }
buttonElement.removeAttribute("disabled");
svgElement.style.color = "rgb(255, 64, 96)";
svgElement.style.fill = "currentcolor";
svgElement.classList.remove("dxYRhf");
svgElement.classList.add("bXjFLc");
} catch (error) {
console.error(error);
buttonElement.removeAttribute("disabled");
}
})();
} else if (svgElement.classList.contains("bXjFLc")) {
// ブックマーク削除
(async () => {
try {
buttonElement.setAttribute("disabled", true);
// BookmarkIDを取得する
const getStorageItem = sessionStorage.getItem(illustId);
sessionStorage.removeItem(illustId);
let bookmarkId;
if (getStorageItem) {
bookmarkId = getStorageItem;
} else {
// https://www.pixiv.net/ajax/user/*/illusts?ids[]=*
const illustInfoUrl = `https://www.pixiv.net/ajax/user/${userId}/illusts?ids[]=${illustId}`;
const illustInfoResponse = await fetch(illustInfoUrl);
const illustInfoJson = await illustInfoResponse.json();
bookmarkId = illustInfoJson.body[illustId].bookmarkData.id;
}
const deleteBookmarkBody = new URLSearchParams({
bookmark_id: bookmarkId
});
const url = "https://www.pixiv.net/ajax/illusts/bookmarks/delete"
const setCsrfToken = await getCsrfToken();
const response = await fetch(url, {
method: "post",
headers: {
"Accept": "application/json",
"x-csrf-token": setCsrfToken,
},
body: deleteBookmarkBody,
credentials: "same-origin"
});
if (!response.ok) { throw new Error(); }
buttonElement.removeAttribute("disabled");
svgElement.removeAttribute("style");
svgElement.classList.remove("bXjFLc");
svgElement.classList.add("dxYRhf");
} catch (error) {
console.error(error);
buttonElement.removeAttribute("disabled");
}
})();
}
})
}
}
// フォロー・フォロー解除
function followAndUnfollow(setFollowLanguage) {
const buttonElements = document.querySelectorAll(".follow");
for (let i = 0; i < buttonElements.length; i++) {
const buttonElement = buttonElements[i];
const userId = buttonElement.getAttribute("data-gtm-user-id");
buttonElement.classList.remove("follow");
buttonElement.addEventListener("click", () => {
if (buttonElement.classList.contains("fOWAlD")) {
// フォローする
(async () => {
try {
buttonElement.setAttribute("disabled", true);
const followBody = new URLSearchParams({
mode: "add",
type: "user",
user_id: userId,
tag: "",
restrict: 0,
format: "json"
});
const url = "https://www.pixiv.net/bookmark_add.php";
const setCsrfToken = await getCsrfToken();
const response = await fetch(url, {
method: "post",
headers: {
"Accept": "application/json",
"x-csrf-token": setCsrfToken,
},
body: followBody,
credentials: "same-origin"
});
if (!response.ok) { throw new Error(); }
buttonElement.removeAttribute("disabled");
buttonElement.classList.remove("fOWAlD");
buttonElement.classList.add("cnpwVx");
buttonElement.style.backgroundColor = "var(--charcoal-surface3)";
buttonElement.style.color = "var(--charcoal-text2)";
buttonElement.style.fontWeight = "bold";
buttonElement.style.padding = "0 24px";
buttonElement.style.borderRadius = "999999px";
buttonElement.style.height = "40px";
buttonElement.textContent = setFollowLanguage[0];
} catch (error) {
console.error(error);
buttonElement.removeAttribute("disabled");
}
})();
} else if (buttonElement.classList.contains("cnpwVx")) {
// フォロー解除
(async () => {
try {
buttonElement.setAttribute("disabled", true);
const unfollowBody = new URLSearchParams({
mode: "del",
type: "bookuser",
id: userId
});
const url = "https://www.pixiv.net/rpc_group_setting.php"
const setCsrfToken = await getCsrfToken();
const response = await fetch(url, {
method: "post",
headers: {
"Accept": "application/json",
"x-csrf-token": setCsrfToken,
},
body: unfollowBody,
credentials: "same-origin"
});
if (!response.ok) { throw new Error(); }
buttonElement.removeAttribute("disabled");
buttonElement.classList.remove("cnpwVx");
buttonElement.classList.add("fOWAlD");
buttonElement.removeAttribute("style");
buttonElement.textContent = setFollowLanguage[1];
} catch (error) {
console.error(error);
buttonElement.removeAttribute("disabled");
}
})();
}
})
}
}
// -----------------------------------------------------------------------------------------
let isProcessed = false;
let currentUrl;
let scrollPageCount = 0;
const followingRegex = /https:\/\/www\.pixiv\.net(?:\/en)?\/users\/(\d+)\/following(?:\?p=(\d+))?/;
const bookmarkRegex = /https:\/\/www\.pixiv\.net(?:\/en)?\/users\/(\d+)\/bookmarks\/artworks(?:\/([^?]+))?(?:\?p=(\d+))?/;
const followUserWorkRegex = /https:\/\/www\.pixiv\.net\/bookmark_new_illust(_r18)?\.php(?:\?p=(\d+))?(?:(?:&|\?)(tag=.*))?/;
const tagRegex = /https:\/\/www\.pixiv\.net(?:\/en)?\/tags\/(.+)\/(artworks|illustrations|manga)(?:\?(order=date))?(?:(?:&|\?)(mode=(?:r18|safe)))?(?:(?:&|\?)(scd=\d{4}\-\d{2}-\d{2}))?(?:(?:&|\?)(ecd=\d{4}\-\d{2}-\d{2}))?(?:(?:&|\?)p=(\d+))?(?:(?:&|\?)(s_mode=(?:s_tag|s_tc)))?(?:(?:&|\?)type=([^&]+))?(?:(?:&|\?)(.+))?/;
const observer = new MutationObserver(mutationsList => {
// URLが変更された際の処理
if (window.location.href != currentUrl) {
isProcessed = false;
scrollPageCount = 0;
// タグページで条件を変更した際に、追加した要素を削除する
if (tagRegex.test(window.location.href)) {
const removeElements = document.querySelectorAll(".addElement");
for (const removeElement of removeElements) {
removeElement.remove();
}
}
}
if (followingRegex.test(window.location.href)) {
// フォロー
currentUrl = window.location.href;
const intersectionTarget = document.querySelector(".sc-1y4z60g-4.cqwgCG");
if (intersectionTarget && !isProcessed) {
isProcessed = true;
const scrollObserver = new IntersectionObserver(entries => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
following_process();
isProcessed = false;
scrollObserver.unobserve(entry.target);
}
})
});
scrollObserver.observe(document.querySelector(".sc-1y4z60g-5.iVLXCu:last-child").previousElementSibling);
}
} else if (bookmarkRegex.test(window.location.href) || followUserWorkRegex.test(window.location.href) || tagRegex.test(window.location.href)) {
// ブックマーク・フォローユーザーの作品・タグ検索
currentUrl = window.location.href;
let checkType;
let matches;
if (bookmarkRegex.test(window.location.href)) {
checkType = "bookmark";
matches = window.location.href.match(bookmarkRegex);
} else if (followUserWorkRegex.test(window.location.href)) {
checkType = "follow";
matches = window.location.href.match(followUserWorkRegex);
if (matches[3]) {
observer.disconnect();
return;
}
} else {
checkType = "tag";
matches = window.location.href.match(tagRegex);
}
let intersectionTarget;
if (bookmarkRegex.test(window.location.href) || followUserWorkRegex.test(window.location.href)) {
intersectionTarget = document.querySelector(".sc-9y4be5-1.jtUPOE");
} else {
intersectionTarget = document.querySelector(".sc-l7cibp-1.krFoBL img");
}
if (intersectionTarget && !isProcessed) {
isProcessed = true;
const options = { rootMargin: "0px 0px 300px 0px" };
const scrollObserver = new IntersectionObserver(entries => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
bookmarkAndTag_process(checkType, matches);
isProcessed = false;
scrollObserver.unobserve(entry.target);
}
})
}, options);
if (bookmarkRegex.test(window.location.href) || followUserWorkRegex.test(window.location.href)) {
scrollObserver.observe(document.querySelector(".sc-9y4be5-2.kFAPOq:last-child"));
} else {
// タグページで条件を切り替えた際に、要素を取得するタイミングを遅らせるためにsetTimeoutを使用
// 2ページ目と3ページ目が同時に読み込まれてしまうので、2ページ目もsetTimeoutを使用
if (scrollPageCount == 0 || scrollPageCount == 1) {
setTimeout(() => {
scrollObserver.observe(document.querySelector(".sc-l7cibp-2.gpVAva:last-child"));
}, 400);
} else {
scrollObserver.observe(document.querySelector(".sc-l7cibp-2.gpVAva:last-child"));
}
}
}
}
});
const config = { childList: true, subtree: true };
observer.observe(document.querySelector("#root"), config);