Fanfiction.net - Customize Default Result Filter

Override Fanfiction.net's default choices for result filters

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

  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 2
  6. // @license MIT
  7. //
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_registerMenuCommand
  11. //
  12. // @compatible firefox Tested regularly under Greasemonkey.
  13. // @compatible chrome Tested occasionally under Tampermonkey.
  14. //
  15. // @noframes
  16. // @match *://www.fanfiction.net/*
  17. // ==/UserScript==
  18.  
  19. // TODO: Try to find a way to safely URL-match so I can minimize the number
  20. // of cases where I need to redirect and use @run-at document-start
  21. // for the rest.
  22. var has_filters = (document.getElementById('filters') !== null);
  23.  
  24. // Skip everything if this isn't a relevant page since we can't URL match them.
  25. if (has_filters) {
  26. // Let short-circuit eval. only call GM_getValue once on empty query string
  27. var preferred_filter;
  28.  
  29. if (window.location.search === "" &&
  30. (preferred_filter = GM_getValue('preferred_filter'))) {
  31. window.location.search = preferred_filter;
  32. } else {
  33. GM_registerMenuCommand("Save Current Filters as Default", function() {
  34. GM_setValue('preferred_filter', window.location.search);
  35. }, 'S');
  36. }
  37. }