Enhanced merit UI [1.3]I had free time, so i decide to make few changes.
Changelog :
- Update jQuery to 3.4.1
- New feature : one-click sMerit send
- New feature : check sMerit amount when click "+Merit" (experemental, disabled by default)
- Change input type to "number" to allow scroll
- Change code structure
- Show text "Getting sMerit amount..." when still checking sMerit amount, re-open pop-up to show sMerit amount
Unofficial full changelog (for history/tracking purpose) :
# RELEASE NOTES
## Version 1.3
* Update jQuery to 3.4.1
* New feature : one-click sMerit send
* New feature : check sMerit amount when click "+Merit" (experemental, disabled by default)
* Change input type to "number" to allow scroll
* Change code structure
* Show text "Getting sMerit amount..." when still checking sMerit amount, re-open pop-up to show sMerit amount
## Version 1.1.2
* Remove @downloadURL to prevent the script update itself to grue's code which don't show personal/source sMerit amount
* Fix Amount of personal sMerit is deducted rather than source sMerit when source sMerit is available
## Version 1.1.1
* Show both personal and source sMerit for merit source
* Change UI for merit source
## Version 1.1-em0.1
* The available sMerit points are shown
## Version 1.1
* Fix csrf token not working when quick reply is disabled
## Version 1.0
* Initial Release
Notes :
- There's delay when open/close popup if you enable feature check sMerit amount when click "+Merit"
- If you want to change amount of one-click sMerit value, change value inside oneClick_amount. Example :
oneClick_amount = [1, 2, 3, 4, 5, 10, 20, 50]
- Only tested on Mozilla Firefox with Tampermonkey
// ==UserScript==
// @name bitcointalk merit
// @version 1.3
// @author grue, minifrij, EcuaMobi, ETFbitcoin
// @source https://github.com/grue0/bitcointalk-scripts/
// @source https://bitcointalk.org/index.php?topic=2833350.0;0
// @description A very simple userscript that allows you to add merit without leaving the page
// @include https://bitcointalk.org/index.php?topic=*
// @require https://code.jquery.com/jquery-3.4.1.min.js
// @grant none
// ==/UserScript==
(() => {
var sMerit, source_sMerit, check_onClick = false, oneClick_amount = [1, 2, 5, 10, 50]
function check_sMerit(msgId){
// Added by EcuaMobi
$.post(
"https://bitcointalk.org/index.php?action=merit;msg=29048068"
).then((data) => {
sMerit = /You have ([0-9]+)<\/b> sendable/.exec(data)[1]
source_sMerit = /The next ([0-9]+) merit you spend will come from your source/.exec(data)[1]
show_popup(msgId)
}).catch(() => sMerit = null)
}
function show_popup(msgId){
if(sMerit!=null && source_sMerit==null) {
$("#em-smerit-count" + msgId).html('Available: '+sMerit+' ')
} else if (sMerit!=null && source_sMerit!=null) {
$("#em-smerit-count" + msgId).html('Available (yours | source): '+sMerit+' | '+source_sMerit+' ')
}else{
$("#em-smerit-count" + msgId).html('Getting sMerit amount... ')
}
$("#grue-merit-popup" + msgId).toggle()
}
// 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];
// Get remaining sMerit
check_sMerit()
// 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]
let oneClick_html = `
One-click send :
`
oneClick_amount.forEach((amount) => {
oneClick_html += `
`
})
const $popup = $([''
].join("\n"))
$popup.find("form").submit( (e) => {
e.preventDefault()
$popup.find('.sendButton')
.prop("disabled", true)
.val("Sending...")
$popup.find('.oneClick')
.prop("disabled", true)
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("
An Error Has Occurred! 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)
if(!check_onClick){
if(source_sMerit!=null && source_sMerit-merits>=0){
source_sMerit -= merits
}else if(source_sMerit!=null && source_sMerit>0){
sMerit -= merits-source_sMerit
source_sMerit = 0
}else if(sMerit!=null){
sMerit -= merits
}
}
return
}
alert("Server response indeterminate.")
})
.catch(() => alert("Failed to add merit."))
.always(() => {
$popup.find('.sendButton')
.prop("disabled", false)
.val("Send")
$popup.find('.oneClick')
.prop("disabled", true)
})
})
$popup.insertAfter(e)
$(e).click((e) => {
e.preventDefault()
if(check_onClick){
check_sMerit(msgId)
}else{
show_popup(msgId)
}
})
})
$(".grue-merit-popup").toggle(false)
})()