How to Change Class CSS with Greasemonkey/Tampermonkey Script?

DDD
Release: 2024-11-03 03:37:02
Original
244 people have browsed it

How to Change Class CSS with Greasemonkey/Tampermonkey Script?

Change Class CSS with Greasemonkey/Tampermonkey Script

To alter the background image of a specific class, such as "banner_url," you can leverage the CSS cascade by adding a stylesheet to the page using GM_addStyle().

// ==UserScript==
// @name     Override banner_url styles
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @grant    GM_addStyle
// @run-at   document-start
// ==/UserScript==

GM_addStyle ( `
    .banner_url {
        background: url('http://www.pxleyes.com/images/contests/kiwis/fullsize/sourceimage.jpg') no-repeat center center fixed !important;
        -webkit-background-size: cover !important;
        -moz-background-size: cover !important;
        -o-background-size: cover !important;
        background-size: cover !important;
    }
` );
Copy after login

By using @run-at document-start, you can minimize visual "flicker" during style changes. Note that for Greasemonkey 4, GM_addStyle() is not functional. It is recommended to switch to Tampermonkey or Violentmonkey. For Greasemonkey 4 users, a shim is provided for GM_addStyle(). Additionally, for pure CSS manipulation, consider using the Stylus extension instead of Greasemonkey/Tampermonkey.

The above is the detailed content of How to Change Class CSS with Greasemonkey/Tampermonkey Script?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template