2017-12-12 15 views
-1

コンソールを使用して1つのサイトに残っている時間を変更しようとするときに問題が発生します。Javascriptタイマーの援助

次のページに進むことができるように、残りの時間をゼロに設定したいと考えています。

私は、次のページに進むために設定する必要があることが複数あると考えています。

下記のコードを参照してください。提供できるヘルプがあれば幸いです。

var pageLoaded = 0; 
 
var timerStatus = 'pending'; 
 
var secondsRemaining = -1; 
 
var secondsElapsed = -1; 
 
var startTicks = 0; 
 
var errorCount = 0; 
 
var estimatedSecondsRemaining = -1; 
 
var zeroTimeCounter = 0; 
 
var intervalIdUpdateBothTimers; 
 
var nonLinearGuid = null; 
 

 
$(document).ready(function() { 
 
    setInterval('AutoSave()', 120000); 
 
    intervalIdUpdateBothTimers = setInterval('UpdateBothTimers()', 1000); 
 

 
    if (timerStatus == 'pending') { 
 
    
 
     var totaltimeclock = document.getElementById('TotalTimeClock'); 
 
     if (totaltimeclock != null) { 
 
      document.getElementById('TotalTimeClock').innerHTML = '-- \: -- \: --'; 
 
     } 
 

 
     var timeremainingclock = document.getElementById('TimeRemainingClock'); 
 
     if (timeremainingclock != null) { 
 
      document.getElementById('TimeRemainingClock').innerHTML = '-- \: -- \: --'; 
 
     } 
 

 
     StartTimer(); 
 
    } 
 

 
}); 
 

 
function loaded(i,f) { 
 
\t if (document.getElementById && document.getElementById(i) != null) 
 
\t { 
 
\t  f(); 
 
\t } 
 
\t else if (!pageLoaded) setTimeout('loaded(\''+i+'\','+f+')',100); 
 
} 
 

 
function SuspendTimer() { 
 
    UpdateBothTimers(); 
 
    
 
    if (timerStatus == 'active') { 
 
     var data = "s=2&cp=" + this.location.pathname + "&nlg=" + GetNonLinearGuid(); 
 
     timerStatus = 'suspended'; 
 

 
     $.ajax({ 
 
      type: "POST", 
 
      url: "/Courses/ajax/CourseData.aspx", 
 
      data: data, 
 
      success: displayTime, 
 
      async: false 
 
     }); 
 

 
     clearInterval(intervalIdUpdateBothTimers); 
 
    } 
 
    
 
} 
 

 
function AutoSave() 
 
{ 
 
    if (timerStatus == 'active') 
 
    { 
 
     SaveTime(); 
 
    } 
 
} 
 

 
function SaveTime() 
 
{ 
 
    var data = ''; 
 
    if (typeof window.IsScormPage === 'undefined') 
 
    { 
 
     data = "cp=" + this.location.pathname + "&sp=false"; 
 
    } 
 
    else 
 
    { 
 
     data = "cp=" + this.location.pathname + "&sp=true"; 
 
    } 
 

 
    data += "&nlg=" + GetNonLinearGuid(); 
 

 
    $.ajax({ 
 
\t \t type: "POST", 
 
\t \t url: "/Courses/ajax/CourseData.aspx", 
 
\t \t data: data, 
 
\t \t success: displayTime, 
 
\t \t async: false 
 
\t }); 
 
} 
 

 
function StartTimer() 
 
{ 
 
    timerStatus = 'active'; 
 

 
    SetNonLinearGuid(); 
 
    SaveTime(); 
 
} 
 

 
// Sets the nonLinearGuid with the one in the DOM 
 
// the GUID was generated in the server side and 
 
// passed it to the client side (DOM) 
 
function SetNonLinearGuid() 
 
{ 
 
    var $nonLinearGuid = $("#nonLinearGuid"); 
 

 
    if ($nonLinearGuid === undefined) 
 
    { 
 
     $nonLinearGuid = $("input[name=nonLinearGuid]"); 
 
    } 
 

 
    if ($nonLinearGuid.length) 
 
    { 
 
     nonLinearGuid = $nonLinearGuid.val() || null; 
 
     window.nonLinearGuid = window.nonLinearGuid || nonLinearGuid; 
 
    } 
 
} 
 

 
function GetNonLinearGuid() { 
 
    var nlg = (window.NonLinearGuid || nonLinearGuid), 
 
     admin = getQueryStringByName("admin", parent.window.location.href) || ""; 
 

 
    if (admin.toLowerCase() == "d3v") { 
 
     printNonLinearGuid(nlg); 
 
    } 
 

 
    return nlg; 
 
} 
 

 
function getQueryStringByName(name, url) { 
 
    if (!url) url = window.location.href; 
 
    name = name.replace(/[\[\]]/g, '\\$&'); 
 
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), 
 
     results = regex.exec(url); 
 
    if (!results) return null; 
 
    if (!results[2]) return ''; 
 
    return decodeURIComponent(results[2].replace(/\+/g, ' ')); 
 
} 
 

 
function displayTime(result) 
 
{ 
 
    
 
\t if (result.isOk == false) 
 
\t { 
 
\t \t alert(result.message); 
 
\t } 
 
\t else 
 
\t { \t 
 
\t  var d = new Date(); 
 
     startTicks = d.getTime(); 
 
\t  
 
\t \t secondsRemaining = parseInt($(result).find("SecondsRemaining").text()); 
 
\t \t secondsElapsed = parseInt($(result).find("SecondsElapsed").text()); 
 
\t \t redirectUrl = $(result).find("RedirectUrl").text(); 
 

 
     var suspendTimer = $(result).find("SuspendTimer").text(); 
 
     var dataNonLinearGuid = "?nlg=" + GetNonLinearGuid(); 
 
\t \t 
 
\t \t if (redirectUrl != "") { 
 
\t \t  location.href = redirectUrl; 
 
\t \t } 
 
\t \t 
 
\t  isError = $(result).find("Error").text(); 
 
\t  
 
\t  if (isError == "true") 
 
\t  { 
 
\t   errorCount++; 
 
\t   
 
\t   if (errorCount > 3) 
 
\t   { 
 
\t    logout(); 
 
\t   } 
 
\t  } 
 

 
\t  isOverworked = $(result).find("IsOverworked").text(); 
 
\t  if (isOverworked == "true") 
 
\t  { 
 
      location.href = "/Courses/MyAccountNonLinear.aspx" + dataNonLinearGuid; 
 
\t  } 
 

 
\t  if (suspendTimer.length > 0) { 
 
\t   if ($.trim(suspendTimer).toLowerCase() == "true") { 
 
\t    SuspendTimer(); 
 
\t   } 
 
\t  }  
 
\t } 
 
} 
 

 
function logout() 
 
{ 
 
    window.top.location.href = "/Courses/loggedout.aspx"; 
 
} 
 

 
function UpdateBothTimers() { 
 
    
 
    if (timerStatus != 'active') return; 
 
    
 
    if (secondsElapsed >= 0) 
 
    {  
 
     UpdateElapsedTimer(); 
 
     //secondsElapsed++; 
 
    } 
 

 
    if (secondsRemaining >= 0) { 
 
     UpdateRemainingTimer(); 
 
    } 
 

 
    if (estimatedSecondsRemaining <= 0 && zeroTimeCounter == 0) { 
 
     zeroTimeCounter++;  
 
     SaveTime(); 
 
    } 
 
} 
 
var lang; 
 
function qt(m,lng) { 
 
    
 
    $('#timeRemaining').css('display', 'none'); 
 
    setTimeout("$('#EOMQuiz').submit();", m * 1000); 
 
    lang = lng; 
 
    setTimeout('updateQ('+ m +')', 1000); 
 
} 
 

 
function updateQ(m) { 
 
    
 
    --m; 
 
    var text; 
 
    if (lang == 'es') { 
 
     text = 'Entregar - ' + m + ' segundos restantes para completar la prueba'; 
 
    } 
 
    else { 
 
     text = 'Submit - ' + m + ' seconds remaining to complete the quiz'; 
 
    } 
 
    
 
    if (m > 0) { 
 
     
 
     setTimeout('updateQ('+m+')', 990); 
 
    } 
 
    else 
 
    { 
 
     $('#eomsubmitDiv').css('background-color', '#FF0000'); 
 
     text ='Submitting... Please Wait.';  
 
    } 
 
    
 
    if (m <= 10 && m > 0) 
 
    { 
 
     if (m % 2 == 0) 
 
     { 
 
      $('#eomsubmitDiv').css('background-color', '#FFFF00'); 
 
     } 
 
     else 
 
     { 
 
      $('#eomsubmitDiv').css('background-color', '#FFFFAA');   
 
     } 
 
      
 
    } 
 
    
 
    $('#eomsubmit').attr('value', text); 
 
} 
 

 
function UpdateElapsedTimer() 
 
{ 
 
    var s = secondsElapsed + (GetTickDiff()/1000); 
 
    UpdateTimer('TotalTimeClock', s, 'UP'); 
 
} 
 

 
function GetTickDiff() 
 
{ 
 
    var d = new Date(); 
 
    var tickDiff = d.getTime() - startTicks; 
 
    return tickDiff; 
 
} 
 

 
function UpdateRemainingTimer() 
 
{ 
 
    
 
    var s = secondsRemaining - (GetTickDiff()/1000); 
 

 
    estimatedSecondsRemaining = s; 
 
    
 
    if (s < 0) s = 0; 
 
    
 
    UpdateTimer('TimeRemainingClock', s, 'DOWN'); 
 
} 
 

 
function UpdateTimer(ClockID,ElapsedSeconds,ClockDirection){ 
 

 
    
 
\t //check to see if we can run this code yet 
 
\t if(document.getElementById && document.getElementById(ClockID) != null){ 
 

 
\t \t //declare vars 
 
\t \t var _Seconds = 0; 
 
\t \t var _Minutes = 0; 
 
\t \t var _Hours = 0; 
 
\t \t 
 
\t \t //Format Seconds 
 
\t \t _Seconds = Math.floor(ElapsedSeconds % 60); 
 
\t \t if(_Seconds <= 9) { 
 
\t \t \t _Seconds = "0"+_Seconds; 
 
\t \t } 
 
\t \t 
 
\t \t //Format minutes 
 
\t \t _Minutes = Math.floor(ElapsedSeconds/60 % 60); 
 
\t \t if(_Minutes <= 9) { 
 
\t \t \t _Minutes = "0"+_Minutes; 
 
\t \t } 
 
\t \t 
 
\t \t //Format hours 
 
\t \t _Hours = Math.floor(ElapsedSeconds/3600 % 60); 
 
\t \t if(_Hours <= 9){ 
 
\t \t \t _Hours = "0"+_Hours; 
 
\t \t } 
 
\t \t 
 
\t \t document.getElementById(ClockID).innerHTML = _Hours + ":" + _Minutes + ":" + _Seconds; 
 
\t \t 
 
     if (timerStatus != 'active') 
 
     { 
 
      setTimeout('UpdateTimer(\''+ClockID+'\','+ElapsedSeconds+',\''+ClockDirection+'\')',1000); \t 
 
      return; 
 
     } 
 

 
\t \t if(ElapsedSeconds > 0 || ClockDirection == "UP"){ 
 
\t \t 
 
\t \t \t if(ClockDirection == "UP") 
 
\t \t \t { 
 
\t \t \t \t ElapsedSeconds = ElapsedSeconds + 1; 
 
\t \t \t } 
 
\t \t \t else 
 
\t \t \t { 
 
\t \t \t \t ElapsedSeconds = ElapsedSeconds - 1; 
 
\t \t \t } 
 
\t \t \t 
 
\t \t \t //setTimeout('UpdateTimer(\''+ClockID+'\','+ElapsedSeconds+',\''+ClockDirection+'\')',1000); \t \t \t 
 
\t \t } 
 
\t \t else{ 
 
\t \t \t //Timer has hit zero. Lets make sure the next buttons are visible. 
 
\t \t \t $('#next_top').show(); 
 
\t \t \t $('#next_bot').show(); 
 
\t \t } \t 
 
\t } 
 
\t else if(!pageLoaded) //call function again in 100ms 
 
\t { 
 
\t \t //setTimeout('UpdateTimer(\''+ClockID+'\','+ElapsedSeconds+',\''+ClockDirection+'\')',100); 
 
\t } 
 
} \t 
 

 
function DisplayNextButtons(){ 
 
\t $('#next_top').show(); 
 
\t $('#next_bot').show(); 
 
} 
 

 
function hideNextButtons(){ 
 
\t $('#next_top').hide(); 
 
\t $('#next_bot').hide(); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

+1

[保存]をクリックします。*これらのものは何ですか?何かエラーがありますか?あなたが見ている正確な問題は何ですか?あなたの質問(および付随するコード)はあまりにも曖昧です。 –

+0

@ScottMarcusコードはHTMLなしで動作しません。編集は不要なバンプだった。 – FrankerZ

+0

@FrankerZコードはすでにスニペットに入っていました。私はちょうどそれにいくつかの訂正をしました。また、スニペットでそれを持つことは、潜在的な回答の出発点として有用です。 –

答えて

0

私は同じコードつまずくに起こりました。あなたが私と同じサイトにいた場合、 私は潜在的な修正があります。 残りの時間を編集する代わりに、時間が切れたときに次にクリックするスクリプトをセットアップしました。私は彼らがタイムスタンプサーバー側をチェックしているかどうかを確認するにはあまりにも怠惰だった。また、サーバのログは通常のユーザに似ています。

指示:

  1. サイトにクローム https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija?hl=en
  2. 移動のために、次の拡張機能をダウンロード
  3. チェック
  4. "このホストのCJSを有効にする" CJS Chrome拡張機能ボタンをクリックしてください

    次のJSスニペットをJSボックスに貼り付けます

    var t=setInterval(try_hit_next,1000); 
    
    function try_hit_next(){ 
        if (estimatedSecondsRemaining <= 0) 
         window.location = $('#next_top').parent()[0]['href']; 
    } 
    
  5. 私は問題は次のページに進むために設定する必要が複数のものがあるということであると信じています*