Puzzling.SE Empuzzler

Hide answers and comments on Puzzling.SE questions until you want to see them.

目前为 2014-10-08 提交的版本。查看 最新版本

// ==UserScript==
// @name        Puzzling.SE Empuzzler
// @namespace   https://gf.qytechs.cn/users/5615-doppelgreener
// @description Hide answers and comments on Puzzling.SE questions until you want to see them.
// @grant       none
// @include     http://puzzling.stackexchange.com/questions/*
// @version     0.1
// ==/UserScript==


// CSS styles needed
var styles = [];
styles.push("body:not(.show-comments) #question .comments { display: none; }");
styles.push("body:not(.show-comments) #question .comments-link { display: none; }");
styles.push("body:not(.show-comments) #question .bounty-link { display: none; }");
styles.push("body:not(.show-answers) #answers { display: none; }");


var main = function () {

    function makeButton(buttonText, classToAdd) {
        return $('<button>')
            .prop('type', 'button')
            .text(buttonText)
            .click(function() {
                $('body').addClass(classToAdd);
                $(this).remove();
            });
    }

    $(window).load(function() {
        var rev = $('<div>')
            .prop('id', 'empuzzler-revealers');

        rev.append(makeButton("Show comments on question", 'show-comments'));
        rev.append(makeButton("Show answers", 'show-answers'));

        rev.insertAfter('#question');
    });

};

//
// Inject content into the page
//

// JavaScript
var script = document.createElement('script');
script.type = 'text/javascript';
script.id = 'empuzzler-script'
script.textContent = '(' + main.toString() + ')();';
document.body.appendChild(script);

// CSS styles, borrowed from Stack Overflow Unofficial Patch:
var styleElem = document.createElement('style');
styleElem.id = 'empuzzler-styles';
styleElem.type = 'text/css';
var code = "";
for (var id in styles) {
  code += styles[id] + "\n";
}
styleElem.textContent = code.replace( /[}] */g, "}\n" )
var head = document.head || document.documentElement;
head.appendChild(styleElem);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址