アクティブ読書
増井俊之.icon提唱概念
読書体験が格段に向上する
プロジェクト名はmtane0412-ISBN13の形式にした
ギリギリ入る
ページ名タイトルをp101とかにした
前後ページに移動するUserScriptがあると楽そう
code:js
// ==UserScript==
// @name Improved Scrapbox Page Navigation for SPA
// @version 1.3
// @description Improve visibility control of navigation buttons in Scrapbox SPA
// @author You
// @grant none
// ==/UserScript==
(function() {
'use strict';
let prevButton, nextButton;
// Function to create a navigation button
function createNavButton(text, isNext) {
const button = document.createElement("a");
button.textContent = text;
button.style.position = "fixed";
button.style.bottom = "20px";
button.style.backgroundColor = "rgba(255, 255, 255, 0.5)";
button.style.padding = "10px";
button.style.borderRadius = "5px";
button.style.textDecoration = "none";
button.style.color = "black";
if (isNext) {
button.style.right = "20px";
} else {
button.style.left = "20px";
}
return button;
}
// Check if the current URL matches the book page pattern
function isBookPage(url) {
const pattern = /https:\/\/scrapbox.io\/mtane0412-.+\/p\d+/;
return pattern.test(url);
}
// Update button URLs and visibility based on current URL
function updateButtons() {
if (isBookPage(location.href)) {
const pathParts = window.location.pathname.split('/');
const currentPageNumber = parseInt(pathParts.pop().substring(1), 10);
const baseUrl = pathParts.join('/');
const prevPageNumber = currentPageNumber - 1;
const nextPageNumber = currentPageNumber + 1;
prevButton.href = baseUrl + '/p' + String(prevPageNumber).padStart(3, '0');
nextButton.href = baseUrl + '/p' + String(nextPageNumber).padStart(3, '0');
prevButton.style.display = "block";
nextButton.style.display = "block";
} else {
prevButton.style.display = "none";
nextButton.style.display = "none";
}
}
// Initialize buttons and start observing URL changes
function init() {
prevButton = createNavButton("← Prev", false);
nextButton = createNavButton("Next →", true);
document.body.appendChild(prevButton);
document.body.appendChild(nextButton);
updateButtons();
// Observe URL changes
let lastUrl = location.href;
new MutationObserver(() => {
const currentUrl = location.href;
if (currentUrl !== lastUrl) {
lastUrl = currentUrl;
updateButtons();
}
}).observe(document, {subtree: true, childList: true});
}
init();
})();