您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Add links to first and last chapter to Fanfiction.net.
当前为
// ==UserScript== // @name Fanfiction.net: Links to First and Last Chapter // @namespace https://greasyfork.org/en/users/163551-vannius // @version 1.0 // @description Add links to first and last chapter to Fanfiction.net. // @author Vannius // @match https://www.fanfiction.net/s/* // @grant none // ==/UserScript== (function() { // Only multi-chapter story has <SELECT> tags. const chapSelectTags = document.getElementsByTagName('SELECT'); if (!chapSelectTags.length) return; // Get data to make links const baseUrl = window.location.href.split('/').slice(0, 5).join('/'); const title = window.location.href.split('/')[6]; const chapter = Number(window.location.href.split('/')[5]); const lastChapter = chapSelectTags[0][chapSelectTags[0].length - 1].value; // When current chapter > 2, add link to first chapter. if (chapter > 2){ for (let i = 0; i < chapSelectTags.length; i++){ // Make firstBtn to frist chapter const firstBtn = document.createElement('BUTTON'); firstBtn.className = 'btn'; firstBtn.type = 'BUTTON'; firstBtn.addEventListener('click', function(e) { e.preventDefault(); window.location.href = [baseUrl, 1, title].join('/'); }); firstBtn.appendChild(document.createTextNode('« First')); // Insert firstBtn chapSelectTags[i].parentElement.insertBefore(firstBtn, chapSelectTags[i].previousElementSibling); // Adjust placement of firstBtn chapSelectTags[i].parentElement.insertBefore(document.createTextNode(' '), chapSelectTags[i].previousElementSibling); } } // When current chapter < lastChapter - 1, add link to last chapter. if (chapter < lastChapter - 1){ for (let i = 0; i < chapSelectTags.length; i++){ // Make lastBtn to last chapter const lastBtn = document.createElement('BUTTON'); lastBtn.className = 'btn'; lastBtn.type = 'BUTTON'; lastBtn.addEventListener('click', function(e) { e.preventDefault(); window.location.href = [baseUrl, lastChapter, title].join('/'); }); lastBtn.appendChild(document.createTextNode('Last ≫')); // Adjust placement of lastBtn chapSelectTags[i].parentElement.appendChild(document.createTextNode(' ')); // Insert lastBtn chapSelectTags[i].parentElement.appendChild(lastBtn); } } })();