Advertisement
DaCurse

50/50 Generator (Client Side)

Jul 8th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Website Link: https://5050.iserv.ml
  2.  
  3. const FFModule = (function() {
  4.            
  5.     var form = $('#gnrt-form'),
  6.     firstLink = $('#link-1'),
  7.     secondLink = $('#link-2'),
  8.     resultInp = $('#link-3'),
  9.     submitBtn = $('#btn-submit'),
  10.     vanillaInp = resultInp.get(0),
  11.    
  12.     result = '',
  13.    
  14.     init = function() {
  15.         form.submit(function(event) {
  16.             event.preventDefault();
  17.             var link1 = encodeURI(firstLink.val());
  18.             var link2 = encodeURI(secondLink.val());
  19.            
  20.             if(link1.length === 0 || link2.length === 0) {
  21.                 resultInp.val('One of the links is invalid.');
  22.                 return false;
  23.             }
  24.            
  25.             var long = link1 + ';' + link2;
  26.            
  27.             submitBtn.attr('disabled', true);
  28.            
  29.             $.post('shorten.php', {'url': long}).done(function(data) {
  30.                 data = JSON.parse(data);
  31.                 if(data.error) {
  32.                     console.info('Error:', data.message || data.msg);
  33.                     result = 'Error, please try again.';
  34.                 } else result = data.id;
  35.                
  36.                 submitBtn.attr('disabled', false);
  37.                 resultInp.val(result);
  38.             });
  39.            
  40.         });
  41.     },
  42.  
  43.     cpy = function() {
  44.         vanillaInp.select();
  45.         document.execCommand("copy");
  46.     };
  47.    
  48.     return {
  49.         Initialize: init,
  50.         Copy: cpy
  51.     }
  52.            
  53. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement