void AutoScrollPlugin::updateScript() { const QString name = QSL("_qupzilla_autoscroll"); QWebEngineScript oldScript = mApp->webProfile()->scripts()->findScript(name); if (!oldScript.isNull()) { mApp->webProfile()->scripts()->remove(oldScript); } QWebEngineScript script; script.setName(name); script.setInjectionPoint(QWebEngineScript::DocumentCreation); script.setWorldId(QWebEngineScript::ApplicationWorld); script.setRunsOnSubFrames(false); QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat); settings.beginGroup(QSL("AutoScroll")); QString source = QzTools::readAllFileContents(QSL(":/autoscroll/data/autoscroll.js")); source.replace(QSL("%MOVE_SPEED%"), settings.value(QSL("Speed"), 5).toString()); source.replace(QSL("%CTRL_CLICK%"), settings.value(QSL("CtrlClick"), true).toString()); source.replace(QSL("%MIDDLE_CLICK%"), settings.value(QSL("MiddleClick"), true).toString()); source.replace(QSL("%IMG_ALL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_all.png")))); source.replace(QSL("%IMG_HORIZONTAL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_horizontal.png")))); source.replace(QSL("%IMG_VERTICAL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_vertical.png")))); script.setSourceCode(source); mApp->webProfile()->scripts()->insert(script); }
void AutoScrollPlugin::unload() { QWebEngineScript script = mApp->webProfile()->scripts()->findScript(QSL("_qupzilla_autoscroll")); if (!script.isNull()) { mApp->webProfile()->scripts()->remove(script); } }
QDebug operator<<(QDebug d, const QWebEngineScript &script) { if (script.isNull()) return d.maybeSpace() << "QWebEngineScript()"; d.nospace() << "QWebEngineScript(" << script.name() << ", "; switch (script.injectionPoint()) { case QWebEngineScript::DocumentCreation: d << "QWebEngineScript::DocumentCreation" << ", "; break; case QWebEngineScript::DocumentReady: d << "QWebEngineScript::DocumentReady" << ", "; break; case QWebEngineScript::Deferred: d << "QWebEngineScript::Deferred" << ", "; break; } d << script.worldId() << ", " << script.runsOnSubFrames() << ", " << script.sourceCode() << ")"; return d.space(); }