Grease Monkey Script无法运行 - 首次尝试脚本

时间:2012-05-24 13:18:10

标签: javascript greasemonkey

好的,所以我创建了一个小脚本,我想根据页面上某些标签中的数据更改表格行的格式,离线脚本工作正常,但我正在尝试调整它以提供as对于greasemonkey的用户脚本,首先我的脚本不会通过该站点安装,其次当我使用“新用户脚本”在本地安装时,它似乎什么都不做,也没有任何内容记录到控制台,继承我的代码:

// // ==UserScript==
// @name    Cerberus Time-since Row Colouring
// @author  David Duke, Luke Mulholland-Helme-Kelsall 
// @description Looks for ABBR tags and their title parameter, and then calculates the time difference between Now and the timestamps. The parent table row then has an appropraite CSS class added to it based on the time difference calculated.
// @include http://{removed url}/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require     http://www.datejs.com/build/date.js

// ==/UserScript==
$(document).ready(function(){
$('abbr').each(function(index){
    var _then = Date.parse($(this).attr('title'));
    var _now = new Date().getTime();
    _then = _then.getTime();            
    var a_minute = 60000;
    if(_now < _then + (a_minute*30)){
        $(this).parent(tr).css("background-color","green");
    } else if(_now < _then + (a_minute*60)){
        $(this).parent(tr).css("background-color","yellow");
    } else {
        $(this).parent(tr).css("background-color","red");
    }
    console.log("title:" + $(this).attr('title') + ",_then:"+_then+",_now:"+_now);
});
});

任何有关这方面的帮助都会很棒,因为我绞尽脑汁,可能与@require部分有关,但是我在google上发现的应该足以使用这些脚本中的功能。

2 个答案:

答案 0 :(得分:0)

// @include http://{removed url}/*

如果您的实际脚本与之匹配,则可能是问题...我在某处看到缺少空格会导致问题......

试试这个:

// @include     http://{removed url}/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js

答案 1 :(得分:-1)

你的问题是,你已经注释掉了,应该是什么,GM scipt声明。

而不是

// // ==UserScript==
// @name    Cerberus Time-since Row Colouring
// @author  David Duke, Luke Mulholland-Helme-Kelsall 
// @description Looks for ABBR tags and their title parameter, and then calculates the time difference between Now and the timestamps. The parent table row then has an appropraite CSS class added to it based on the time difference calculated.
// @include http://{removed url}/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require     http://www.datejs.com/build/date.js

// ==/UserScript==

使用:

// ==UserScript==
@name    Cerberus Time-since Row Colouring
@author  David Duke, Luke Mulholland-Helme-Kelsall 
@description Looks for ABBR tags and their title parameter, and then calculates the time difference between Now and the timestamps. The parent table row then has an appropraite CSS class added to it based on the time difference calculated.
@include http://{removed url}/*
@require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
@require     http://www.datejs.com/build/date.js

// ==/UserScript==

这将解决您的脚本检测或安装问题。