Project Euler score offsets

Shows the difference between your score and your friends' on Project Euler.

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

  1. // ==UserScript==
  2. // @name Project Euler score offsets
  3. // @namespace http://mathemaniac.org/
  4. // @version 1.0.1
  5. // @description Shows the difference between your score and your friends' on Project Euler.
  6. // @match http://projecteuler.net/friends
  7. // @copyright 2013, Sebastian Paaske Tørholm
  8. // @require https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. var myScore;
  14. $('table.grid > tbody > tr').each(function () {
  15. if ($(this).children('td').last().html().match(/ /)) {
  16. myScore = 1 * $(this).children('td:nth-child(4)').text();
  17. }
  18. }).each(function () {
  19. if ($(this).children('th').length > 0) {
  20. $(this).children('th:nth-child(4)').after('<th>Offset</th>');
  21. } else {
  22. var scoreCell = $(this).children('td:nth-child(4)');
  23. var score = 1 * scoreCell.text();
  24. var diff = score - myScore;
  25. scoreCell.after(diff > 0 ? '<td style="color: green; text-align: center">+' + diff + '</td>' :
  26. diff < 0 ? '<td style="color: red; text-align: center">' + diff + '</td>' : '<td style="text-align: center">0</td>');
  27. }
  28. });
  29.  
  30. console.log(myScore);
  31. })();