如何使用Greasemonkey更改CSS类? [英] How to change CSS-classes with Greasemonkey?

查看:191
本文介绍了如何使用Greasemonkey更改CSS类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力开发一个小的Greasemonkey脚本,它接受一个类的内容并将其更改为另一个类。

基本上会改变:

I've been trying to gin up a small Greasemonkey script, that takes the content of a class and changes it to another class.
Basically it would change:

<ul class='user_type_1'>

into:

<ul class='administrator'>

但是,我完全是绿色的javascript& Greasemonkey和所有的研究,我只是让我更困惑。

But, I'm completely green to javascript & Greasemonkey, and all the research I did just left me even more confused.

理想情况下,我想要有人详细解释我如何实现这一点,而不是只是交出。

Ideally I would like someone to explain in detail HOW I achieve this, instead of just handing over a script that works (though currently even that would be a help).

推荐答案

这是非常容易的 jQuery (一个javascript实用程序/库)。 jQuery提供了 addClass() 的功能和 removeClass() ,以

This is super-easy with jQuery (a javascript utility/library). jQuery provides the functions addClass() and removeClass(), to make this a snap.

这是一个完整的Firefox Greasemonkey脚本,用于更改该类:

// ==UserScript==
// @name     _Change one class into another.
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant    GM_addStyle   
// ==/UserScript==
/*- The @grant directive is needed to work around a design change introduced
    in GM 1.0.   It restores the sandbox.
*/
//-- Get everything that has the class "user_type_1".
var userTypeNodes = $(".user_type_1");

userTypeNodes.removeClass ("user_type_1");
userTypeNodes.addClass ("administrator");

这篇关于如何使用Greasemonkey更改CSS类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