Skip to content

Question: How to injection css? #717

@getoutnow2013

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);
})();

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