表示調整
閉じる
挿絵表示切替ボタン
▼配色
▼行間
▼文字サイズ
▼メニューバー
×閉じる

ブックマークに追加しました

設定
0/400
設定を保存しました
エラーが発生しました
※文字以内
ブックマークを解除しました。

エラーが発生しました。

エラーの原因がわからない場合はヘルプセンターをご確認ください。

ブックマーク機能を使うにはログインしてください。
8/11

しおりダイアログでの、しおり位置設定を常に可能に

 と言う訳で、別スレッドの不具合内容の対処。

 ボタンの挿入と、ハンドラの設定を行う。


manifest.json

-----------

{

"name": "narouListModifier",

"version": "1.0.0",

"manifest_version": 3,

"description": "なろうのBMから最新まで読んだものを非表示にする",

"host_permissions":[

"https://syosetu.com/*"

],

"content_scripts": [{

"run_at": "document_end",

"matches": ["https://syosetu.com/favnovelmain/list/*"],

"js": [

"content.js"

]

},{

"run_at": "document_start",

"matches": ["https://ncode.syosetu.com/*"],

"world": "MAIN",

"js": [

"bookmark.js"

]

}]

}

-----------

worldの指定を行っている。セキュリティ的とかには、適当ではないのだけれど。


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("div.bookmark-change");

let newButton = document.createElement("button");

newButton.setAttribute("type", "button");

newButton.setAttribute("class", "button button_remodal 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.novel_bn")[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);

}

}

}

});

-----------


まあ、とりあえずは動くみたい。動けば正義。




評価をするにはログインしてください。
この作品をシェア
Twitter LINEで送る
ブックマークに追加
ブックマーク機能を使うにはログインしてください。
― 新着の感想 ―
このエピソードに感想はまだ書かれていません。
感想一覧
+注意+

特に記載なき場合、掲載されている作品はすべてフィクションであり実在の人物・団体等とは一切関係ありません。
特に記載なき場合、掲載されている作品の著作権は作者にあります(一部作品除く)。
作者以外の方による作品の引用を超える無断転載は禁止しており、行った場合、著作権法の違反となります。

この作品はリンクフリーです。ご自由にリンク(紹介)してください。
この作品はスマートフォン対応です。スマートフォンかパソコンかを自動で判別し、適切なページを表示します。

↑ページトップへ