NarouRankingFilter

なろうのランキングにフィルター機能を追加

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NarouRankingFilter
// @namespace    drownia.narourankingfilter
// @version      1.1
// @description  なろうのランキングにフィルター機能を追加
// @author       Drownia
// @homepage https://twitter.com/Dr0wnia
// @match        https://yomou.syosetu.com/rank/list/type/*
// @match        https://yomou.syosetu.com/rank/isekailist/type/*
// @match        https://yomou.syosetu.com/rank/genrelist/type/*
// @require            https://openuserjs.org/src/libs/sizzle/GM_config.js
// @grant              GM_getValue
// @grant              GM_setValue
// @require       https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==

GM_config.init({
    'id': 'NarouRankingFilter',
    'title': '小説家になろう ランキングフィルター',
    'fields': {
        'whitelist_em': {
            'label': 'ホワイトリスト(完全一致)',
            'type': 'textarea',
            'default': ''
        },
        'blacklist_em': {
            'label': 'ブラックリスト(完全一致)',
            'type': 'textarea',
            'default': ''
        },
        'whitelist_pm': {
            'label': 'ホワイトリスト(部分一致)',
            'type': 'textarea',
            'default': ''
        },
        'blacklist_pm': {
            'label': 'ブラックリスト(部分一致)',
            'type': 'textarea',
            'default': ''
        }
    },
    'events': {
        'save': function(forgotten) {
            location.reload();
        }
    }
});

$(function() {
    $('#header').append('<li><a id = "open_config"><span style="color:blue">⚙️ランキングのフィルター設定を開く</span></a></li>')
    jQuery(document).on('click', '#open_config', function(){
        GM_config.open();
    });
    var blank_line_reg = /^\n$/gm
    GM_config.set('whitelist_em', GM_config.get('whitelist_em').replace(blank_line_reg, ''));
    GM_config.set('blacklist_em', GM_config.get('blacklist_em').replace(blank_line_reg, ''));
    GM_config.set('whitelist_pm', GM_config.get('whitelist_pm').replace(blank_line_reg, ''));
    GM_config.set('blacklist_pm', GM_config.get('blacklist_pm').replace(blank_line_reg, ''));
    var white_tag_em = GM_config.get('whitelist_em').replace('\n', '|');
    var black_tag_em = GM_config.get('blacklist_em').replace('\n', '|');
    var white_tag_pm = GM_config.get('whitelist_pm').replace('\n', '|');
    var black_tag_pm = GM_config.get('blacklist_pm').replace('\n', '|');
    if (black_tag_em == '') {black_tag_em = 'DUMMYTAG'}
    if (black_tag_pm == '') {black_tag_pm = 'DUMMYTAG'}
    var reg_white_em = new RegExp('(?<=<a href="/search\\.php\\?word=)(?=' + white_tag_em + ').+(?=">)');
    var reg_black_em = new RegExp('(?<=<a href="/search\\.php\\?word=)(?=' + black_tag_em + ').+(?=">)');
    var reg_white_pm = new RegExp('(?<=<a href="/search\\.php\\?word=).*(?=' + white_tag_pm + ').*(?=">)');
    var reg_black_pm = new RegExp('(?<=<a href="/search\\.php\\?word=).*(?=' + black_tag_pm + ').*(?=">)');

    var rank = $('div.rank_h').map(function(i, obj) {
        return [[obj, $('table.rank_table')[i]]];
    });
    var utf8_uri = new RegExp(
            "%[0-7][0-9A-F]|"+
            "%C[2-9A-F]%[89AB][0-9A-F]|%D[0-9A-F]%[89AB][0-9A-F]|"+
            "%E[0-F](?:%[89AB][0-9A-F]){2}|"+
            "%F[0-7](?:%[89AB][0-9A-F]){3}|"+
            "%F[89AB](?:%[89AB][0-9A-F]){4}|"+
            "%F[CD](?:%[89AB][0-9A-F]){5}","ig");
    var filtered_rank = rank.filter(function(i) {
        return (reg_white_em.test($($('tr:nth-child(4)')[i]).prop('outerHTML').replace(utf8_uri, function(whole){
                    return decodeURI(whole);
                })) &&
                !reg_black_em.test($($('tr:nth-child(4)')[i]).prop('outerHTML').replace(utf8_uri, function(whole){
                    return decodeURI(whole);
                })) &&
                reg_white_pm.test($($('tr:nth-child(4)')[i]).prop('outerHTML').replace(utf8_uri, function(whole){
                    return decodeURI(whole);
                })) &&
                !reg_black_pm.test($($('tr:nth-child(4)')[i]).prop('outerHTML').replace(utf8_uri, function(whole){
                    return decodeURI(whole);
                })));
    }).map(
        function(i, obj) {
            return [[obj[0], obj[1]]];
        }
    );

    var url_reg = /\/rank\/list\/type\/.*/;
    var modify_num = 1;
    if (url_reg.test(location.pathname)) {
        modify_num = 2
    }
    for (var i = 0; i <= 300; i++) {
        $('.ranking_list:nth-child(' + (i+modify_num) + ')').html($(filtered_rank[i]));
    }
})