简体   繁体   English

在网站上连续执行javascript功能的脚本

[英]Script to continuously execute javascript function on website

A friend of mine has recently posted his javascript game online. 我的一个朋友最近在网上发布了他的JavaScript游戏。 You first go to the homepage and then you click on a button that brings you to the game. 您首先进入主页,然后单击将您带入游戏的按钮。

Something like this when I inspect element: 当我检查元素时,是这样的:

onclick="playgame()"

When somebody clicks this, a counter increments so he knows how many people have played. 当有人单击此按钮时,计数器会增加,因此他知道有多少人玩。 He only did this for practice as he doesn't actually expect anyone to play. 他这样做只是为了练习,因为他实际上并不期望任何人玩。

I want to surprise him though, by having a script continuously click this button over and over and make him think he has 1000's of plays. 不过,我想让他感到惊讶,方法是让脚本连续不断地单击此按钮,并使他认为他有1000多个剧本。 He'll love the prank when I tell him ;) 当我告诉他时,他会爱上恶作剧的;)

Does anyone know if this is possible? 有人知道这是否可能吗? I'm experienced in c#, but from looking online, php seems to be more suitable? 我有C#的经验,但是从网上看,php似乎更合适? I'm 100% open to any other methods Thanks 我100%接受其他任何方式,谢谢

EDIT: I was looking at something like this 编辑:我正在看这样的东西

<?php
echo '<script type="text/javascript">'
, 'jsfunction();'
, '</script>'
;
?>

But then I don't know how I will execute this on his website 但是我不知道如何在他的网站上执行

EDIT 2: Actually seems like python would be the correct option 编辑2:实际上似乎python将是正确的选项

I am not sure, if this work in your situation, but if you would like to do something x times, you can do it with a loop like in any other language. 我不确定这是否可以解决您的问题,但是如果您想做x次,可以像使用其他任何语言一样循环执行。

For example if you would like to call a function x times, you could do it this way: 例如,如果您想调用一个函数x次,则可以这样进行:

function someFunction(x) { console.log(x) }
var iterations = 1000;
for (var i = 0; i < iterations ; i++ ) {
  someFunction(i);
}

Infinite 无穷

var iterations = 0
while(true) someFunction(iterations++)

Just use simple iteration, make a function like this and run it. 只需使用简单的迭代,创建一个像这样的函数并运行它即可。

function click1k() {
    var clicks=1000;
    for (var i=clicks; i>0; i--) {
        playgame();
    }
 }

And run: 并运行:

click1k();

如果是网站,则可以将iMacros插件用于Firefox,并只记录一个宏,甚至可以将js用于更复杂的脚本,但只需一个简单的循环即可。

You can trigger that button continuously. 您可以连续触发该按钮。 Here is the code. 这是代码。

 setInterval(function(){
    $("Selector").click();
 }, 5000);

It will click automatically selected button or any element every 5 seconds. 它将每5秒单击一次自动选择的按钮或任何元素。 You can increase or decrease the time so it will look real to get play counter in time gaps 您可以增加或减少时间,以便在时间间隙获得反击

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM