Skip to content

Question: How to injection css? #717

Closed

Description

@getoutnow2013

I've make 2 scripts to inject.

TestAlert.js - is a simply javascript alert
TestHideCss.js - inject hide everything under body

But only alert shows, inject css is fail.
testUserScript1

How to inject css success? Can anyone give me a sample?
Thanks.

TestAlert.js Code:

// ==UserScript==
// @name         TestAlert
// @description  Alert
// @author       Userscripts
// @version      0.0.1
// @match        *://*/*
// @grant        none
// @inject-into  content
// ==/UserScript==

(function () {
  alert("This is a test script");
})();

TestHideCss.js Code:

// ==UserScript==
// @name         TestHideCss
// @description  Test CSS
// @version      0.0.1
// @author       getoutnow
// @match        *://*/*
// @grant        GM_addStyle
// ==/UserScript==

(function () {
  const myStyleCss = `body.readable { display:none !important; }`;
  document.body.className += 'readable';
  GM_addStyle(myStyleCss);
})();

Activity

  1. Repository owner locked and limited conversation to collaborators on Sep 15, 2024
  2. converted this issue into a discussion #718 on Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions