FFN Filters Auto-Select

Auto-selects fanfiction.net filters.

目前為 2015-02-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        FFN Filters Auto-Select
// @description Auto-selects fanfiction.net filters.
// @include     *://*.fanfiction.net/*
// @include     *://*.fictionpress.com/*
// @version     1.3
// @grant       none
// @copyright   2014+, Azurewren
// @history     1.3 Added comments/documentation.
// @history     1.2 Bug fixing.
// @history     1.1 Bug fixing.
// @history     1.0 First Version. 
// @namespace https://greasyfork.org/users/3972
// ==/UserScript==

// SETTING PREFERENCES
// All values should be exact. Setting name should not be the same name as on ffn. 
// Format: 'setting name for filter: "exact name as filter preference option",' 
settings = {
  language: 'English',
  rating: 'Rating: All',
  wordlength: '20K words'
}

var $ = unsafeWindow.$;
var filter = $('form[name="myform"]');

// SETTINGS
// For each setting up above, include a line for it below. Settingvariablename should be defined up above. 
// Format: 'ffn filtername: {prefer: settings.settingvariablename, default: '0'},'
var filteroptions = {
  languageid: {
    prefer: settings.language,
  default:
    '0'
  },
  censorid: {
    prefer: settings.rating,
  default:
    document.URL.search('fanfiction.net/community/') === - 1 ? '103' : '3'
  },
  length: {
    prefer: settings.wordlength,
  default:
    '0'
  }
};

function select(values, name) {
  var filteroption = filter.find('select[name="' + name + '"]');
  if (filteroption.val() === values.default) {
    var option = filteroption.find('option:contains("' + values.prefer + '")');
    return option.length && filteroption.val(option.val());
  }
}

if ($.map(filteroptions, select).some(function (a) {
  return a;
})) {
  filter.find('span.btn-primary, input[type="Submit"]').click();
}