Post
Topic
Board Разное
Merits 2 from 2 users
Topic OP
Скрипт для работы с Merit.
by
Xal0lex
on 27/02/2018, 18:52:36 UTC
⭐ Merited by zasad@ (1) ,madnessteat (1)
Оригинальная англотема: https://bitcointalk.org/index.php?topic=2833350.0

Это очень простой скрипт, который позволяет добавлять Мериты, не покидая страницу топика. После установки скрипта нажмите на ссылку «+ Merit», чтобы открыть/закрыть всплывающее окно.





Установка скрипта:

1. Если у вас ещё не установлено расширение для работы со скриптами в браузере, установить можно по ссылкам:


2. Установить (скачать) скрипт: Merit.user.js


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...

Here's the modified source. grue, feel free to update your original code if you like the change:
Code:
// ==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 ([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 = $(['
',
      '  
',
      '    
',
      '      Merit points: ',
      '    
',
 // Modified by EcuaMobi
      '    
',
      '  
',
      '
'
    ].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("An Error Has Occurred!</title")) {<br>          throw "error";<br>        }<br>        //double check and see whether the post we merited was added to the list. Its msgId should be visible in the page source.<br>        if(data.includes("#msg" + msgId)) {<br>          alert("Merit added.");<br>          $("#grue-merit-popup" + msgId).toggle(false);<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>  // Added by EcuaMobi<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>  if(sMerit!=null) { sMerit -= merits }<br>          return;<br>        }<br>        alert("Server response indeterminate.");<br>      })<br>      .catch(() => alert("Failed to add merit."))<br>      .always(() => {<br>        $popup.find('input[type="submit"]')<br>        .prop("disabled", false)<br>        .val("Send");<br>      });<br>    });<br>    $popup.insertAfter(e);<br>    <br>    $(e).click((e) => {<br>      e.preventDefault();<br>      $("#grue-merit-popup" + msgId).toggle();<br><span style="white-space: pre;"> </span>  // Added by EcuaMobi<br><span style="white-space: pre;"> </span>  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>    ') };<br>    });<br>  });<br>   $(".grue-merit-popup").toggle(false);<br>   <br>})();</div></div><br><div class="quoteheader"><a href="https://bitcointalk.org/index.php?topic=3033518.msg51974134#msg51974134">Quote from: Xal0lex on July 27, 2019, 10:10:59 PM</a></div><div class="quote"><span style="font-size: 10pt !important; line-height: 1.3em;"><b>Модификация скрипта для меритсорсов</b> от <a class="ul" href="https://bitcointalk.org/index.php?topic=2833350.msg51972715#msg51972715">ETFbitcoin</a>.</span><br><br><div class="codeheader">Code:</div><div class="code">// ==UserScript==<br>// @name        bitcointalk merit<br>// @namespace   grue<br>// @include     https://bitcointalk.org/index.php?topic=*<br>// @require     https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js<br>// @version     1.1.1<br>// @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<br>// @grant none<br>// ==/UserScript==<br><br>(() => {<br>  var sMerit;<br>  var source_sMerit;<br><br>  //get csrf token from the logout link<br>  let sc = $('td.maintab_back a[href*="index.php?action=logout;sesc="').attr("href");<br>  sc = /;sesc=(.*)/.exec(sc)[1];<br><br>  //Added by EcuaMobi: Get remaining sMerit<br>  $.post(<br><span style="white-space: pre;"> </span>"https://bitcointalk.org/index.php?action=merit;msg=29048068"<br>  ).then((data) => {<br>    sMerit = /You have <b>([0-9]+)<\/b> sendable/.exec(data)[1];<br>    source_sMerit = /The next ([0-9]+) merit you spend will come from your source/.exec(data)[1];<br>  }).catch(() => sMerit = null);<br><br>  //selector for the "+Merit" link<br>  $('td.td_headerandpost div[id^=ignmsgbttns] a[href*="index.php?action=merit;msg="]')<br>  .each((i, e) => {<br>    const msgId = /msg=([0-9]+)/.exec(e.href)[1];<br><br>    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;">',<br>      '  <form>',<br>      '    <div>',<br>      '      Merit points: <input size="6" name="merits" value="1" type="text"/>',<br>      '    </div>',<br><span style="white-space: pre;"> </span>  // Modified by EcuaMobi<br>      '    <div style="margin-top: 6px; "><span id="em-smerit-count' + msgId +'" style="font-size:11px;" /> <input value="Send" type="submit"></div>',<br>      '  </form>',<br>      '</div>'<br>    ].join("\n"));<br>    $popup.find("form").submit( (e) => {<br>      e.preventDefault();<br>      $popup.find('input[type="submit"]')<br>        .prop("disabled", true)<br>        .val("Sending...");<br>      const merits = e.target.elements["merits"].value;<br><br>      $.post(<br>        "https://bitcointalk.org/index.php?action=merit",<br>        {merits, msgID: msgId, sc}<br>      ).then((data) => {<br>        //Error pages usually have this (rough heuristic)<br>        if(data.includes("<title>An Error Has Occurred!</title")) {<br>          throw "error";<br>        }<br>        //double check and see whether the post we merited was added to the list. Its msgId should be visible in the page source.<br>        if(data.includes("#msg" + msgId)) {<br>          alert("Merit added.");<br>          $("#grue-merit-popup" + msgId).toggle(false);<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>  // Added by EcuaMobi<br><span style="white-space: pre;"> </span><span style="white-space: pre;"> </span>  if(sMerit!=null) { sMerit -= merits }<br>          return;<br>        }<br>        alert("Server response indeterminate.");<br>      })<br>      .catch(() => alert("Failed to add merit."))<br>      .always(() => {<br>        $popup.find('input[type="submit"]')<br>        .prop("disabled", false)<br>        .val("Send");<br>      });<br>    });<br>    $popup.insertAfter(e);<br><br>    $(e).click((e) => {<br>      e.preventDefault();<br>      $("#grue-merit-popup" + msgId).toggle();<br><span style="white-space: pre;"> </span>  // Added by EcuaMobi<br><span style="white-space: pre;"> </span>  if(sMerit!=null && source_sMerit==null) {<br>      $("#em-smerit-count" + msgId).html('<a href="https://bitcointalk.org/index.php?action=merit;msg='+msgId+'" target="_blank">Available:</a> <b>'+sMerit+'</b>    ')<br>    } else if (sMerit!=null && source_sMerit!=null) {<br>      $("#em-smerit-count" + msgId).html('<a href="https://bitcointalk.org/index.php?action=merit;msg='+msgId+'" target="_blank">Available (yours | source):</a> <b>'+sMerit+' | '+source_sMerit+'</b>    ')<br>    };<br>    });<br>  });<br>   $(".grue-merit-popup").toggle(false);<br>})();<br></div><br><img class="userimg" src="https://ip.bitcointalk.org/?u=https%3A%2F%2Fi.ibb.co%2F6syStGT%2F111.png&t=613&c=4-nWgtcrYav-HQ" alt border="0"><br></div><br><div class="quoteheader"><a href="https://bitcointalk.org/index.php?topic=3033518.msg52265704#msg52265704">Quote from: Xal0lex on August 25, 2019, 07:49:18 PM</a></div><div class="quote">Вышла <a class="ul" href="https://bitcointalk.org/index.php?topic=2833350.msg52249695#msg52249695">новая версия </a>скрипта от <a class="ul" href="https://bitcointalk.org/index.php?action=profile;u=359716">ETFbitcoin</a>.<br><br><img class="userimg" src="https://ip.bitcointalk.org/?u=https%3A%2F%2Fi.imgur.com%2F43TkPIF.png&t=613&c=VBEAvtxFXxusNQ" alt border="0"><br></div>