|
Parameters |
---|
(body of plugin) - text |
no parameters |
{CASPERJS()} {SOURCE()} var casper = require('casper').create(); var links; function getLinks() { // Scrape the links from top-right nav of the website var links = document.querySelectorAll('ul.navigation li a'); return Array.prototype.map.call(links, function (e) { return e.getAttribute('href') }); } // Opens casperjs homepage casper.start('http://casperjs.org/'); casper.then(function () { links = this.evaluate(getLinks); tikiBridge.add('links', links); }); {SOURCE} {CASPERJS}
Currently, it runs casperjs, and display back to the user:
How does the TikiBridge works:
TikiBridge.add('variable_name', variable)
TikiBridge.done
that will format the variables to be sent back to tiki.
In a Tiki Page, use the following code:
{CASPERJS()} {SOURCE()} var casper = require('casper').create(); casper.start('https://dev.tiki.org/Development', function() { casper.capture('screenshots/tiki_dev.png'); this.echo('File saved in TIKI_ROOT/screenshots/tiki_dev.png'); }); casper.run(); {SOURCE} {CASPERJS}
Click on Execute CasperJS script and the screenshoot will be stored in "TIKI_ROOT/screenshots", with "tiki_dev.png" filename
Output
In a Tiki Page, use the following code.
{CASPERJS()} {SOURCE()} var casper = require('casper').create(); casper.start('https://tiki.org/HomePage', function() { this.echo('https://tiki.org/HomePage page title:' + this.getTitle()); }); casper.thenOpen('https://dev.tiki.org/Development', function() { this.echo('https://dev.tiki.org/Development page title:' + this.getTitle()); }); casper.run(); {SOURCE} {CASPERJS}
Output
In a Tiki Page, use the following code:
{CASPERJS()} {SOURCE()} var titleTags = []; var casper = require('casper').create(); function getLinks() { var titleTags = document.querySelectorAll('h3.r a'); return Array.prototype.map.call(titleTags, function(e) { return e.innerText; }); } // Set user-agent to render page like chrome casper.userAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'); casper.start('http://google.com/', function() { // Wait for the page to be loaded this.waitForSelector('form[action="/search"]'); }); casper.then(function() { // search for 'tikiwiki groupware' from google this.fill('form[action="/search"]', { q: 'tikiwiki groupware' }, true); }); casper.then(function() { // aggregate results for the 'tikiwiki groupware' search titleTags = this.evaluate(getLinks); }); casper.run(function() { this.echo(titleTags.length + ' Title Tags found:'); this.echo(' - ' + titleTags.join('\n - ')).exit(); }); {SOURCE} {CASPERJS}
Output