Fanfiction.net - Customize Default Result Filter

Override Fanfiction.net's default choices for result filters

目前為 2015-11-30 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Fanfiction.net - Customize Default Result Filter
  3. // @namespace ssokolow.com
  4. // @description Override Fanfiction.net's default choices for result filters
  5. // @version 3
  6. // @license MIT
  7. //
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_registerMenuCommand
  11. //
  12. // @noframes
  13. // @match *://www.fanfiction.net/*
  14. // ==/UserScript==
  15.  
  16. // TODO: Try to find a way to safely URL-match so I can minimize the number
  17. // of cases where I need to redirect and use @run-at document-start
  18. // for the rest.
  19. var has_filters = (document.getElementById('filters') !== null);
  20.  
  21. // Skip everything if this isn't a relevant page since we can't URL match them.
  22. if (has_filters) {
  23. // Let short-circuit eval. only call GM_getValue once on empty query string
  24. var preferred_filter;
  25.  
  26. if (window.location.search === "" &&
  27. (preferred_filter = GM_getValue('preferred_filter'))) {
  28. history.replaceState({}, '', preferred_filter);
  29. location.reload();
  30. } else {
  31. GM_registerMenuCommand("Save Current Filters as Default", function() {
  32. GM_setValue('preferred_filter', window.location.search);
  33. }, 'S');
  34. }
  35. }