9Hits Macros - Build-in functions

Note that some functions are required await keyword

Access your website information

You can get some informations of your site from TheCampaign object.

{ 
   "id": 123,
   "url": "http://google.com",
   "duration": 15
}
//For example, to get the site ID, you can use
TheCampaign.id

Alert (msg)

Show a dialog with a message.

Parameters:
  • msg: The text message.

await Delay (ms)

Pause the script for a period of time in milliseconds

Parameters:
  • ms: Delay time in miliseconds.
Example:
await Delay(3000);
Alert ("Hello Worlds");

Random (min, max)

Returns a random integer that is within a specified range.

Parameters:
  • min: The inclusive lower bound of the random number returned.
  • max: The exclusive upper bound of the random number returned. max must be greater than or equal to min.

RandomArray (array)

Take a random item from an array.

Parameters:
  • array: Source array.
Example:
var randomKeyword = RandomArray(["traffic exchange", "auto surf"]);
Alert (randomKeyword);

await ClickByCoordinates (X1, Y1, X2, Y2, nClick)

Click on an area on your website based on coordinates.

Parameters:
  • X1, Y1, X2, Y2: coordinates of the area
    X1, Y1 X2, Y2
  • nClick: number of clicks, the default is 1.
Example:
await ClickByCoordinates(100, 100, 200, 200);
await ClickByCoordinates(100, 100, 200, 200, 2);

You can also get the coordinates from the browser of the Macros Editor like this


await ClickById (id, nClick, frameUrlRegex)

Click on an element based on its ID.

Parameters:
  • id: ID of the element.
  • nClick: number of clicks, the default is 1.
  • frameUrlRegex: The regex pattern of the frame URL to click on, the default is the main frame.
Example:
await ClickById("load-more-button");

await ClickByXpath (xpath, nClick, frameUrlRegex)

Click on an element based on its xpath.

Parameters:
  • xpath: xpath of the element. You may use the GenerateXpath function to generate xpath.
  • nClick: number of clicks, the default is 1.
  • frameUrlRegex: The regex pattern of the frame URL to click on, the default is the main frame.
Example:
await ClickByXpath("/html/body/div/div[1]/div/ul/li[6]/a/div[1]/span");
await ClickByXpath(GenerateXpath("a", "href", "https://9hits.com%"));

await ClickByTag (tag, index, nClick, frameUrlRegex)

Click on an element based on its tag name.

Parameters:
  • tag: Tag name of the element.
  • index: Index of the element in case there is multiple elements with the same class name. You can use number (0 for the first element) or "random" to click any element randomly, default is 0.
  • nClick: number of clicks, the default is 1.
  • frameUrlRegex: The regex pattern of the frame URL to click on, the default is the main frame.
Example:
await ClickByTag("a"); //click to the first link element
await ClickByTag("a", 1); //click to the 2nd link element
await ClickByTag("a", "random"); //click random a link

await ClickByClass (class, index, nClick, frameUrlRegex)

Click on an element based on its class name.

Parameters:
  • class: Class name of the element.
  • index: Index of the element in case there is multiple elements with the same class name. You can use number (0 for the first element) or "random" to click any element randomly, default is 0.
  • nClick: number of clicks, the default is 1.
  • frameUrlRegex: The regex pattern of the frame URL to click on, the default is the main frame.
Example:
await ClickByClass("skip-button"); //Click to the first element has class name "skip-button"
await ClickByClass("skip-button", 1); //Click to the 2nd element has class name "skip-button"
await ClickByClass("skip-button", "random"); //Click to the random any element has class name "skip-button"

await ClickRandomLink (useMouse, frameUrlRegex)

Randomly click any link on your website.

Parameters:
  • useMouse: Call the javascript click function or click with the mouse.
  • frameUrlRegex: The regex pattern of the frame URL to click on, the default is the main frame.
Example:
await ClickRandomLink();
await ClickRandomLink(true);

await ClickRandomInternalLink (useMouse, frameUrlRegex)

Randomly click any internal link on your website.

Parameters:
  • useMouse: Call the javascript click function or click with the mouse.
  • frameUrlRegex: The regex pattern of the frame URL to click on, the default is the main frame.
Example:
await ClickRandomInternalLink();
await ClickRandomInternalLink(true);

await ClickRandomExternalLink (useMouse, frameUrlRegex)

Randomly click any external link on your website.

Parameters:
  • useMouse: Call the javascript click function or click with the mouse.
  • frameUrlRegex: The regex pattern of the frame URL to click on, the default is the main frame.
Example:
await ClickRandomExternalLink();
await ClickRandomExternalLink(true);

await SetById (id, attr, value, frameUrlRegex)

Set the value for an attribute of an element based on its ID.

Parameters:
  • id: ID of the element.
  • attr: The attribute you want to set.
  • value: The value you want to set.
  • frameUrlRegex: The regex pattern of the frame URL to set on, the default is the main frame.
Example:
await SetById("email", "value", "[email protected]");

await SetByXpath (xpath, attr, value, frameUrlRegex)

Set the value for an attribute of an element based on its xpath.

Parameters:
  • xpath: Xpath of the element.
  • attr: The attribute you want to set.
  • value: The value you want to set.
  • frameUrlRegex: The regex pattern of the frame URL to set on, the default is the main frame.
Example:
await SetByXpath ('//input[@type="email"]', 'value', '[email protected]');

await SetByClass (class, attr, value, index, frameUrlRegex)

Set the value for an attribute of an element based on its class name.

Parameters:
  • class: Class name of the element.
  • attr: The attribute you want to set.
  • value: The value you want to set.
  • index: Index of the element in case there is multiple elements with the same class name. 0 is the first element.
  • frameUrlRegex: The regex pattern of the frame URL to set on, the default is the main frame.
Example:
await SetByClass("text-box", "value", "text value");
await SetByClass("text-box", "value", "text value", 2);

await SetByTag (tag, attr, value, index, frameUrlRegex)

Set the value for an attribute of an element based on its tag name.

Parameters:
  • tag: Tag name of the element.
  • attr: The attribute you want to set.
  • value: The value you want to set.
  • index: Index of the element in case there is multiple elements with the same class name. 0 is the first element.
  • frameUrlRegex: The regex pattern of the frame URL to set on, the default is the main frame.
Example:
await SetByTag("input", "value", "text value");
await SetByTag("input", "value", "text value", 2);

await ExecuteScript (jsCode, frameUrlRegex)

Execute javascript code on your website.

Parameters:
  • jsCode: The code to execute.
  • frameUrlRegex: The regex pattern of the frame URL to run the javascript code on, the default is the main frame.
Example:
await ExecuteScript ('document.write("Hello 9Hits")');

await EvaluateScript (jsCode, frameUrlRegex)

Execute javascript code on your website and return value.

Parameters:
  • jsCode: The code to execute.
  • frameUrlRegex: The regex pattern of the frame URL to run the javascript code on, the default is the main frame.
Example:
var result = await EvaluateScript ('document.getElementById("email").value');
Alert (result);

GenerateXpath (tag, attr, value, index)

Create xpath to target the element. You can combine this function with ClickByXpath and SetByXpath functions.

Parameters:
  • tag: Tag name of the element.
  • attr: The attribute of the element.
  • value: The value of the element.
  • index: The index of the element.
Example:
//a link has href = "http://google.com"
GenerateXpath("a", "href", "http://google.com");

//a link has href starts with "http://google"
GenerateXpath("a", "href", "http://google%");

//a link has href ends with "google.com"
GenerateXpath("a", "href", "%google.com");

//a link has href contains "google"
GenerateXpath("a", "href", "%google%");

await GetAttribute (xpath, attr, frameUrlRegex)

Get the value of an attribute of an element based on its xpath.

Parameters:
  • xpath: Xpath of the element.
  • attr: The attribute you want to get value.
  • frameUrlRegex: The regex pattern of the frame URL to work on, the default is the main frame.
Example:
var result = await GetAttribute ('//input[@type="email"]', 'value');
Alert (result);

await GetElementPos (jsCode, frameUrlRegex)

Get the coordinates of an element.

Parameters:
  • jsCode: The javascript code to locate the element.
  • frameUrlRegex: The regex pattern of the frame URL to find the element, the default is the main frame.
Example:
var pos = await GetElementPos ("return document.getElementById('submit-button');");
//Return: object {X1: 100, Y1: 100, X2:200, Y2: 200}
ClickByCoordinates(pos.X1, pos.Y1, pos.X2, pos.Y2);

