Reddit RES Style Class

Adds class to html for subreddit RES style on/off

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit RES Style Class
// @namespace    http://your.homepage/
// @version      1.0
// @description  Adds class to html for subreddit RES style on/off
// @author       muffleyd
// @match        http*://*.reddit.com/r/*
// @grant        none
// @run-at document-body
// ==/UserScript==

var classname = 'no-subr-style'
var classname2 = 'yes-subr-style'
var $html = $('html')
$html.addClass(classname2)

window.addEventListener ("load", function () {

var toggleStyle = function () {
    $html.removeClass(classname).removeClass(classname2)
    if ($('head link[title="applied_subreddit_stylesheet"]').length == 0) {
        $html.addClass(classname)
    } else {
        $html.addClass(classname2)
    }
    /*if ($el.length) {
        if (!$el[0].checked) {
            $html.addClass(classname)
        } else {
            $html.addClass(classname2)
        }
    }*/
}

var $el = $('')
var refresh$el = function () {
    $el.off('click', toggleStyle)
    $el = $('.res-sr-style-toggle > input[type=checkbox]')
    if ($el.length) {
        $el.on('change', toggleStyle)
    }
}

document.addEventListener('visibilitychange', function () {
    if (!document.hidden) {
        refresh$el()
        toggleStyle()
    }
})

refresh$el()
toggleStyle()

})