Guest User

Untitled

a guest
May 20th, 2023
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         dota replies
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  перед отправкой поста нажать кнопку "replies"
  6. // @author       joepesch
  7. // @match        https://2ch.hk/vg/res/*.html
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=2ch.hk
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. const sub = (thId, str) => {
  13.     let data = $.ajax({
  14.         async: false,
  15.         url: `https://2ch.hk/vg/res/${thId}.json`,
  16.     }).responseJSON;
  17.     let posts = data.threads[0].posts;
  18.     let rev = {}
  19.     posts.forEach((e, i) => rev[e.num] = i + 1);
  20.     return str.replace(/>>(\d+)/, (...g) => rev[g[1]]);
  21. }
  22.  
  23. $(document).ready(function () {
  24.     const button_html = '<button type="button" class="dotareplies button desktop">replies</button>';
  25.     $(".postform").each(function () {
  26.         $(this).children(".postform__raw").first().append(button_html);
  27.     });
  28.     $(".dotareplies").click(function () {
  29.         let thId = location.pathname.match(/\d+/)[0];
  30.         $("#shampoo").val(sub(thId, $("#shampoo").val()));
  31.     });
  32. });
  33.  
Add Comment
Please, Sign In to add comment