Guest User

SA:MP Forum auto post reply

a guest
Jan 19th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        SA:MP Auto post reply
  3. // @namespace   SAMP
  4. // @description Auto reply on thread when it's possible
  5. // @include     http://forum.sa-mp.com/showthread.php*
  6. // @include     https://forum.sa-mp.com/showthread.php*
  7. // @require       http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  8. // @version     1
  9. // @grant       none
  10. // @authro coapsyfactor
  11. // ==/UserScript==
  12. $(document).ready(function () {
  13.   var form = $('#qrform'),
  14.       regex = new RegExp(/[A-Z]*([0-9])\w+/g),
  15.       errorMsg = null,
  16.       waitTimeout = null;
  17.  
  18.   if (form.length == 0) {
  19.     return;
  20.   }
  21.  
  22.   form.on('submit', function (e) {    
  23.     var counter = 0, waitTime;
  24.    
  25.     errorMsg = {
  26.        length: 0
  27.     };
  28.    
  29.     try {
  30.       clearTimeout(waitTimeout);
  31.     } catch (e) {}
  32.    
  33.     var interval = setInterval(function () {
  34.       if (counter == 10) {
  35.         clearInterval(interval);
  36.         counter = 0;
  37.         return;
  38.       }
  39.      
  40.       errorMsg = $('#qr_error_td li');
  41.      
  42.       if (errorMsg.length) {
  43.         clearInterval(interval);
  44.        
  45.         errorMsg.filter(function () {
  46.           return regex.test($(this).html());
  47.         });
  48.        
  49.         waitTime = parseInt(new String($(errorMsg[0]).text()).match(/[A-Z]*([0-9])\w+/g)[1]) + 3;
  50.        
  51.         if (!waitTimeout) {
  52.           var timeout = setTimeout(function () {
  53.             clearInterval(interval);
  54.             clearTimeout(timeout);
  55.            
  56.             if ($(form).find('textarea').val().length > 4) {
  57.               $(form).submit();
  58.             }
  59.           }, waitTime * 1000);
  60.         }
  61.       } else {
  62.         counter++;
  63.       }
  64.     }, 1000);
  65.   });
  66. });
Advertisement
Add Comment
Please, Sign In to add comment