AO3: [Wrangling] Sort Unwrangled Bin Links by Tag Age

change the Unwrangled bin links on the Wrangling Home page to sort by tag creation date

  1. // ==UserScript==
  2. // @name AO3: [Wrangling] Sort Unwrangled Bin Links by Tag Age
  3. // @namespace https://greasyfork.org/en/users/906106-escctrl
  4. // @description change the Unwrangled bin links on the Wrangling Home page to sort by tag creation date
  5. // @author escctrl
  6. // @version 1.2
  7. // @match *://*.archiveofourown.org/tag_wranglers/*
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. // CONFIGURATION OPTION
  13. // The bins will sort tags by age. Which direction should the bins sort, and on which page do you want to start wrangling?
  14. // "oldest first" = old -> new, go to the oldest tags on page 1
  15. // "oldest last" = new -> old, go to the oldest tags on the last page
  16. // "newest first" = new -> old, go to the newest tags on page 1
  17. // "newest last" = old -> new, go to the newest tags on the last page
  18. const url_mode = "newest first";
  19.  
  20. (function($) {
  21. 'use strict';
  22.  
  23. // loop through the unwrangled bins
  24. $('.assigned tbody tr td[title~="unwrangled"] a').each(function() {
  25.  
  26. let link = new URL($(this).prop('href'));
  27. let params = new URLSearchParams(link.search);
  28.  
  29. params.set('sort_column', 'created_at');
  30.  
  31. if (url_mode == "oldest first" || url_mode == "newest last") params.set('sort_direction', 'ASC');
  32. else params.set('sort_direction', 'DESC');
  33.  
  34. if (url_mode.includes('first')) params.set('page', '1');
  35. else params.set('page', Math.ceil(parseInt($(this).text(), 10)/20).toString()); // some math to find the last page in a bin
  36.  
  37. // status=X has to be the last parameter in the URL for compatibility with other scripts
  38. params.delete('status');
  39. params.append('status', 'unwrangled');
  40.  
  41. // create the new URL and set it on the <a>
  42. link.search = "?" + params.toString();
  43. $(this).prop('href', link.toString());
  44. });
  45. })(jQuery);