mirror of https://github.com/vitalif/phantomjs
Merge remote-tracking branch 'upstream/master'
commit
3b4163521f
|
@ -22,6 +22,10 @@ Version 1.1.0
|
|||
|
||||
Added support for rasterizing as GIF image (Ariya Hidayat).
|
||||
|
||||
Added support for CoffeeScript (Ariya Hidayat).
|
||||
|
||||
Fixed issue #19: option for setting the proxy (Clint Berry, Ariya Hidayat).
|
||||
|
||||
2011-01-17: Version 1.0.0
|
||||
|
||||
Initial launch.
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# List following and followers from several accounts
|
||||
|
||||
if phantom.state.length == 0
|
||||
phantom.state = ['SenchaInc',
|
||||
'aconran',
|
||||
'ariyahidayat',
|
||||
'darrellmeyer',
|
||||
'DavidKaneda',
|
||||
'DmitryBaranovsk',
|
||||
'donovanerba',
|
||||
'edspencer',
|
||||
'helder_correia',
|
||||
'jamespearce',
|
||||
'jamieavins',
|
||||
'jarrednicholls',
|
||||
'jayrobinson',
|
||||
'lojjic',
|
||||
'mmullany',
|
||||
'philogb',
|
||||
'rdougan',
|
||||
'tmaintz',
|
||||
'whereisthysting'].join ':'
|
||||
phantom.open 'http://mobile.twitter.com/SenchaInc'
|
||||
else
|
||||
users = phantom.state.split ':'
|
||||
id = users[0]
|
||||
next = users[1]
|
||||
data = document.querySelector 'div.timeline-following'
|
||||
phantom.state = users.slice(1).join ':'
|
||||
console.log id + ': ' + data.innerText
|
||||
if next
|
||||
phantom.open 'http://mobile.twitter.com/' + next
|
||||
else
|
||||
phantom.exit 1;
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
// List following and followers from several accounts
|
||||
|
||||
if (phantom.state.length === 0) {
|
||||
phantom.state = ['SenchaInc',
|
||||
'aconran',
|
||||
'ariyahidayat',
|
||||
'darrellmeyer',
|
||||
'DavidKaneda',
|
||||
'DmitryBaranovsk',
|
||||
'donovanerba',
|
||||
'edspencer',
|
||||
'helder_correia',
|
||||
'jamespearce',
|
||||
'jamieavins',
|
||||
'jarrednicholls',
|
||||
'jayrobinson',
|
||||
'lojjic',
|
||||
'mmullany',
|
||||
'philogb',
|
||||
'rdougan',
|
||||
'tmaintz',
|
||||
'whereisthysting'].join(':');
|
||||
phantom.open('http://mobile.twitter.com/SenchaInc');
|
||||
} else {
|
||||
var users = phantom.state.split(':'),
|
||||
id = users[0],
|
||||
next = users[1],
|
||||
data = document.querySelector('div.timeline-following');
|
||||
phantom.state = users.slice(1).join(':');
|
||||
console.log(id + ': ' + data.innerText);
|
||||
if (next) {
|
||||
phantom.open('http://mobile.twitter.com/' + next);
|
||||
} else {
|
||||
phantom.exit();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
console.log 'Hello, world!'
|
||||
phantom.exit()
|
|
@ -0,0 +1,7 @@
|
|||
if phantom.state.length == 0
|
||||
phantom.state = 'tweets'
|
||||
phantom.open 'http://mobile.twitter.com/SenchaInc'
|
||||
else
|
||||
list = document.querySelectorAll 'span.status'
|
||||
console.log i.innerHTML.replace(/<.*?>/g, '') for i in list
|
||||
phantom.exit()
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
if (phantom.state.length === 0) {
|
||||
phantom.state = 'tweets';
|
||||
phantom.open('http://mobile.twitter.com/mr3bc');
|
||||
phantom.open('http://mobile.twitter.com/SenchaInc');
|
||||
} else {
|
||||
var list = document.querySelectorAll('span.status');
|
||||
for (var i = 0; i < list.length; ++i) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
This file is part of the PhantomJS project from Ofi Labs.
|
||||
|
||||
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the <organization> nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "csconverter.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QFile>
|
||||
#include <QWebFrame>
|
||||
#include <QDebug>
|
||||
|
||||
CSConverter::CSConverter(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
QFile file(":/coffee-script.js");
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
std::cerr << "CoffeeScript compiler is not available!" << std::endl << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
QString script = QString::fromUtf8(file.readAll());
|
||||
file.close();
|
||||
m_webPage.mainFrame()->evaluateJavaScript(script);
|
||||
m_webPage.mainFrame()->addToJavaScriptWindowObject("converter", this);
|
||||
}
|
||||
|
||||
QString CSConverter::convert(const QString &script)
|
||||
{
|
||||
setProperty("source", script);
|
||||
QWebFrame *frame = m_webPage.mainFrame();
|
||||
QVariant result = frame->evaluateJavaScript("this.CoffeeScript.compile(converter.source)");
|
||||
if (result.type() == QVariant::String)
|
||||
return result.toString();
|
||||
return QString();
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
This file is part of the PhantomJS project from Ofi Labs.
|
||||
|
||||
Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the <organization> nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef CSCONVERTER_H
|
||||
#define CSCONVERTER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWebPage>
|
||||
|
||||
class CSConverter: public QObject
|
||||
{
|
||||
public:
|
||||
CSConverter(QObject *parent = 0);
|
||||
QString convert(const QString &script);
|
||||
|
||||
private:
|
||||
QWebPage m_webPage;
|
||||
};
|
||||
|
||||
#endif // CSCONVERTER_H
|
||||
|
|
@ -34,6 +34,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#include <gifwriter.h>
|
||||
#include "csconverter.h"
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(4, 5, 0)
|
||||
#error Use Qt 4.5 or later version
|
||||
|
@ -60,8 +61,9 @@ void showUsage()
|
|||
std::cerr << "Options:" << std::endl;
|
||||
std::cerr << "\t--load-images=[yes|no]\t\tLoad all inlined images (default is 'yes')." << std::endl;
|
||||
std::cerr << "\t--load-plugins=[yes|no]\tLoad all plugins (i.e. 'Flash', 'Silverlight', ...) (default is 'no')." << std::endl;
|
||||
std::cerr << "\t--proxy=address:port\tSet the network proxy." << std::endl;
|
||||
std::cerr << "\t--upload-file fileId=/file/path\tUpload a file by creating a '<input type=\"file\" id=\"foo\" />'\n"
|
||||
"\t\t\t\tand calling phantom.setFormInputFile(document.getElementById('foo', 'fileId')." << std::endl;
|
||||
"\t\t\t\tand calling phantom.setFormInputFile(document.getElementById('foo', 'fileId')." << std::endl;
|
||||
}
|
||||
|
||||
class WebPage: public QWebPage
|
||||
|
@ -192,16 +194,21 @@ private slots:
|
|||
private:
|
||||
QString m_scriptFile;
|
||||
QStringList m_args;
|
||||
QString m_proxyHost;
|
||||
int m_proxyPort;
|
||||
QString m_loadStatus;
|
||||
WebPage m_page;
|
||||
int m_returnValue;
|
||||
QString m_script;
|
||||
QString m_state;
|
||||
CSConverter *m_converter;
|
||||
};
|
||||
|
||||
Phantom::Phantom(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_proxyPort(1080)
|
||||
, m_returnValue(0)
|
||||
, m_converter(0)
|
||||
{
|
||||
QPalette palette = m_page.palette();
|
||||
palette.setBrush(QPalette::Base, Qt::transparent);
|
||||
|
@ -244,6 +251,18 @@ Phantom::Phantom(QObject *parent)
|
|||
pluginsEnabled = false;
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--proxy=")) {
|
||||
m_proxyHost = arg.mid(8).trimmed();
|
||||
if (m_proxyHost.lastIndexOf(':') > 0) {
|
||||
bool ok = true;
|
||||
int port = m_proxyHost.mid(m_proxyHost.lastIndexOf(':') + 1).toInt(&ok);
|
||||
if (ok) {
|
||||
m_proxyHost = m_proxyHost.left(m_proxyHost.lastIndexOf(':')).trimmed();
|
||||
m_proxyPort = port;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (arg.startsWith("--")) {
|
||||
std::cerr << "Unknown option '" << qPrintable(arg) << "'" << std::endl;
|
||||
exit(-1);
|
||||
|
@ -259,6 +278,13 @@ Phantom::Phantom(QObject *parent)
|
|||
return;
|
||||
}
|
||||
|
||||
if (m_proxyHost.isEmpty()) {
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||
} else {
|
||||
QNetworkProxy proxy(QNetworkProxy::HttpProxy, m_proxyHost, m_proxyPort);
|
||||
QNetworkProxy::setApplicationProxy(proxy);
|
||||
}
|
||||
|
||||
// The remaining arguments are available for the script.
|
||||
while (argIterator.hasNext()) {
|
||||
const QString &arg = argIterator.next();
|
||||
|
@ -326,6 +352,12 @@ bool Phantom::execute()
|
|||
m_script.prepend("//");
|
||||
}
|
||||
|
||||
if (m_scriptFile.endsWith(".coffee")) {
|
||||
if (!m_converter)
|
||||
m_converter = new CSConverter(this);
|
||||
m_script = m_converter->convert(m_script);
|
||||
}
|
||||
|
||||
m_page.mainFrame()->evaluateJavaScript(m_script);
|
||||
return true;
|
||||
}
|
||||
|
@ -510,8 +542,6 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
app.setWindowIcon(QIcon(":/phantomjs-icon.png"));
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
TEMPLATE = app
|
||||
TARGET = phantomjs
|
||||
DESTDIR = ../bin
|
||||
SOURCES = phantomjs.cpp
|
||||
HEADERS += csconverter.h
|
||||
SOURCES = phantomjs.cpp csconverter.cpp
|
||||
RESOURCES = phantomjs.qrc
|
||||
QT += network webkit
|
||||
CONFIG += console
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>phantomjs-icon.png</file>
|
||||
<file>coffee-script.js</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Reference in New Issue