// ==UserScript== // @name Reddit Reveal // @author buddydvd // @description Reveal hidden information on reddit // @namespace Reddit Revealer // @include http://www.reddit.com/* // @include http://www.baconbuzz.com/* // @include http://reddit.destructoid.com/* // @include http://www.thecutelist.com/* // @include http://reddit.independent.co.uk/* // @include http://www.redditgadgetguide.com/* // @include http://www.weheartgossip.com/* // @include http://www.idealistnews.com/* // @include https://www.reddit.com/* // @include https://www.baconbuzz.com/* // @include https://reddit.destructoid.com/* // @include https://www.thecutelist.com/* // @include https://reddit.independent.co.uk/* // @include https://www.redditgadgetguide.com/* // @include https://www.weheartgossip.com/* // @include https://www.idealistnews.com/* // @version 1.0 // @downloadURL none // ==/UserScript== function reveal() { var l = window.document.location, h = l.href, q = l.search, u = h.substring(0, h.length - q.length) + ".json" + q; $.getJSON(u, function (json_data) { var dom_data = (function () { var result = {}, key; $.each($(".thing"), function () { var thingDom = this; if ($(this).css("display") === "none") { return; } $.each(this.className.split(" "), function () { if (this.indexOf("id-") === 0) { var thing_type_name = this.substr(3).split("_"); if (typeof(result[thing_type_name[0]]) === "undefined") { result[thing_type_name[0]] = []; } result[thing_type_name[0]].push({ name: thing_type_name[1], domObj: thingDom }); } }); }); return result; })(); var json_result = {}; function gather_data(json_data) { var crawl = function (obj) { if (obj && obj.length) { $.each(obj, function () { crawl(this); }); } else if (typeof(obj) === "object") { var kind = obj.kind; var data = obj.data; if (kind) { if (kind === "Listing") { crawl(data.children); } else if (data) { if (typeof(json_result[kind]) === "undefined") { json_result[kind] = {}; } json_result[kind][data.id] = data; if (kind === "t1" && data.replies) { crawl(data.replies); } } } } }; crawl(json_data); } gather_data(json_data); var enable_source = function (entry, text) { if (entry.find(".usertext-edit").size() > 0 || entry.find(".usertext-body").size() === 0) { return; } entry.find(".usertext-body").after("
"); entry.find(".flat-list.buttons").append("
  • source
  • "); }; var get_upvote_downvote_html = function (data) { var rv = " ("; rv += "+" + data.ups + "/"; rv += "-" + data.downs + ""; rv += ") "; return rv; }; var update_ui = function () { if (dom_data.t1) { $.each(dom_data.t1, function () { var id = this.name; var domObj = this.domObj; var data = json_result.t1[id]; if (!data) { return; } var entry = $(domObj).children(".entry"); entry.find(".score.likes").after(get_upvote_downvote_html(data)); enable_source(entry, data.body); }); } var update_t3_ui = function (domObj, data) { var thing = $(domObj); var entry = thing.children(".entry"); var midcol = thing.children(".midcol"); var score = data.score; // reveal up/down vote score entry.find(".reddit-comment-link, .tagline").prepend(get_upvote_downvote_html(data)); // reveal mark down source enable_source(entry, data.selftext); // reveal vote score if (midcol.hasClass("likes")) { score--; } if (midcol.hasClass("dislikes")) { score++; } midcol.find(".score.likes").text(score + 1); midcol.find(".score.unvoted").text(Math.max(0, score)); // min score is 0 midcol.find(".score.dislikes").text(Math.max(0, score - 1)); // min score is 0 }; if (dom_data.t3) { $.each(dom_data.t3, function () { var name = this.name; var domObj = this.domObj; var data = json_result.t3[name]; if (!data) { $.getJSON("/by_id/t3_" + name + ".json", function (json_data) { update_t3_ui(domObj, json_data.data.children[0].data); }); return; } else { update_t3_ui(domObj, data); } }); } }; update_ui(); }); $(".button").on("click", function(ev) { console.log(this.id); if (this.id.indexOf("more_t1_") === 0) { var id = this.id.split("_")[2]; console.log(id); } }); $(".author").on("mouseover", function (ev) { var username = $(this).text(); var rev = $(this).next(".revelation"); if (rev.size() === 0) { var tip = $(""); $(this).after(tip); $.getJSON("/user/" + username + "/about.json", function (a) { tip.html(" (" + a.data.link_karma + " link karma," + " " + a.data.comment_karma + " comment karma, " + " " + parseInt((((new Date()).getTime() / 1000) - a.data.created_utc) / 86400, 10) + " days) "); }); } else { rev.css("display", ""); } }).on("mouseout", function (ev) { $(this).next(".revelation").css("display", "none"); }); } (function () { var s = document.createElement('script'); s.textContent = "(" + reveal.toString() + ')();'; document.head.appendChild(s); })();