| 69 | } |
| 70 | |
| 71 | void GM_Plugin::populateWebViewMenu(QMenu* menu, WebView* view, const WebHitTestResult& r) |
| 72 | { |
| 73 | Q_UNUSED(r) |
| 74 | |
| 75 | if (!m_manager->isEnabled()) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | if (m_manager->contextMenuScripts().isEmpty()) { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | const QUrl url = view->url(); |
| 84 | QList<GM_Script*> matchingScripts; |
| 85 | |
| 86 | auto contextMenuScripts = m_manager->contextMenuScripts(); |
| 87 | for (const auto &script : std::as_const(contextMenuScripts)) { |
| 88 | if (script->match(url)) { |
| 89 | matchingScripts.append(script); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (matchingScripts.isEmpty()) { |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | auto* gmMenu = new QMenu(tr("GreaseMonkey")); |
| 98 | gmMenu->setIcon(QIcon(QSL(":gm/data/icon.svg"))); |
| 99 | |
| 100 | for (const auto &script : std::as_const(matchingScripts)) { |
| 101 | gmMenu->addAction(script->icon(), script->name(), this, [script, view]() { |
| 102 | view->page()->execJavaScript(script->webScript().sourceCode(), WebPage::SafeJsWorld); |
| 103 | }); |
| 104 | } |
| 105 | |
| 106 | menu->addMenu(gmMenu); |
| 107 | } |
| 108 | |
| 109 | bool GM_Plugin::acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) |
| 110 | { |
nothing calls this directly
no test coverage detected