AO3: Visible Full-page Index Button

Moves or copies (setting is user configurable) the "Full-page index" button to the main work navigation bar for ease of access

当前为 2023-05-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name AO3: Visible Full-page Index Button
  3. // @namespace https://github.com/w4tchdoge
  4. // @version 1.2.3-20230524_005424
  5. // @description Moves or copies (setting is user configurable) the "Full-page index" button to the main work navigation bar for ease of access
  6. // @author w4tchdoge
  7. // @homepage https://github.com/w4tchdoge/MISC-UserScripts
  8. // @match *://archiveofourown.org/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=archiveofourown.org
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. `use strict`;
  14.  
  15. /* IMPORTANT – Change this value depending on whether or not you want the initial "Full-page index" button remove from the "Chapter Index" dropdown – IMPORTANT */
  16. const remove_ini_fpi_btn = true;
  17.  
  18. // Only execute the rest of the script if the "Chapter Index" element exists (this is so it doesn't throw an error in the console when viewing an entire work or a single chapter work)
  19. if (document.querySelector(`ul.work.navigation.actions li[class="chapter"]`) != null) {
  20.  
  21. // Find the "Chapter Index" button on the main work navbar
  22. var ch_indx_btn = document.querySelector(`ul.work.navigation.actions li[class="chapter"]`);
  23.  
  24. // Get the "Full-page index" button using XPATH
  25. var ini_fpi_btn = document.evaluate(`//*[@id="chapter_index"]/li[*/text()[contains(.,'Full-page index')]]`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  26.  
  27. // Get the href attribute of the "Full-page index" button that normally lives within the "Chapter Index" dropdown
  28. var fpi_href = ini_fpi_btn.querySelector(`a`).getAttribute(`href`);
  29.  
  30. // Create a slightly modified copy of the "Full-page index" button element
  31. var fpi_button = Object.assign(document.createElement(`a`), {
  32. id: `navbar_full_page_index_btn`,
  33. href: `${fpi_href}`,
  34. innerHTML: `Full-page index`
  35. });
  36.  
  37. // Append the modified copy to the "Chapter Index" button element such that it appears to the right of it in the main work navbar
  38. ch_indx_btn.append(fpi_button);
  39.  
  40. // Code to run if the original "Full-page index" button is to be removed
  41. if (remove_ini_fpi_btn == true) {
  42.  
  43. // Remove the "Full-page index" button from the "Chapter Index" dropdown if remove_ini_fpi_btn is set to true
  44. ini_fpi_btn.remove();
  45.  
  46. // Remove the padding-right on the "Go" button in the "Chapter Index" dropdown
  47. document.querySelector(`ul#chapter_index select#selected_id+span`).setAttribute(`style`, `padding-right: 0 !important;`);
  48.  
  49. }
  50.  
  51. }
  52.  
  53. })();