Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Sidebar Answer Status
- // @namespace https://stackexchange.com/users/305991/jason-c
- // @version 1.0
- // @description Show answer status of questions in sidebar.
- // @author You
- // @match https://meta.stackexchange.com/questions/*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- showIfAnswered(getAnswerStatus(getSidebarQuestions()));
- function getSidebarQuestions () {
- var qs = [];
- $('div.linked div.answer-votes, div.related div.answer-votes').each(function (_, obj) {
- var url = $(obj).parent().attr('href');
- var qid = /\/q\/([0-9]*)/.exec(url);
- if (qid) {
- qs[qid[1]] = {
- id: qid[1],
- votes: $(obj),
- link: $(obj).parent()
- };
- }
- });
- return qs;
- }
- function getAnswerStatus (qs) {
- var site = document.location.host;
- var ids = Object.keys(qs).join(';');
- var url = `//api.stackexchange.com/2.2/questions/${ids}?order=desc&sort=activity&site=${site}&filter=!4(YqyYcHA.0whnoIN`;
- $.getJSON(url, function (r) {
- for (var item of r.items)
- qs[item.question_id].status = item;
- });
- return qs;
- }
- function showIfAnswered (qs) {
- console.log(qs);
- for (var q of Object.values(qs)) {
- console.log(q);
- console.log(`q.id = ${q.id}`);
- console.log(`q.status = ${q.status}`);
- /*
- if (q.status.is_answered) {
- q.votes.css('border', '1px solid black');
- q.link.attr('title', `Answered (${q.status.answer_count})`);
- } else {
- q.link.attr('title', `Unanswered (${q.status.answer_count})`);
- }*/
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement