XKit.tools
: Utility functions for XKit.
# XKit.tools.get_blogs()
Returns an array of the URLs of the blogs the user has.
# XKit.tools.remove_css(extension_id)
Removes the CSS added by extension_id
.
# XKit.tools.add_css(css, extension_id)
Adds css
to the page with id extension_id
.
Example usage:
run: function() {
var hide_post = true;
if (hide_posts) {
// Lets hide all posts.
XKit.tools.add_css("#posts .post { display: none; }", "my_extension_name");
}
},
destroy: function() {
XKit.tools.remove_css("my_extension_name");
}
# XKit.tools.init_css(extension_id)
Loads the extension’s CSS into the page.
If your CSS has code that you’ll be using all the time, use the Stylesheet tab on XKit Editor, then call init_css function to let XKit load it to the page. Use XKit.tools.remove_css
to remove it.
Example usage:
/* my_extension.css */
#my_fancy_div {
background: red;
color: yellow;
}
// my_extension.js
run: function() {
XKit.tools.init_css("my_extension_name");
$("body").append("<div id=\"my_fancy_div\">This will be red and yellow.</div>");
},
destroy: function() {
XKit.tools.remove_css("my_extension_name");
}
<a name”escape_html” href=”XKit.tools.md#escape_html”>#</a> XKit.tools.escape_html(text)
Will return the passed text, with all potentially dangerous-for-HTML characters escaped.
see also the OWASP wiki for the source of the list of escaping rules in this function.
Under no circumstances should the output of this function be injected into an unquoted element attribute, as there are many ways to escape from an unquoted attribute that aren’t covered here. Don’t use unquoted attributes.
<a name”random_string” href=”XKit.tools.md#random_string”>#</a> XKit.tools.random_string()
Returns a random 30-character string.
# XKit.tools.add_function(func, execute, add_t)
Adds the function func
to the page, and executes it if execute
is true
.
add_t
contains data that is passed along with func
to be available as the variable add_tag
in the context of the browser page.
# XKit.tools.parse_version(version_string)
Parses version_string
in format <MAJOR>.<MINOR>.<PATCH>
, <MAJOR>.<MINOR>
, or <MAJOR>.<MINOR> REV <N>
and returns a Semver-styled object:
{
major,
minor,
patch
}
<a name”get_parameter_by_name” href=”XKit.tools.md#get_parameter_by_name”>#</a> XKit.tools.getParameterByName(name)
Gets a query string value by name.
Example: for the URL https://www.tumblr.com/reblog/137048498063/jL2F1abw/?redirect_to=http://www.example.com
, calling XKit.tools.getParameterByName("redirect_to")
will return http://www.example.com
.
destroy
function..my_div
; instead use .my_extension_my_div