Greasy Fork 支持简体中文。

AO3 Easy Navigation Userscripts

Adds "Marked for Later" and "Bookmarked Fics" buttons on the home page of AO3, as well as creates a "random works" button in marked for later list

目前為 2023-07-09 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name AO3 Easy Navigation Userscripts
  3. // @namespace Ellililunch AO3 USERSCIPTS
  4. // @version 0.3
  5. // @history 0.0 deplicated JaneBuzJane's script to put the "Marked for Later" button on the home page of AO3.
  6. // @history 0.1 modified JaneBuzJane's script to put the "Marked for Later" button on the home page of AO3 wo create a "bookmarked fics" botton to the home tab of AO3.
  7. // @history 0.2 combined the script for a "Marked for Later" and "Bookmarked Fics" botton in one script
  8. // @history 0.3 added the escctrl's AO3: Jump to a Random Work script to adds a "Random Work" button (top right corner) when viewing works in a tag/filter or your Marked For Later list
  9. // @description Adds "Marked for Later" and "Bookmarked Fics" buttons on the home page of AO3, as well as creates a "random works" button in marked for later list
  10. // @author Ellililunch
  11. // @match http://archiveofourown.org/*
  12. // @match https://archiveofourown.org/*
  13. // @match http://archiveofourown.org/works*
  14. // @match https://archiveofourown.org/works*
  15. // @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js
  16. // @require https://code.jquery.com/jquery-2.2.4.js
  17. // @run-at document-idle
  18. // @grant none
  19. // @match *://*.archiveofourown.org/tags/*/works*
  20. // @match *://*.archiveofourown.org/works?*
  21. // @match *://*.archiveofourown.org/users/*/readings*show=to-read*
  22. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js
  23. // @license MIT
  24. // ==/UserScript==
  25.  
  26.  
  27.  
  28. //////Puts Marked for Later Button on AO3 Home Bar///////////////
  29. var $j = jQuery.noConflict();
  30.  
  31. $j(document).ready(function() {
  32.  
  33. // From https://greasyfork.org/en/scripts/406616-ao3-no-rekudos/code
  34. var greeting, username;
  35. greeting = document.getElementById('greeting');
  36. username = greeting.querySelector('a').href;
  37. // From https://stackoverflow.com/questions/43742732/use-javascript-or-jquery-to-create-an-href-url-using-variables-passed-in-through
  38. var dynamicContent = "archiveofourown.org";
  39. var username = ""+username+"";
  40. var url = ""+username+"/readings?show=to-read";
  41. $('#container').html('<a href="'+url+'">Marked for Later</a>');
  42.  
  43.  
  44. // From https://stackoverflow.com/questions/1145208/how-to-add-a-list-item-to-an-existing-unordered-list
  45. $("ul.primary.navigation.actions").append('<li><a href="'+url+'"><span class="dropdown-toggle">Marked for Later</span></a></li>');
  46. });
  47.  
  48.  
  49. ////////////////////////////////////////
  50. ///////////////AO3: Jump to a Random Work///////////// adds a "Random Work" button (top right corner) when viewing works in a tag/filter or your Marked For Later list
  51. ////////////////////////////////////////////////
  52. (function($) {
  53. 'use strict';
  54.  
  55. // add a button
  56. var button = document.createElement('li');
  57. button.innerHTML = '<a href="#">Random Work</a>';
  58. button.addEventListener("click", RandomWork);
  59. if (location.href.indexOf('show=to-read') > 0) document.querySelector('div#main.readings-index ul.navigation.actions').appendChild(button);
  60. else document.querySelector('div#main.works-index div.navigation.actions.module ul.user.navigation.actions').appendChild(button);
  61.  
  62. // when the button was pressed, read the number of works, pick a random one, and redirect there
  63. function RandomWork() {
  64.  
  65. // Find number of pages. content of second-to-last <li> tells us
  66. var pageCount = parseInt($('ol.pagination').first().find('li').last().prev().text() || 1);
  67.  
  68. // pick random whole number of the available pages
  69. const pageRandom = Math.floor((Math.random() * pageCount) + 1);
  70.  
  71. // figure out which page we're currently viewing
  72. var thisPage = location.search.match(/page=(\d)+/);
  73. thisPage = thisPage === null ? 1 : parseInt(thisPage[1]); // match only works if URL contained a page (i.e. if not on page 1)
  74.  
  75. // check: are we currently on the randomly chosen page?
  76. if (thisPage !== pageRandom) LoadRandomPage(pageRandom); // if not - read that page to find a random work link
  77. else Redirect2Work($('ol.work.index.group li.work.blurb')); // if yes - skip page loads, read a random work link from this page
  78. }
  79.  
  80. function LoadRandomPage(r) {
  81. // build the URL of the page to load
  82. var pageURL = location.search.indexOf('page=') > 0 ? location.href.replace(/page=(\d)+/, 'page='+r) // replace existing page number
  83. : location.href + (location.href.indexOf('?') > 0 ? '&' : '?') + 'page='+r; // add page number if not yet in URL search parameters
  84.  
  85. // grab the list of works from the page
  86. $.get(pageURL, function(response) {
  87. }).done(function(response) {
  88. Redirect2Work($(response).find('ol.work.index.group li.work.blurb'));
  89.  
  90. // if that sent us to jail, set the ao3jail marker
  91. }).fail(function(data, textStatus, xhr) {
  92. console.log("Random Work script has hit Retry later", data.status);
  93. return false;
  94. });
  95. }
  96.  
  97. function Redirect2Work(worksList) {
  98. // pick a random work from within the list
  99. var pick = Math.floor((Math.random() * worksList.length) + 1);
  100.  
  101. // read that random work's URL and title
  102. pick = $(worksList[pick-1]).find('h4 a').first();
  103. var path = $(pick).attr('href');
  104. var title = $(pick).text();
  105.  
  106. // jump to that work but warn the user
  107. alert('Redirecting you to a random work: '+title);
  108. window.location.assign(path);
  109. }
  110.  
  111. function HideClearHistory(){
  112. var btn;
  113. btn = document.getElementById('Clear History');
  114. btn.style.display = "none";
  115. }
  116.  
  117.  
  118. })(jQuery);
  119.  
  120. //////////////////////////////////////////
  121. ///////////////////////////////////////Put Bookmarks Button on AO3 Home//////////////////////////
  122. ///////////////////Puts the "Bookmarked Fics" button on the home page of AO3.
  123.  
  124. var $j = jQuery.noConflict();
  125.  
  126. $j(document).ready(function() {
  127.  
  128. // From https://greasyfork.org/en/scripts/406616-ao3-no-rekudos/code
  129. var greeting, username;
  130. greeting = document.getElementById('greeting');
  131. username = greeting.querySelector('a').href;
  132.  
  133. // From https://stackoverflow.com/questions/43742732/use-javascript-or-jquery-to-create-an-href-url-using-variables-passed-in-through
  134. var dynamicContent = "archiveofourown.org";
  135. var username = ""+username+"";
  136. var url = ""+username+"/bookmarks";
  137. $('#container').html('<a href="'+url+'">Bookmarked Fics</a>');
  138.  
  139.  
  140. // From https://stackoverflow.com/questions/1145208/how-to-add-a-list-item-to-an-existing-unordered-list
  141. $("ul.primary.navigation.actions").append('<li><a href="'+url+'"><span class="dropdown-toggle">Bookmarked Fics</span></a></li>');
  142.  
  143. });