-
Notifications
You must be signed in to change notification settings - Fork 0
[en]trashscript_lib
devel01 edited this page Dec 7, 2024
·
5 revisions
sleep(milliseconds);
The time interval for which execution is to be suspended, in milliseconds.
timestamp()
The timestamp() function returns a datetime value based on a date or datetime value, identical to new Date().getTime()
DOM manipulation can only read content from the webpage and does not provide any functionality for making modifications.
//query elements
elements = $(css_selector);
//query all div elements
elements = $("div")
//query all div elememts under body
elements = $("div","body")
elements = $("div")
elements.length; //the length of div elements
elements = $("div")
elements.eq(0) //get an element from the elements by index
/*
* the each method is an iterative method.
* It calls a provided callbackFn function once for each element in an array in ascending-index order.
*/
elements = $("div");
result = elements.each(function(i,element){
//the result is undefined
});
result = elements.each(function(i,element){
//break the loop, the result is true
return true;
});
<span id="content" style="color:red"></span>
//Get the corresponding computed style from an element.
color = $("#content").css("color")
<img src="img.png"/>
//Get the corresponding attribute from an element.
src = $("img").attr("src");
get property from a DOM object
$("div").prop("dom_property")
$("div").prop(function(name,value){
if(name === "key"){
return value;
}
})
get data from a DOM dataset object
$("div").data("dataset_property")
$("div").data(function(name,value){
if(name === "key"){
return value;
}
})
Click all elements
$("button").click();
<span id="aa">text</span>
//Get the rendered text content of a element and its descendant.
src = $("#aa").text();
<span id="aa"><span>text</span></span>
//The html method returns a serialization of the nested child DOM elements within the element.
src = $("#aa").html();
<body>
<span></span>
</body>
//Get the parent element of the span.
element = $("span").parent()
<body>
<span>1</span>
<span>2</span>
<span>3</span>
</body>
elements = $("body").children();
elements.each(function(i,element){
console.log(element.text());
});
<body>
<span id="a">1</span>
<span id="b">2</span>
<span id="c">3</span>
</body>
siblings = $("#a").siblings();
siblings.each(function(i,element){
console.log(element.text());
});
<body>
<span id="a">1</span>
<span id="b">2</span>
<span id="c">3</span>
</body>
$("#a").next(); //b
<body>
<span id="a">1</span>
<span id="b">2</span>
<span id="c">3</span>
</body>
$("#b").prev(); //a
Get the value of and element.
<input value="123" />
$("input").val(); //The value is "123"
Execute HTTP requests.
http = HTTP(method,url,username = "",password = "")
http.options(opts = {})
http.request(post_data = null)
{
//key: value, HTTP request headers
headers: {
referer:"http://xxxx"
}
}
http = HTTP.get(url,options = {})
http = HTTP.get(url,post_data,options = {})
/*
* The default XMLHttpRequest does not support cross-origin requests.
* However, you can override the HTTP_Intermedia function to forward the request to another program, such as background.js.
* Finally, you can execute the resolve_callback to submit the results.
*/
TrashScript.perperties.HTTP_Intermedia = function(option,resolve_callback)
{
//option.method; request method: GET, POST....
//option.url; request url
//option.data; post data (string or object)
//option.timeout, {timeout:5000}
//option.headers, {referer:"xxxx"}
resolve_callback({status:200,status_text:"text",headers:{},body:"response content"})
}
{
method: String,
url: String,
request_headers: Object,
options: function(options_object),
request: function(post_data),
}
{
status: Number, //status code
status_text: String, //status text
body: String, //response body
text: String, //response text
XML: String, //formatted response xml
JSON: String, //formatted response JSON, or null
header: function(name) //response headers, if name is undefined, it returns all headers
}