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).

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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);
}