WebBrowser/Tools/Scripts.py

branch
QtWebEngine
changeset 4729
fc8d00860717
parent 4728
0367675d783d
child 4731
67d861d9e492
--- a/WebBrowser/Tools/Scripts.py	Mon Feb 08 20:56:16 2016 +0100
+++ b/WebBrowser/Tools/Scripts.py	Tue Feb 09 20:29:26 2016 +0100
@@ -76,3 +76,44 @@
     
     style = css.replace("'", "\\'").replace("\n", "\\n")
     return source.format(style)
+
+
+def toggleMediaPause(pos):
+    """
+    Function generating a script to toggle the paused state of a media element.
+    
+    @param pos position of the media element
+    @type QPoint
+    @return script to toggle the element paused state
+    @rtype str
+    """
+    source = """
+        (function() {{
+            var e = document.elementFromPoint({0}, {1});
+            if (!e)
+                return;
+            if (e.paused)
+                e.play();
+            else
+                e.pause();
+            }})()"""
+    return source.format(pos.x(), pos.y())
+
+
+def toggleMediaMute(pos):
+    """
+    Function generating a script to toggle the mute state of a media element.
+    
+    @param pos position of the media element
+    @type QPoint
+    @return script to toggle the element mute state
+    @rtype str
+    """
+    source = """
+        (function() {[
+            var e = document.elementFromPoint({0}, {1});
+            if (!e)
+                return;
+            e.muted = !e.muted;
+            }})()"""
+    return source.format(pos.x(), pos.y())

eric ide

mercurial