QWebEngineScript GM_Script::webScript() const { QWebEngineScript::InjectionPoint injectionPoint; switch (startAt()) { case DocumentStart: injectionPoint = QWebEngineScript::DocumentCreation; break; case DocumentEnd: injectionPoint = QWebEngineScript::DocumentReady; break; case DocumentIdle: injectionPoint = QWebEngineScript::Deferred; break; default: Q_UNREACHABLE(); } QWebEngineScript script; script.setName(fullName()); script.setWorldId(QWebEngineScript::MainWorld); script.setInjectionPoint(injectionPoint); script.setRunsOnSubFrames(!m_noframes); script.setSourceCode(QSL("%1\n%2").arg(m_manager->bootstrapScript(), m_script)); return script; }
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 WebScrollBarManager::createUserScript(int thickness) { QWebEngineScript script; script.setName(QSL("_kclient_scrollbar")); script.setInjectionPoint(QWebEngineScript::DocumentReady); script.setWorldId(WebPage::SafeJsWorld); script.setSourceCode(m_scrollbarJs.arg(thickness)); mApp->webProfile()->scripts()->insert(script); }
QWebEngineProfile* createWebEngineProfile(const WizWebEngineViewInjectObjects& objects, QObject* parent) { if (objects.empty()) return nullptr; // QWebEngineProfile *profile = new QWebEngineProfile("WizNoteWebEngineProfile", parent); // QString jsWebChannelFileName = Utils::WizPathResolve::resourcesPath() + "files/webengine/wizwebchannel.js"; QString jsWebChannel; WizLoadUnicodeTextFromFile(jsWebChannelFileName, jsWebChannel); // QString initFileName = Utils::WizPathResolve::resourcesPath() + "files/webengine/wizwebengineviewinit.js"; QString jsInit; WizLoadUnicodeTextFromFile(initFileName, jsInit); // CWizStdStringArray names; for (auto inject : objects) { names.push_back("\"" + inject.name + "\""); } // CString objectNames; WizStringArrayToText(names, objectNames, ", "); // jsInit.replace("__objectNames__", objectNames); // QString jsAll = jsWebChannel + "\n" + jsInit; // { QWebEngineScript script; script.setSourceCode(jsAll); script.setName("qwebchannel.js"); script.setWorldId(QWebEngineScript::MainWorld); script.setInjectionPoint(QWebEngineScript::DocumentCreation); script.setRunsOnSubFrames(true); profile->scripts()->insert(script); } // return profile; }