parent
08f3456e28
commit
51f0232ca3
10 changed files with 218 additions and 29 deletions
@ -1 +1 @@ |
||||
if(typeof GM_xmlhttpRequest==="undefined")GM_xmlhttpRequest=function(details){details.method=details.method.toUpperCase()||"GET";if(!details.url)throw"GM_xmlhttpRequest requires an URL.";var oXhr=new XMLHttpRequest;if(oXhr){if("onreadystatechange"in details)oXhr.onreadystatechange=function(){details.onreadystatechange(oXhr)};if("onload"in details)oXhr.onload=function(){details.onload(oXhr)};if("onerror"in details)oXhr.onerror=function(){details.onerror(oXhr)};oXhr.open(details.method,details.url,true);if("headers"in details)for(var header in details.headers)oXhr.setRequestHeader(header,details.headers[header]);if("data"in details)oXhr.send(details.data);else oXhr.send()}else throw"This Browser is not supported, please upgrade.";};if(typeof GM_addStyle==="undefined"){function GM_addStyle(styles){var head=document.getElementsByTagName("head")[0];if(head===undefined)document.onreadystatechange=function(){if(document.readyState=="interactive"){var oStyle=document.createElement("style");oStyle.setAttribute("type","text/css");oStyle.appendChild(document.createTextNode(styles));document.getElementsByTagName("head")[0].appendChild(oStyle)}};else{var oStyle=document.createElement("style");oStyle.setAttribute("type","text/css");oStyle.appendChild(document.createTextNode(styles));head.appendChild(oStyle)}}}if(typeof GM_log==="undefined"){function GM_log(log){if(console)console.log(log)}}if(typeof GM_openInTab==="undefined"){function GM_openInTab(url){window.open(url)}}var unsafeWindow=window;window.wrappedJSObject=unsafeWindow;if(typeof GM_registerMenuCommand==="undefined"){function GM_registerMenuCommand(caption,commandFunc,accessKey){}}if(typeof GM_getResourceText==="undefined"){function GM_getResourceText(resourceName){throw"QupZilla: GM Resource is not supported!";}}if(typeof GM_getResourceURL==="undefined"){function GM_getResourceURL(resourceName){throw"QupZilla: GM Resource is not supported!";}}if(typeof GM_getValue==="undefined"){function GM_getValue(name,defaultValue){return defaultValue}}if(typeof GM_setValue==="undefined"){function GM_setValue(name,value){}}if(typeof GM_deleteValue==="undefined"){function GM_deleteValue(name){}}if(typeof GM_listValues==="undefined"){function GM_listValues(){return new Array("")}}; |
||||
if(typeof GM_xmlhttpRequest==="undefined")GM_xmlhttpRequest=function(details){details.method=details.method.toUpperCase()||"GET";if(!details.url)throw"GM_xmlhttpRequest requires an URL.";var oXhr=new XMLHttpRequest;if(oXhr){if("onreadystatechange"in details)oXhr.onreadystatechange=function(){details.onreadystatechange(oXhr)};if("onload"in details)oXhr.onload=function(){details.onload(oXhr)};if("onerror"in details)oXhr.onerror=function(){details.onerror(oXhr)};oXhr.open(details.method,details.url, true);if("headers"in details)for(var header in details.headers)oXhr.setRequestHeader(header,details.headers[header]);if("data"in details)oXhr.send(details.data);else oXhr.send()}else throw"This Browser is not supported, please upgrade.";}; if(typeof GM_addStyle==="undefined"){function GM_addStyle(styles){var head=document.getElementsByTagName("head")[0];if(head===undefined)document.onreadystatechange=function(){if(document.readyState=="interactive"){var oStyle=document.createElement("style");oStyle.setAttribute("type","text/css");oStyle.appendChild(document.createTextNode(styles));document.getElementsByTagName("head")[0].appendChild(oStyle)}};else{var oStyle=document.createElement("style");oStyle.setAttribute("type","text/css");oStyle.appendChild(document.createTextNode(styles)); head.appendChild(oStyle)}}}if(typeof GM_log==="undefined"){function GM_log(log){if(console)console.log(log)}}if(typeof GM_openInTab==="undefined"){function GM_openInTab(url){window.open(url)}}if(typeof GM_getValueImpl==="undefined"){function GM_getValueImpl(namespace,name,value){return window._qz_greasemonkey.getValue(namespace,name,value)}}if(typeof GM_setValueImpl==="undefined"){function GM_setValueImpl(namespace,name,value){window._qz_greasemonkey.setValue(namespace,name,value)}} if(typeof GM_deleteValueImpl==="undefined"){function GM_deleteValueImpl(namespace,name){window._qz_greasemonkey.deleteValue(namespace,name)}}if(typeof GM_listValuesImpl==="undefined"){function GM_listValuesImpl(namespace){return window._qz_greasemonkey.listValues(namespace)}}var unsafeWindow=window;window.wrappedJSObject=unsafeWindow;if(typeof GM_registerMenuCommand==="undefined"){function GM_registerMenuCommand(caption,commandFunc,accessKey){}} if(typeof GM_getResourceText==="undefined"){function GM_getResourceText(resourceName){throw"QupZilla: GM Resource is not supported!";}}if(typeof GM_getResourceURL==="undefined"){function GM_getResourceURL(resourceName){throw"QupZilla: GM Resource is not supported!";}}; |
||||
|
||||
@ -0,0 +1,122 @@ |
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser |
||||
* Copyright (C) 2013 David Rosca <nowrep@gmail.com> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */ |
||||
#include "gm_jsobject.h" |
||||
|
||||
GM_JSObject::GM_JSObject(QObject* parent) |
||||
: QObject(parent) |
||||
, m_settings(0) |
||||
{ |
||||
} |
||||
|
||||
void GM_JSObject::setSettingsFile(const QString &name) |
||||
{ |
||||
if (m_settings) { |
||||
m_settings->sync(); |
||||
delete m_settings; |
||||
} |
||||
|
||||
m_settings = new QSettings(name, QSettings::IniFormat); |
||||
} |
||||
|
||||
QVariant GM_JSObject::getValue(const QString &nspace, const QString &name, const QVariant &dValue) |
||||
{ |
||||
QString valueName = QString("GreaseMonkey-%1/%2").arg(nspace, name); |
||||
QString savedValue = m_settings->value(valueName, dValue).toString(); |
||||
|
||||
if (savedValue.isEmpty()) { |
||||
return dValue; |
||||
} |
||||
|
||||
QString actualValue = savedValue.mid(1).trimmed(); |
||||
if (actualValue.isEmpty()) { |
||||
return dValue; |
||||
} |
||||
|
||||
switch (savedValue.at(0).toAscii()) { |
||||
case 'b': |
||||
return QVariant(actualValue == QLatin1String("true")); |
||||
|
||||
case 'i': { |
||||
bool ok; |
||||
int val = actualValue.toInt(&ok); |
||||
return ok ? QVariant(val) : dValue; |
||||
} |
||||
|
||||
case 's': |
||||
return actualValue; |
||||
|
||||
default: |
||||
break; |
||||
} |
||||
|
||||
return dValue; |
||||
} |
||||
|
||||
void GM_JSObject::setValue(const QString &nspace, const QString &name, const QVariant &value) |
||||
{ |
||||
QString savedValue; |
||||
|
||||
switch (value.type()) { |
||||
case QVariant::Bool: |
||||
savedValue = value.toBool() ? "btrue" : "bfalse"; |
||||
break; |
||||
|
||||
case QVariant::Int: |
||||
case QVariant::UInt: |
||||
case QVariant::LongLong: |
||||
case QVariant::ULongLong: |
||||
case QVariant::Double: |
||||
savedValue = "i" + QString::number(value.toInt()); |
||||
break; |
||||
|
||||
case QVariant::String: |
||||
savedValue = "s" + value.toString(); |
||||
break; |
||||
|
||||
default: |
||||
break; |
||||
} |
||||
|
||||
QString valueName = QString("GreaseMonkey-%1/%2").arg(nspace, name); |
||||
m_settings->setValue(valueName, savedValue); |
||||
} |
||||
|
||||
void GM_JSObject::deleteValue(const QString &nspace, const QString &name) |
||||
{ |
||||
QString valueName = QString("GreaseMonkey-%1/%2").arg(nspace, name); |
||||
m_settings->remove(valueName); |
||||
} |
||||
|
||||
QStringList GM_JSObject::listValues(const QString &nspace) |
||||
{ |
||||
QString nspaceName = QString("GreaseMonkey-%1").arg(nspace); |
||||
|
||||
m_settings->beginGroup(nspaceName); |
||||
QStringList keys = m_settings->allKeys(); |
||||
m_settings->endGroup(); |
||||
|
||||
return keys; |
||||
} |
||||
|
||||
GM_JSObject::~GM_JSObject() |
||||
{ |
||||
if (m_settings) { |
||||
m_settings->sync(); |
||||
delete m_settings; |
||||
} |
||||
} |
||||
@ -0,0 +1,45 @@ |
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser |
||||
* Copyright (C) 2013 David Rosca <nowrep@gmail.com> |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */ |
||||
#ifndef GM_JSOBJECT_H |
||||
#define GM_JSOBJECT_H |
||||
|
||||
#include <QObject> |
||||
#include <QStringList> |
||||
#include <QSettings> |
||||
#include <QVariant> |
||||
|
||||
class GM_JSObject : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
explicit GM_JSObject(QObject* parent = 0); |
||||
~GM_JSObject(); |
||||
|
||||
void setSettingsFile(const QString &name); |
||||
|
||||
public slots: |
||||
QVariant getValue(const QString &nspace, const QString &name, const QVariant &dValue); |
||||
void setValue(const QString &nspace, const QString &name, const QVariant &value); |
||||
void deleteValue(const QString &nspace, const QString &name); |
||||
QStringList listValues(const QString &nspace); |
||||
|
||||
private: |
||||
QSettings* m_settings; |
||||
}; |
||||
|
||||
#endif // GM_JSOBJECT_H
|
||||
Loading…
Reference in new issue