12
\$\begingroup\$

You can load this Snippet using the Arbitrary Stack Snippet Loader, with the following parameters:

site = 'meta.codegolf';
postID = 5686;
isAnswer = false;
QUESTION_ID = ;

QUESTION_ID is for the question that the answers could be cracked (the cops thread), NOT for the question where the answers are cracking other answers. It doesn't matter where do you put the Snippet.

It requires the comment to contain a link with "cracked" (case insensitive) in the link text, so it wouldn't be a problem if they talk about cracking without posting a real crack, OR there is a "cracked" in the first line of the answer, since we couldn't edit the comment if it wasn't in the right format. And it apparently has more rules that I have forgotten.

var safe_list=[];
var uncracked_list=[];
var n=0;
var bycreation=function(x,y){return (x[0][0]<y[0][0])-(x[0][0]>y[0][0]);};
var bylength=function(x,y){return (x[0][1]>y[0][1])-(x[0][1]<y[0][1]);};
function u(l,o){
  jQuery(l[1]).empty();
  l[0].sort(o);
  for(var i=0;i<l[0].length;i++)
    l[0][i][1].appendTo(l[1]);
  if(l[0].length==0)
    jQuery('<tr><td colspan="3" class="message">none yet.</td></tr>').appendTo(l[1]);
}
function m(s) {
  if('error_message' in s)
    jQuery('#api_error').text('API Error: '+s.error_message);
}
function g(p) {
  jQuery.getJSON('//api.stackexchange.com/2.2/questions/' + QUESTION_ID + '/answers?page=' + p + '&pagesize=100&order=desc&sort=creation&site=codegolf&filter=!.Fjs-H6J36w0DtV5A_ZMzR7bRqt1e', function(s) {
    m(s);
    s.items.map(function(a) {
      var he = jQuery('<div/>').html(a.body).children().first();
      he.find('strike').text('');
      var h = he.text();
      if (!/cracked/i.test(h) && (typeof a.comments == 'undefined' || a.comments.filter(function(b) {
        var c = jQuery('<div/>').html(b.body);
        return /^cracked/i.test(c.text()) || c.find('a').filter(function() {
          return /cracked/i.test(jQuery(this).text())
        }).length > 0
      }).length == 0)) {
        var m = /^\s*((?:[^,;(\s]|\s+[^-,;(\s])+)\s*(?:[,;(]|\s-).*?([0-9]+)/.exec(h);
        var e = [[n++, m ? parseInt(m[2]) : null],
          jQuery('<tr/>').append(
            jQuery('<td/>').append(
              jQuery('<a/>').text(m ? m[1] : h).attr('href', a.link)),
            jQuery('<td class="score"/>').text(m ? m[2] : '?'),
            jQuery('<td/>').append(
              jQuery('<a/>').text(a.owner.display_name).attr('href', a.owner.link))
          )];
        if(/safe/i.test(h))
          safe_list.push(e);
        else
          uncracked_list.push(e);
      }
    });
    if (s.items.length == 100)
      g(p + 1);
    else {
      var s=[[uncracked_list, '#uncracked'], [safe_list, '#safe']];
      for(var i=0;i<2;i++)
        u(s[i],bylength);
      jQuery('#uncracked_by_length').bind('click',function(){u(s[0],bylength);return false});
      jQuery('#uncracked_by_creation').bind('click',function(){u(s[0],bycreation);return false});
    }
  }).error(function(e){
    m(e.responseJSON);
  });
}
g(1);
table th,
table td {
  padding: 5px;
}
th {
  text-align: left;
}
.score {
  text-align: right;
}
table a {
  display: block;
}
.main {
  float: left;
  margin-right: 30px;
}
.main h3,
.main div {
  margin: 5px;
}
.message {
  font-style: italic;
}
#api_error {
  color: red;
  font-weight: bold;
  margin: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/Sites/codegolf/all.css?v=7509797c03ea">
<div id="api_error"></div>
<div class="main">
<h3>Uncracked submissions</h3>
<table>
  <tr>
    <th>Language</th>
    <th class="score">Length</th>
    <th>User</th>
  </tr>
  <tbody id="uncracked"></tbody>
</table>
<div>Sort by:
  <a href="#" id="uncracked_by_length">length</a>
  <a href="#" id="uncracked_by_creation">creation</a>
</div>
</div>
<div class="main">
<h3>Safe submissions</h3>
<table>
  <tr>
    <th>Language</th>
    <th class="score">Length</th>
    <th>User</th>
  </tr>
  <tbody id="safe"></tbody>
</table>
</div>

\$\endgroup\$
  • \$\begingroup\$ I really don't understand your code, so how could I order the list from shortest to longest code? \$\endgroup\$ – Beta Decay Aug 12 '15 at 11:40
  • \$\begingroup\$ And by the way, this is great and saved me a huge amount of work :) \$\endgroup\$ – Beta Decay Aug 12 '15 at 12:09
  • 1
    \$\begingroup\$ @BetaDecay Changed to sort by length (and ungolfed the code). It was firstly used in this question. \$\endgroup\$ – jimmy23013 Aug 12 '15 at 16:10
  • \$\begingroup\$ Whoa, this is awesome. Excellent work, Jimmy! \$\endgroup\$ – Alex A. Aug 12 '15 at 19:43
1
\$\begingroup\$

Example usage

<script>site = 'meta.codegolf'; postID = 5686; isAnswer = false; QUESTION_ID = 40932;</script><script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script><script>jQuery(function(){var u='https://api.stackexchange.com/2.2/';if(isAnswer)u+='answers/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJeRCD';else u+='questions/'+postID+'?order=asc&sort=creation&site='+site+'&filter=!GeEyUcJFJO6t)';jQuery.get(u,function(b){function d(s){return jQuery('<textarea>').html(s).text()};function r(l){return new RegExp('<pre class="snippet-code-'+l+'\\b[^>]*><code>([\\s\\S]*?)</code></pre>')};b=b.items[0].body;var j=r('js').exec(b),c=r('css').exec(b),h=r('html').exec(b);if(c!==null)jQuery('head').append(jQuery('<style>').text(d(c[1])));if (h!==null)jQuery('body').append(d(h[1]));if(j!==null)jQuery('body').append(jQuery('<script>').text(d(j[1])))})})</script>

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .