Project Euler score offsets

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name       Project Euler score offsets
// @namespace  http://mathemaniac.org/
// @version    1.0.1
// @description  Shows the difference between your score and your friends' on Project Euler.
// @match      http://projecteuler.net/friends
// @copyright  2013-2017, Sebastian Paaske Tørholm
// @require    https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js
// @grant none
// ==/UserScript==

(function () {
    var myScore;
    $('table.grid > tbody > tr').each(function () {
        if ($(this).children('td').last().html().match(/ /)) {
            myScore = 1 * $(this).children('td:nth-child(4)').text();
        }
    }).each(function () {
        if ($(this).children('th').length > 0) {
            $(this).children('th:nth-child(4)').after('<th>Offset</th>');
        } else {
            var scoreCell = $(this).children('td:nth-child(4)');
            var score = 1 * scoreCell.text();
            var diff = score - myScore;
            scoreCell.after(diff > 0 ? '<td style="color: green; text-align: center">+' + diff + '</td>' :
                            diff < 0 ? '<td style="color: red; text-align: center">' + diff + '</td>' : '<td style="text-align: center">0</td>');
        }
    });
})();