2012-10-27 4 views
1

저는 작은 Greasemonkey 스크립트를 작성하려고했습니다. 스크립트는 클래스의 내용을 받아서 다른 클래스로 변경합니다.Greasemonkey로 CSS 클래스를 변경하는 방법?

<ul class='user_type_1'> 

로 :
은 기본적으로는 바꿀 것

<ul class='administrator'> 

하지만, 자바 스크립트 & 그리스 몽키 완전히 녹색 해요, 그리고 내가 한 모든 연구는 나를 더욱 혼란 떠났다.

이상적으로는 (현재는 도움이 될지라도) 이상적으로 나는 이것을 달성하는 방법에 대해 누군가가 설명해 주길 바란다.

답변

3

이것은 매우 편리합니다 jQuery (자바 스크립트 유틸리티/라이브러리). jQuery는이 기능을 제공하기 위해 addClass()removeClass() 함수를 제공합니다. 여기

이다 완전한 클래스 변경 파이어 폭스 그리스 몽키 스크립트 :

// ==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"); 
관련 문제