Fanfiction.net - Customize Default Result Filter

Override Fanfiction.net's default choices for result filters

当前为 2018-09-05 提交的版本,查看 最新版本

  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 5
  6. // @license MIT
  7. //
  8. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  9. //
  10. // @grant GM_getValue
  11. // @grant GM.getValue
  12. // @grant GM_setValue
  13. // @grant GM.setValue
  14. // @grant GM_registerMenuCommand
  15. // @grant GM.registerMenuCommand
  16. //
  17. // @noframes
  18. // @match *://www.fanfiction.net/*
  19. // ==/UserScript==
  20.  
  21. (async function() {
  22. // Skip everything if this isn't a relevant page since we can't URL-match them.
  23. if (document.getElementById('filters')) {
  24. // Let short-circuit eval only call GM_getValue once on empty query string
  25. let preferred_filter;
  26.  
  27. if (window.location.search === "" &&
  28. (preferred_filter = await GM.getValue('preferred_filter'))) {
  29. // Make it more clear when the page hasn't yet reloaded
  30. document.querySelector('body').style.opacity = 0.2;
  31.  
  32. history.replaceState({}, '', preferred_filter);
  33. location.reload();
  34. } else {
  35. // Work around bad interaction between Firefox and replaceState+reload
  36. let filter_form = document.querySelector('#filters #myform')
  37. if (filter_form) { filter_form.reset(); }
  38.  
  39. GM.registerMenuCommand("Save Current Filters as Default", function() {
  40. GM.setValue('preferred_filter', window.location.search);
  41. }, 'S');
  42. }
  43. }
  44. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址