なろうのスタイルが変更された2
自作品の編集画面へのジャンプ機能も、スタイル変更で動かなくなっているじゃない。
というわけで、こちらもbookmark.jsに組み込んでしまいました。
bookmark.js
--------
document.addEventListener("DOMContentLoaded", function() {
const sioris = document.querySelectorAll("input[name=auto_siori]");
sioris.forEach((x) => {
x.setAttribute("name", "auto_siori_x");
});
if (sioris.length > 0) {
const no = sioris[0].attributes["data-no"].value - 0;
const favno = sioris[0].attributes["data-favno"].value - 0;
const url = sioris[0].attributes["data-url"].value;
const primary = sioris[0].attributes["data-primary"].value;
const token = sioris[0].attributes["data-token"].value;
window.mover = () => {
try {
const formData = new FormData();
formData.append('no', no);
formData.append('primary', primary);
formData.append('token', token);
fetch(url, {
method: 'POST',
body: formData,
credentials: "include"
})
.then(response => {
return response.json();
})
.then(data => {
if (data.error.code) {
alert("しおりの更新に失敗しました。")
}
else {
document.querySelector(".js-siori").classList.add("is-active");
}
})
.catch (error => {
alert("しおりの更新に失敗しました。")
});
}
catch (error) {
alert("しおりの更新に失敗しました。");
}
};
const parent = document.querySelector("input.js-delconf_bookmark_submit").parentElement;
let newButton = document.createElement("button");
newButton.setAttribute("type", "button");
newButton.setAttribute("class", "c-button c-button--beige c-button--siori siori_setbtn");
newButton.setAttribute("onclick", "window.mover();this.style.display='none';")
newButton.innerText = "しおりをここへ移動";
parent.insertBefore(newButton, parent.firstChild);
if (no == favno + 1) {
const targetElement = document.querySelectorAll("div.c-pager")[1];
if (targetElement) {
const callback = (entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// TODO
window.mover();
observer.disconnect();
}
});
};
const options = {
root: null,
rootMargin: '0px',
threshold: 1.0
};
const observer = new IntersectionObserver(callback, options);
observer.observe(targetElement);
}
}
}
// 自分用Edit
if (document.querySelector("div.p-novelgood-form__icon") === null) {
const header = document.querySelector("header.c-menu nav");
const id = header
.children[3]
.getAttribute("href")
.match(/\/list\/ncode\/(\d+)\//)[1]
const url = 'https://syosetu.com/usernovelmanage/top/ncode/' + id + '/';
const html = "<a class='c-menu__item' href='" + url + "'>編集</a></li>";
const elem = document.createRange().createContextualFragment(html);
header.insertBefore(elem, header.children[5]);
}
});
------
これで、ここで作ったほとんどの機能を一つの拡張機能に突っ込んじゃったことになります。
編集メニューの追加は、縦型スマホ表示だとあるいはきついかも。




