RES filter button

Replaces "Join Subreddit" button on r/all/ with a button that filters the subreddit using Reddit Enhancement Suite (which needs to be installed).

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         RES filter button
// @version      0.2
// @description  Replaces "Join Subreddit" button on r/all/ with a button that filters the subreddit using Reddit Enhancement Suite (which needs to be installed).
// @author       cosmik_debree
// @include       http://reddit.com/*
// @include       https://reddit.com/*
// @include       http://*.reddit.com/*
// @include       https://*.reddit.com/*
// @namespace https://greasyfork.org/users/830718
// ==/UserScript==

(function() {
    'use strict';
    var cusid_ele = document.getElementsByClassName("subreddit-subscribe");
    var elems = [].slice.call(cusid_ele);
    // replaces all of the "Join subreddit" buttons with the filter subreddit button
    for (var i = 0; i < elems.length; ++i) { (function(i) {
        elems[i].removeAttribute("class");
        elems[i].removeAttribute("data-success-title");
        elems[i].title = elems[i].title.replace("Join", "Filter");
        elems[i].innerHTML = "➖";
        elems[i].onclick = function(){
            filter(elems[i].title.replace("Filter r/", ''));
        }})(i);
                                           }
}
)();
// somewhat janky, but opens the RES cmd line and pastes the cmd to filter the sub. if RES has an API to filter subs, this would be where it would be called.
async function filter(sub) {
    document.getElementById("RESSettingsButton").click();
    await new Promise(r => setTimeout(r, 200));
    document.getElementsByClassName("RESMenuItemButton res-icon")[1].click();
    var cmdLine = document.getElementById("keyCommandInput");
    cmdLine.value = "f " + sub;
    const ke = new KeyboardEvent('keydown', {
        bubbles: true, cancelable: true, key: "Enter"
    });
    cmdLine.dispatchEvent(ke);
}