reddit cubing competition result helper

Select a score and press "c" to show a text-box with the markdown needed for making the result list.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name       reddit cubing competition result helper
// @namespace  http://www.mathemaniac.org
// @version    1.0
// @description  Select a score and press "c" to show a text-box with the markdown needed for making the result list.
// @match      http://www.reddit.com/r/Cubers/comments/*/cubing_competition*/
// @copyright  2013-2017, Sebastian Paaske Tørholm
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js
// ==/UserScript==

$('html').keypress(function (event) {
    if (event.shiftKey || event.altKey || event.ctrlKey) return;

    if (event.charCode != 99) return; // 'c'

    var selection = window.getSelection();
    if (selection.rangeCount == 0) return;

    var p = selection.getRangeAt(0).startContainer.parentNode;
    var post = $(p).closest('div.entry');

    var username = $('a.author', post)[0].innerText;

    var line = '1. ' + selection.toString() + " - ["+username+"](/u/"+username+")";

    $(post).append('<div><input type="text" value="'+line+'" style="width: 400px;"/></div>');
});