6#include "webenginescript.h"
7using namespace WebEngineViewer;
9QString WebEngineScript::findAllImages()
11 const QString source = QStringLiteral(
14 "var imgs = document.getElementsByTagName('img');"
15 "for (var i = 0; i < imgs.length; ++i) {"
27QString WebEngineScript::findAllScripts()
29 const QString source = QStringLiteral(
32 "var scripts = document.getElementsByTagName('script');"
33 "for (var i = 0; i < scripts.length; ++i) {"
34 " var e = scripts[i];"
45QString WebEngineScript::findAllAnchors()
47 const QString source = QStringLiteral(
50 "var anchors = document.getElementsByTagName('a');"
51 "for (var i = 0; i < anchors.length; ++i) {"
52 " var r = anchors[i].getBoundingClientRect();"
54 " src: anchors[i].href,"
55 " title: anchors[i].title,"
56 " boudingRect: [r.top, r.left, r.width, r.height]"
65QString WebEngineScript::findAllAnchorsAndForms()
67 const QString source = QStringLiteral(
71 "var anchors = document.getElementsByTagName('a');"
72 "for (var i = 0; i < anchors.length; ++i) {"
74 " src: anchors[i].href,"
75 " title: anchors[i].title,"
76 " text: anchors[i].innerText"
79 "var forms = document.getElementsByTagName('form');"
82 " forms: forms.length"
90QString WebEngineScript::setElementByIdVisible(
const QString &elementStr,
bool visibility)
93 const QString source = QStringLiteral(
94 "var element = document.getElementById('%1'); "
96 " element.style.removeProperty( 'display' );"
101 const QString source = QStringLiteral(
102 "var element = document.getElementById('%1'); "
104 " element.style.display = \"none\";"
111QString WebEngineScript::searchElementPosition(
const QString &elementStr)
113 const QString source = QStringLiteral(
114 "var element = document.getElementById('%1'); "
116 " var geometry = element.getBoundingClientRect(); "
117 " [(geometry.left + window.scrollX), (geometry.top + window.scrollY)]; "
125 return QStringLiteral(
"document.documentElement.scrollTop");
128QString WebEngineScript::scrollPercentage(
int percent)
130 const QString source = QStringLiteral(
"var current = ") + scrollTop()
133 "var docElement = document.documentElement;"
134 "var height = docElement.clientHeight;"
135 "var newPosition = current + height * %1 /100;"
136 "window.scrollTo(window.scrollX, newPosition);")
141QString WebEngineScript::scrollUp(
int pixel)
143 const QString source = QStringLiteral(
"window.scrollBy(0, %1);").
arg(-pixel);
147QString WebEngineScript::scrollDown(
int pixel)
149 const QString source = QStringLiteral(
"window.scrollBy(0, %1);").
arg(pixel);
155 const QString source = QStringLiteral(
"window.scrollTo(%1, %2); [window.scrollX, window.scrollY];").
arg(pos.
x()).
arg(pos.
y());
159QString WebEngineScript::removeStyleToElement(
const QString &elementStr)
161 const QString source = QStringLiteral(
162 "var element = document.getElementById('%1'); "
164 " element.removeAttribute(\"style\");"
172 const QString source = QStringLiteral(
173 "var element = document.getElementById('%1'); "
175 " element.style = '%2';"
177 .
arg(elementStr, style);
181QString WebEngineScript::scrollToRelativePosition(qreal pos)
183 const QString source = QStringLiteral(
"window.scrollTo(window.scrollX, %1); [window.scrollX, window.scrollY];").
arg(pos);
187QString WebEngineScript::isScrolledToBottom()
189 return QStringLiteral(
191 "var docElement = document.documentElement;"
192 "var viewportHeight = docElement.clientHeight;"
196 " + viewportHeight >= document.body.scrollHeight;"
197 "return Boolean(isAtBottom); "
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:13 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.