Надо обычное расширение сделать. Нафига эти бубны с грисманкеем?
В чём преимущество обычного расширения?
В том, что оно устанавливается в один клик
Дело в том, что каждое установленное и запущенное расширение добавляет общий вес браузера в памяти компьютера. Для тех, у кого, например, ноутбук с 2-4 гигами памяти это важно. А скрипт ничего, практически, не добавляет к уже запущенному расширению и, соответственно, к общему весу браузера в памяти. Поэтому, я лично предпочитаю использовать скрипты.
Единственное, что не очень удобно в этом скрипте, то что не видно сколько у меня осталось смерита для отправки. Может кто-то сможет добавить эту функцию в скрипт?
Есть такая реализация скрипта от
EcuaMobi:
I have combined my
own suggestion as well as
sncc's and modified grue's script to implement them.
This is the result:
![Loading image...](https://ip.bitcointalk.org/?u=https%3A%2F%2Fi.imgur.com%2FL5xiXfT.png&t=665&c=sXgjVuIgPkx2aA)
The available sMerit points are shown. 'Available' is a link which opens the default
https://bitcointalk.org/index.php?action=merit;msg=30923337 (with the corresponding
msg) in a new window to keep the original functionality.
Here's the modified source. grue, feel free to update your original code if you like the change:
// ==UserScript==
// @name bitcointalk merit
// @namespace grue
// @include https://bitcointalk.org/index.php?topic=*
// @require https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js
// @version 1.1-em0.1
// @downloadURL https://grue.blob.core.windows.net/scripts/Merit.user.js?sv=2014-02-14&si=1&sr=c&sig=k%2BqstGBI3oQ8TrHfPWjS5HgjrazuDPmKJ6rYNs7rvRk%3D&.user.js
// @grant none
// ==/UserScript==
(() => {
var sMerit;
//get csrf token from the logout link
let sc = $('td.maintab_back a[href*="index.php?action=logout;sesc="').attr("href");
sc = /;sesc=(.*)/.exec(sc)[1];
//Added by EcuaMobi: Get remaining sMerit
$.post(
"https://bitcointalk.org/index.php?action=merit;msg=29048068"
).then((data) => {
sMerit = /You have <b>([0-9]+)<\/b> sendable/.exec(data)[1];
}).catch(() => sMerit = null);
//selector for the "+Merit" link
$('td.td_headerandpost div[id^=ignmsgbttns] a[href*="index.php?action=merit;msg="]')
.each((i, e) => {
const msgId = /msg=([0-9]+)/.exec(e.href)[1];
const $popup = $(['<div id="grue-merit-popup' + msgId +'" class="grue-merit-popup" style="position: absolute; right: 40px; background-color: #ddd; font-size: 13px; padding: 8px;border-width: 1px;border-color: black;border-style: solid;">',
' <form>',
' <div>',
' Merit points: <input size="6" name="merits" value="0" type="text"/>',
' </div>',
// Modified by EcuaMobi
' <div style="margin-top: 6px; "><span id="em-smerit-count' + msgId +'" style="font-size:11px;" /> <input value="Send" type="submit"></div>',
' </form>',
'</div>'
].join("\n"));
$popup.find("form").submit( (e) => {
e.preventDefault();
$popup.find('input[type="submit"]')
.prop("disabled", true)
.val("Sending...");
const merits = e.target.elements["merits"].value;
$.post(
"https://bitcointalk.org/index.php?action=merit",
{merits, msgID: msgId, sc}
).then((data) => {
//Error pages usually have this (rough heuristic)
if(data.includes("<title>An Error Has Occurred!</title")) {
throw "error";
}
//double check and see whether the post we merited was added to the list. Its msgId should be visible in the page source.
if(data.includes("#msg" + msgId)) {
alert("Merit added.");
$("#grue-merit-popup" + msgId).toggle(false);
// Added by EcuaMobi
if(sMerit!=null) { sMerit -= merits }
return;
}
alert("Server response indeterminate.");
})
.catch(() => alert("Failed to add merit."))
.always(() => {
$popup.find('input[type="submit"]')
.prop("disabled", false)
.val("Send");
});
});
$popup.insertAfter(e);
$(e).click((e) => {
e.preventDefault();
$("#grue-merit-popup" + msgId).toggle();
// Added by EcuaMobi
if(sMerit!=null) { $("#em-smerit-count" + msgId).html('<a href="https://bitcointalk.org/index.php?action=merit;msg='+msgId+'" target="_blank">Available:</a> <b>'+sMerit+'</b> ') };
});
});
$(".grue-merit-popup").toggle(false);
})();
I've clearly marked the modified code with either "Added by EcuaMobi" or "Modified by EcuaMobi". I also changed the version
A small limitation is that it queries the available sMerit points once (when the thread is loaded). It does subtract them when points are sent. However, if sMerit points are received the change won't be reflected unless the page is reloaded. That would require re-querying every time which I considered an overkill.
To install this version, you can just modify grue's script or install this from scratch:
https://openuserjs.org/scripts/EcuaMobi/bitcointalk_merit(grue, I assumed this code is open-source. If that's not the case, let me know to unpublish this)