await GetBrowserWidth ()

Return the browser width.


await GetBrowserHeight ()

Return the browser height.


await GetSource ()

Return the source code of the website.


await GetHtml ()

Return the HTML code of the website.


await GetUrl ()

Return the current URL.


GetUserAgent ()

Return the current User-Agent.


await GetDuration () [ Only available on the 9Hits Viewer]

Returns the maximum duration in seconds that the viewer will view your website.


await GetViewedDuration () [ Only available on the 9Hits Viewer]

Returns the total time in seconds that the viewer viewed your website.


await IsLoading ()

Indicates that the browser is loading or not.


IsMobile ()

Indicates that the browser is mobile or not (base on the User-Agent).


await IsHideBrowser ()

Indicates whether the browser is hidden by the user.


await WaitForLoading ()

Wait until the browser has finished loading.


await GetMaxPopups () [ Only available on the 9Hits Viewer]

Returns the maximum number of popups your site may be allowed to open, if the viewer is disabled popups, the return value will be 0


await GetConnectionType () [ Only available on the 9Hits Viewer]

Returns the connection type of the viewer. Possible values are: system, http, socks4, socks5, ssh.


await GetImageByXpath (xpath, frameUrlRegex)

Get an image in base64 format based on its xpath.

Parameters:
  • xpath: xpath of the element
  • frameUrlRegex: The regex pattern of the frame URL, the default is the main frame.

await _2CaptchaSolve (params, timeout)

Solve captcha by 2Captcha service.

Parameters: Example:
var captBase64 = await GetImageByXpath('//*[@id="CAPTCHA"]');
var result = await _2CaptchaSolve({
    'key' : '2CAPTCHA_API_KEY', //replace with your 2Captcha API Key
    'method' : 'base64',
    'json' : 1,
    'body': captBase64
});
Alert("Result is: " + result.request);
//Example Result: {status:1, request: VMXKDG, captchaId: 1241352612}

await _2CaptchaReportBad (key, captchaId)

If you believe that captcha is resolved incorrectly, you can use this function to report it. However do not abuse.

Parameters:
  • key: Your 2Captcha API Key.
  • captchaId: ID of the captcha returned by the _2CaptchaSolve function.
Example:
var captBase64 = await GetImageByXpath('//*[@id="CAPTCHA"]');
var result = await _2CaptchaSolve({
    'key' : '2CAPTCHA_API_KEY', //replace with your 2Captcha API Key
    'method' : 'base64',
    'json' : 1,
    'body': captBase64
});
//do something...
await _2CaptchaReportBad('2CAPTCHA_API_KEY', result.captchaId);

await ACSolve (params, timeout)

Solve captcha by anti-captcha service.
Demo .

Parameters: Example:
var image = await GetImageByXpath('//*[@id="captcha_one"]');
var result = await ACSolve({
    "clientKey":"Your anti-captcha API Key",
    "task":
    {
        "type":"ImageToTextTask",
        "body":image,
        "phrase":false,
        "case":false,
        "numeric":false,
        "math":0,
        "minLength":0,
        "maxLength":0
    }
}, 150);
Example Result:
{
    "taskId":1234567,
    "errorId":0,
    "status":"ready",
    "solution":
        {
            "text":"deditur",
            "url":"http:\/\/61.39.233.233\/1\/147220556452507.jpg"
        },
    "cost":"0.000700",
    "ip":"46.98.54.221",
    "createTime":1472205564,
    "endTime":1472205570,
    "solveCount":"0"
}

await ACReportIncorrectImage(key, taskId);

If you believe that the image captcha is resolved incorrectly, you can use this function to report it. However do not abuse.

Parameters: Example:
var image = await GetImageByXpath('//*[@id="captcha_one"]');
var result = await ACSolve({
    "clientKey":"Your anti-captcha API Key",
    "task":
    {
        "type":"ImageToTextTask",
        "body":image,
        "phrase":false,
        "case":false,
        "numeric":false,
        "math":0,
        "minLength":0,
        "maxLength":0
    }
}, 150);
...
//do something | submit captcha...
...
if(somehow you know that the captcha was incorrect)
{
    ACReportIncorrectImage("Your anti-captcha API Key", result.taskId);
}

await ACReportIncorrectRecaptcha(key, taskId);

If you believe that the reCaptcha is resolved incorrectly, you can use this function to report it. However do not abuse.

Parameters: Example:
var result = await ACSolve({
    "clientKey": "Your anti-captcha API Key",
    "task":
    {
        "type":"NoCaptchaTaskProxyless",
        "websiteURL":"https://9hits.com",
        "websiteKey":"6LdPp08UAAAAADi4dE6frVDXCv2CgESTpcscb_LS"
    }
}, 600);
...
//do something | submit captcha...
...
if(somehow you know that the reCaptcha was incorrect)
{
    ACReportIncorrectRecaptcha("Your anti-captcha API Key", result.taskId);
}

await TabCount ()

Returns the total number of opened tabs.


await Typing (text, speed1, speed2)

Simulate typing

Parameters:
  • text: Text to type.
  • speed1 - speed2: Delay time range to adjust typing speed.
Example:
await Typing ("Hello 9Hits");
await Typing ("Hello 9Hits", 300, 500);

ResizeTo (width, height)

Change the browser size.

Parameters:
  • width: New width.
  • height: New height.

ScrollTo (X, Y)

Scroll the browser to the specified coordinates.

Parameters:
  • X: New width.
  • Y: New height.

TabFocus (target)

Focusing on the specified tab, macros will be executed on the selected tab after this function call

Parameters:
  • target: Can be a tab index (1 is the first tab) or a search pattern by URL.
Example:
await WaitForLoading();
ExecuteScript('document.write("this is main tab")');
TabFocus(2); //focus to the 2nd tab
await Delay(1000);
ExecuteScript('document.write("this 2nd tab")');
TabFocus("facebook.com"); //focus to the tab which has url contains "facebook.com"
await Delay(1000);
ExecuteScript('document.write("this facebook tab")');

SendKeyDown (keyCode)

Simulate keydown event.

Parameters:
  • keyCode: Key Code.

SendKeyUp (keyCode)

Simulate keyup event.

Parameters:
  • keyCode: Key Code.

SendKeyChar (keyCode)

Simulate keychar event.

Parameters:
  • keyCode: Key Code.

SendKeyPress (keyCode)

Simulate keypress event.

Parameters:
  • keyCode: Key Code.

SendMouseClick (x, y, button)

Simulate mouseclick event.

Parameters:
  • x: coordinates X.
  • y: coordinates Y.
  • button: can be "left", "right" or "middle"

SendMouseMove (x, y)

Simulate mousemove event.

Parameters:
  • x: coordinates X.
  • y: coordinates Y.

SendMouseWheel (deltaX, deltaY)

Simulate mousewheel event.

Parameters:
  • deltaX: Delta X.
  • deltaX: Delta Y.
Example:
SendMouseWheel(0, -120); //scroll down 120px
SendMouseWheel(0, 120); //scroll up 120px

Exit ()

Close the browser immediately.


await HttpRequest (url, params, referrer) [ Only available on the 9Hits Traffic Bot]

Make HTTP Request

Parameters:
  • url: URL to send request.
  • params: Post Parameters.
  • referrer: Referrer URL.
Example:
var test1 = await HttpRequest("http://google.com");
var test2 = await HttpRequest("http://google.com", {"post_data" : "xxx", "other_data", "yyy"});

await ReadFile (path) [ Only available on 9Hits the Traffic Bot]

Read and return the contents of a file as text

Parameters:
  • path: Path to file.
Example:
var test = await ReadFile("C:\\test.txt");
Alert(test);

WriteFile (path, content, mode) [ Only available on the 9Hits Traffic Bot]

Write text to a file

Parameters:
  • path: Path to file.
  • content: Text content.
  • mode: Can be "override" or "append".
Example:
WriteFile("C:\\test.txt", "Hello");
WriteFile("C:\\test.txt", "Hello", "append");

await GetCurrentDir () [ Only available on the 9Hits Traffic Bot]

Returns the current path that 9Hits Traffic Bot is running


await GetDownloadedFiles () [ Only available on the 9Hits Traffic Bot]

Returns the array of downloaded files


await IsFileDownloaded (fileName) [ Only available on the 9Hits Traffic Bot]

Check if the given file has been downloaded

Parameters:
  • fileName: Name of the file to check.

By using our site, you acknowledge that you have read and understood our Cookie Policy, Privacy Policy and our Terms of Service