Sort character lists alphabetically

The character lists are not sorted alphabetically, making finding characters in the more difficult than it should be. This script sorts them across the page.

当前为 2023-08-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Sort character lists alphabetically
  3. // @namespace http://f-list.net/c/Grimokk
  4. // @version 1.0
  5. // @description The character lists are not sorted alphabetically, making finding characters in the more difficult than it should be. This script sorts them across the page.
  6. // @author Grimokk
  7. // @match https://www.f-list.net/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=f-list.net
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. function _gmSortCharacterList(target) {
  18.  
  19. //https://stackoverflow.com/questions/13033472/ordering-a-select-with-javascript-without-jquery
  20. var sorted = Array.prototype.slice.call(target.options).sort(function(a, b) {
  21. if(a.label < b.label) return -1;
  22. if(a.label > b.label) return 1;
  23. return 0;
  24. });
  25.  
  26. for(var i = 0; i < sorted.length; i++) {
  27. target.add(sorted[i]);
  28. }
  29.  
  30. }
  31.  
  32. // get element used to fill in character lists on note page
  33. var _gmCharListNotes = document.getElementById("NoteVarCharacters");
  34. var _gmCharListOther = document.getElementsByName("character_id");
  35.  
  36. // only try sorting this if the element actually exists
  37. if(_gmCharListNotes) {
  38. _gmSortCharacterList(_gmCharListNotes);
  39. }
  40.  
  41. // only try sorting this if the element actually exists and is a select element
  42. if(_gmCharListOther && _gmCharListOther.length > 0 && _gmCharListOther[0].type === "select-one") {
  43. _gmSortCharacterList(_gmCharListOther[0]);
  44. }
  45.  
  46. })();