load userstyles on demand

This commit is contained in:
Malte Jürgens 2023-02-17 15:47:36 +01:00
parent 78d43991ab
commit 63180f5d53
No known key found for this signature in database
GPG Key ID: D29FBD5F93C0CFC3
4 changed files with 39 additions and 3 deletions

View File

@ -157,6 +157,22 @@ function main() {
streamStartBtnClone.remove();
});
function updateUserstyles() {
userscript.log("Loading userstyles...");
let stylesheet = document.getElementById("discordScreenaudioUserstyles");
if (!stylesheet) {
stylesheet = document.createElement("style");
stylesheet.id = "discordScreenaudioUserstyles";
stylesheet.type = "text/css";
document.head.appendChild(stylesheet);
}
stylesheet.innerText = userscript.userstyles;
userscript.log("Finished loading userstyles");
}
userscript.userstylesChanged.connect(updateUserstyles);
setTimeout(() => updateUserstyles());
setInterval(async () => {
const streamActive =
document.getElementsByClassName("panel-2ZFCRb activityPanel-9icbyU")

View File

@ -20,6 +20,8 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) {
connect(this, &QWebEnginePage::featurePermissionRequested, this,
&DiscordPage::featurePermissionRequested);
connect(this, &DiscordPage::fullScreenRequested, MainWindow::instance(),
&MainWindow::fullScreenRequested);
setupPermissions();
@ -113,8 +115,8 @@ void DiscordPage::fetchUserStyles(QFile *file) {
return;
}
}
injectFile(&DiscordPage::injectStylesheet, "userstyles.js", file->fileName());
file->close();
qDebug(userstylesLog) << "Injecting userstyles";
m_userScript.setProperty("userstyles", fileContent);
file->deleteLater();
}

View File

@ -15,6 +15,8 @@ UserScript::UserScript() : QObject() {
setupShortcutsDialog();
setupStreamDialog();
setupVirtmic();
// connect(this, &UserScript::loadingMessageChanged, MainWindow::instance(),
// &MainWindow::setLoadingIndicator);
}
void UserScript::setupHelpMenu() {

View File

@ -18,6 +18,12 @@
#endif
#ifdef KNOTIFICATIONS
#include <KNotification>
#endif
#include <KJob>
class UserScript : public QObject {
Q_OBJECT
@ -27,18 +33,26 @@ public:
Q_PROPERTY(QString version READ version CONSTANT);
Q_PROPERTY(bool kxmlgui MEMBER m_kxmlgui CONSTANT);
Q_PROPERTY(bool kglobalaccel MEMBER m_kglobalaccel CONSTANT);
Q_PROPERTY(QString userstyles MEMBER m_userstyles NOTIFY userstylesChanged);
Q_PROPERTY(QString loadingMessage MEMBER m_loadingMessage NOTIFY
loadingMessageChanged);
private:
QProcess m_virtmicProcess;
StreamDialog *m_streamDialog;
bool m_kxmlgui = false;
bool m_kglobalaccel = false;
QString m_userstyles;
QString m_loadingMessage;
#ifdef KXMLGUI
KHelpMenu *m_helpMenu;
#ifdef KGLOBALACCEL
KActionCollection *m_actionCollection;
KShortcutsDialog *m_shortcutsDialog;
#endif
#endif
#ifdef KNOTIFICATIONS
KJob *m_loadingJob = nullptr;
#endif
void setupHelpMenu();
void setupShortcutsDialog();
@ -49,6 +63,8 @@ Q_SIGNALS:
void muteToggled();
void deafenToggled();
void streamStarted(bool video, int width, int height, int frameRate);
void userstylesChanged();
void loadingMessageChanged();
public Q_SLOTS:
void log(QString message);