summaryrefslogtreecommitdiff
path: root/plugin_loader/utilities.py
diff options
context:
space:
mode:
authorWerWolv <werwolv98@gmail.com>2022-04-12 21:59:09 +0200
committerWerWolv <werwolv98@gmail.com>2022-04-12 21:59:09 +0200
commitfe9faefd0bb01212299259bcdcc431d24493d963 (patch)
treea04b54f5660e6b55b4ac1272f79ae1a0c67e92c9 /plugin_loader/utilities.py
parent012274b1a09f6959d41e9aa8bd69f5c30cc8f871 (diff)
downloaddecky-loader-fe9faefd0bb01212299259bcdcc431d24493d963.tar.gz
decky-loader-fe9faefd0bb01212299259bcdcc431d24493d963.zip
Added functions to inject and remove css from tabs
Diffstat (limited to 'plugin_loader/utilities.py')
-rw-r--r--plugin_loader/utilities.py71
1 files changed, 69 insertions, 2 deletions
diff --git a/plugin_loader/utilities.py b/plugin_loader/utilities.py
index a1785c15..0d6c549b 100644
--- a/plugin_loader/utilities.py
+++ b/plugin_loader/utilities.py
@@ -1,5 +1,6 @@
from aiohttp import ClientSession
from injector import inject_to_tab
+import uuid
class Utilities:
def __init__(self, context) -> None:
@@ -8,7 +9,9 @@ class Utilities:
"ping": self.ping,
"http_request": self.http_request,
"confirm_plugin_install": self.confirm_plugin_install,
- "execute_in_tab": self.execute_in_tab
+ "execute_in_tab": self.execute_in_tab,
+ "inject_css_into_tab": self.inject_css_into_tab,
+ "remove_css_from_tab": self.remove_css_from_tab
}
async def confirm_plugin_install(self, request_id):
@@ -28,9 +31,47 @@ class Utilities:
async def execute_in_tab(self, tab, run_async, code):
try:
+ result = await inject_to_tab(tab, code, run_async)
+
+ if "exceptionDetails" in result["result"]:
+ return {
+ "success": False,
+ "result": result["result"]
+ }
+
+ return {
+ "success": True,
+ "result" : result["result"]["result"]["value"]
+ }
+ except Exception as e:
+ return {
+ "success": False,
+ "result": e
+ }
+
+ async def inject_css_into_tab(self, tab, style):
+ try:
+ css_id = str(uuid.uuid4())
+
+ result = await inject_to_tab(tab,
+ f"""
+ (function() {{
+ const style = document.createElement('style');
+ style.id = "{css_id}";
+ document.head.append(style);
+ style.sheet.insertRule(`{style}`);
+ }})()
+ """, False)
+
+ if "exceptionDetails" in result["result"]:
+ return {
+ "success": False,
+ "result": result["result"]
+ }
+
return {
"success": True,
- "result" : await inject_to_tab(tab, code, run_async)
+ "result" : css_id
}
except Exception as e:
return {
@@ -38,3 +79,29 @@ class Utilities:
"result": e
}
+ async def remove_css_from_tab(self, tab, css_id):
+ try:
+ result = await inject_to_tab(tab,
+ f"""
+ (function() {{
+ let style = document.getElementById("{css_id}");
+
+ if (style.nodeName.toLowerCase() == 'style')
+ style.parentNode.removeChild(style);
+ }})()
+ """, False)
+
+ if "exceptionDetails" in result["result"]:
+ return {
+ "success": False,
+ "result": result
+ }
+
+ return {
+ "success": True
+ }
+ except Exception as e:
+ return {
+ "success": False,
+ "result": e
+ }