Advertisement
Guest User

scriptoffset.js

a guest
Nov 22nd, 2012
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function setCookie (url, offset){
  2.         var ws=new Date();
  3.         if (!offset && !url) {
  4.                 ws.setMinutes(10-ws.getMinutes());
  5.             } else {
  6.                 ws.setMinutes(10+ws.getMinutes());
  7.             }
  8.         document.cookie="scriptOffsetUrl="+url+";expires="+ws.toGMTString();
  9.         document.cookie="scriptOffsetOffset="+offset+";expires="+ws.toGMTString();
  10.     }
  11.    
  12. function getCookie(name) {
  13.         var cookie = " " + document.cookie;
  14.         var search = " " + name + "=";
  15.         var setStr = null;
  16.         var offset = 0;
  17.         var end = 0;
  18.         if (cookie.length > 0) {
  19.             offset = cookie.indexOf(search);
  20.             if (offset != -1) {
  21.                 offset += search.length;
  22.                 end = cookie.indexOf(";", offset)
  23.                 if (end == -1) {
  24.                     end = cookie.length;
  25.                 }
  26.                 setStr = unescape(cookie.substring(offset, end));
  27.             }
  28.         }
  29.         return(setStr);
  30.     }
  31.  
  32. function showProcess (url, sucsess, offset, action) {
  33.         $('#url, #refreshScript').hide();
  34.         $('.progress').show();
  35.         $('#runScript').text('Стоп!');
  36.         $('.bar').text(url);
  37.         $('.bar').css('width', sucsess * 100 + '%');
  38.         setCookie(url, offset);
  39.  
  40.         $('#runScript').click(function(){
  41.                 document.location.href=document.location.href
  42.             });
  43.        
  44.         scriptOffset(url, offset, action);
  45.     }
  46.  
  47. function scriptOffset (url, offset, action) {
  48.         $.ajax({
  49.             url: "http://bfmn.ru/scriptoffset/scriptoffset.php",
  50.             type: "POST",
  51.             data: {
  52.                 "action":action
  53.               , "url":url
  54.               , "offset":offset
  55.             },
  56.             success: function(data){
  57.                 data = $.parseJSON(data);
  58.                 if(data.sucsess < 1) {
  59.                     showProcess(url, data.sucsess, data.offset, action);
  60.                     } else {
  61.                     setCookie();
  62.                     $('.bar').css('width','100%');
  63.                     $('.bar').text('OK');
  64.                     $('#runScript').text('Еще');
  65.                     }
  66.             }
  67.         });
  68.     }
  69.    
  70. $(document).ready(function() {
  71.    
  72.     var url = getCookie("scriptOffsetUrl");
  73.     var offset = getCookie("scriptOffsetOffset");
  74.    
  75.     if (url && url != 'undefined') {       
  76.             $('#refreshScript').show();
  77.             $('#runScript').text('Продолжить');
  78.             $('#url').val(url);
  79.             $('#offset').val(offset);
  80.         }
  81.    
  82.     $('#runScript').click(function() {
  83.        
  84.             var action = $('#runScript').data('action');
  85.             var offset = $('#offset').val();
  86.             var url = $('#url').val();
  87.            
  88.             if ($('#url').val() != getCookie("scriptOffsetUrl")) {
  89.                     setCookie();
  90.                     scriptOffset(url, 0, action);
  91.                 } else {
  92.                     scriptOffset(url, offset, action);
  93.                 }
  94.             return false;
  95.         });
  96.        
  97.     $('#refreshScript').click(function() {
  98.        
  99.             var action = $('#runScript').data('action');
  100.             var url = $('#url').val();
  101.        
  102.             setCookie();
  103.             scriptOffset(url, 0, action);
  104.             return false;
  105.         });
  106.        
  107. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement