简体   繁体   English

如何将 CSS 更改注入我的 Electron js 应用程序?

[英]How to Inject CSS changes into my Electron js app?

I use loadURL to load the web, I want to make some changes.我使用loadURL加载 web,我想做一些更改。 Is there a way to inject a css snippet once the page is rendered?有没有办法在页面呈现后注入 css 片段?

There are extensions for chrome that do what I want (like UserCSS), but I understand that they can't be used inside an Electron App. chrome 有一些扩展可以满足我的需求(比如 UserCSS),但我知道它们不能在 Electron 应用程序中使用。

在此处输入图像描述

After your page has completed loading...在您的页面完成加载后...

Here is an example of adding CSS:这是添加 CSS 的示例:

// When document has loaded, initialize
document.onreadystatechange = (event) => {
    if (document.readyState == "complete") {
        // Document has finished loading here
            var styles = `img#license {
                            animation: none;
                            animation-iteration-count: 1;
                            animation-fill-mode: forwards;
                            position: absolute;
                            z-index: 3;
                            width: 375px;
                            top: 204px;
                            left: 112px;
                            visibility: hidden;
                        }`
            var styleSheet = document.createElement("style");
            styleSheet.innerText = styles;
            document.head.appendChild(styleSheet);
    }
};

I use the above to display a unlicensed image over my Electron app from the preload.js script, as it has access to the document element.我使用上面的代码从 preload.js 脚本在我的 Electron 应用程序上显示未经许可的图像,因为它可以访问文档元素。

Edit the CSS to your needs.根据您的需要编辑 CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的外部 css 文件不会加载到 electron 应用程序中 - My external css file will not load in electron app 我创建了我的 react 应用程序并与 electron.js 连接。 现在如何将我的后端从服务器文件夹与电子连接 - I create a build of my react app and connected with electron.js. now how to connect my backend from server folder with electron 电子:如何在 2021 年通过 js 关闭应用程序? - Electron :how to close app via js in 2021? Electron 应用程序未找到包中包含的 CSS/JS - Electron app isn't finding CSS/JS included in package 当我构建我的下一个 js 应用程序时,css 文件没有得到最后的更改 - When i build my next js app, css files doesn't get last changes 我的应用程序没有关闭按钮,electron.js - My app doesn't close on button, electron.js 不能在我的 node.js 文件 electron 应用程序中使用 HTML ID 和 electron-db - cant use HTML ID in my node.js file electron app with electron-db 如何使用外部内容将jQuery注入Electron BrowserWindow - How to inject jQuery into Electron BrowserWindow with external content 如何使用NW.js(或电子版)向ubuntu应用指示器添加文本? - How to add text to ubuntu app indicator with with NW.js (or electron)? Selenium:如何启动使用 Main.js 作为参数的 electron 应用程序 - Selenium: How to start electron app that uses Main.js as argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM