Advertisement
Guest User

Untitled

a guest
May 29th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Sidebar Answer Status
  3. // @namespace    https://stackexchange.com/users/305991/jason-c
  4. // @version      1.0
  5. // @description  Show answer status of questions in sidebar.
  6. // @author       You
  7. // @match        https://meta.stackexchange.com/questions/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     showIfAnswered(getAnswerStatus(getSidebarQuestions()));
  15.  
  16.     function getSidebarQuestions () {
  17.  
  18.         var qs = [];
  19.  
  20.         $('div.linked div.answer-votes, div.related div.answer-votes').each(function (_, obj) {
  21.             var url = $(obj).parent().attr('href');
  22.             var qid = /\/q\/([0-9]*)/.exec(url);
  23.             if (qid) {
  24.                 qs[qid[1]] = {
  25.                     id: qid[1],
  26.                     votes: $(obj),
  27.                     link: $(obj).parent()
  28.                 };
  29.             }
  30.         });
  31.  
  32.         return qs;
  33.  
  34.     }
  35.  
  36.     function getAnswerStatus (qs) {
  37.  
  38.         var site = document.location.host;
  39.         var ids = Object.keys(qs).join(';');
  40.         var url = `//api.stackexchange.com/2.2/questions/${ids}?order=desc&sort=activity&site=${site}&filter=!4(YqyYcHA.0whnoIN`;
  41.  
  42.         $.getJSON(url, function (r) {
  43.             for (var item of r.items)
  44.                 qs[item.question_id].status = item;
  45.         });
  46.  
  47.         return qs;
  48.  
  49.     }
  50.  
  51.     function showIfAnswered (qs) {
  52.        
  53.         console.log(qs);
  54.        
  55.         for (var q of Object.values(qs)) {
  56.             console.log(q);
  57.             console.log(`q.id = ${q.id}`);
  58.             console.log(`q.status = ${q.status}`);
  59.             /*
  60.             if (q.status.is_answered) {
  61.                 q.votes.css('border', '1px solid black');
  62.                 q.link.attr('title', `Answered (${q.status.answer_count})`);
  63.             } else {
  64.                 q.link.attr('title', `Unanswered (${q.status.answer_count})`);
  65.             }*/
  66.         }
  67.    
  68.     }
  69.  
  70. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement