如何使用Violentmonkey脚本跳过此倒计时

时间:2019-06-23 14:36:33

标签: javascript

是否有一种方法可以使脚本不跳过此倒计时?我已经尝试过自己编写脚本,但是我是javascript新手,所以我想不出办法。

这是倒计时的代码(它是一个内联脚本,并且是该页面中唯一的内联脚本)。

我的密码

// ==UserScript==
// @name Site Countdown Skip
// @autor SecretX
// @namespace namespace_secretx
// @description Skip the silly countdown.
// @version 2019.06.23
// @match http://example.com/download/?*
// @match https:/example.com/download/?*
// @grant none
// ==/UserScript==

var changed = 0;

window.addEventListener('beforescriptexecute', function(e) {

    if(e.target===document.getElementsByTagName("script")[0]){
        e.stopPropagation();
        e.preventDefault();
    }
    window.removeEventListener(e.type, arguments.callee, true);
}, true);

页面代码

<div id="pleasewait">Please wait <span id="contador">15</span> seconds</div>
<iframe class="clearfix" src="https://a.site.com.br/download/php_code.php" id="iframe" style="border: 0;width:100%;height:100%;" __idm_frm__="12884901909"></iframe>
<script type="text/javascript">
  var seconds;
  var temp;

  function countdown() {
    seconds = document.getElementById('countdown1').innerHTML;
    seconds = parseInt(seconds, 10);

    if (seconds == 1) {
      temp = document.getElementById('pleasewait');
      temp.innerHTML = '<a href="magnet:?xt=urn:btih:00et8wt78wga5tre874fe8afw8w&amp;dn=Video_File_999_FHD.mkv&amp;xl=687980321&amp;tr=udp://tracker.tracker.org:1337/announce" id="continuar"><i id="cola"></i></a>';
      return;
    }

    seconds--;
    temp = document.getElementById('countdown1');
    temp.innerHTML = seconds;
    timeoutMyOswego = setTimeout(countdown, 1000);
  } 

  countdown();
</script>

1 个答案:

答案 0 :(得分:0)

根据您发布的代码,如果您想尽可能地减少计数而不在第二个代码块中编辑HTML或JS,那么您只需将此JS行添加到文档中: / p>

document.getElementById('countdown1').innerHTML = 1;

这会将元素innerHtml设置为1。 在JS函数countdown()中,有一个if语句正在检查“ countdown1”元素的innerHtml是否为1,如果是,那么它将更新“ temp”元素的内容。

这里是一个例子:

<div id="pleasewait">Please wait <span id="countdown1">15</span> seconds</div>
<iframe class="clearfix" src="https://a.site.com.br/download/php_code.php" id="iframe" style="border: 0;width:100%;height:100%;" __idm_frm__="12884901909"></iframe>

<script>
document.getElementById('countdown1').innerHTML = 1
</script>

<script type="text/javascript">
  var seconds;
  var temp;

  function countdown() {
    seconds = document.getElementById('countdown1').innerHTML;
    seconds = parseInt(seconds, 10);

    if (seconds == 1) {
      temp = document.getElementById('pleasewait');
      temp.innerHTML = 'LOAD THIS';
      return;
    }

    seconds--;
    temp = document.getElementById('countdown1');
    temp.innerHTML = seconds;
    timeoutMyOswego = setTimeout(countdown, 1000);
  } 

  countdown();
</script>

我写的是LOAD THIS,而不是最初的示例,您真正需要做的就是写以下行:

<script>
    document.getElementById('countdown1').innerHTML = 1
</script>

此元素之后:

<div id="pleasewait">Please wait <span id="countdown1">15</span> seconds</div>