0

I'm using NinjaKit in Safari (Same as Greasemonkey). The codes are like this

// ==UserScript==
// @name          demo
// @namespace     http://dailymed.nlm.nih.gov/
// @include       http://dailymed.nlm.nih.gov/dailymed/*
// @require      http://code.jquery.com/jquery-1.11.0.min.js
// @require      http://johannburkard.de/resources/Johann/jquery.highlight-4.closure.js
// ==/UserScript==
$(document).ready(function () {
    document.title = 'Hello!' + document.title;
    alert("ZaiJian");

    $("body p").highlight(["a"]);
});

When I visit this page, the alert can be displayed well, but the .highlight function which depends on jQuery.highlight and jQuery doesn't work. It says:

TypeError: 'undefined' is not a function (evaluating 'c.toUpperCase()')

And I find it quite hard to debug this.. Does anyone have ideas about it?

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237

2 Answers2

1

I believe that NinjaKit currently doesn't do @require. Here's an example I made, that works in Firefox/GreaseMonkey and not in Safari/Ninjakit:

// ==UserScript==
// @name           DEBUG
// @include       http://localhost/Library.html
// @require  file:///Users/#######/Sites/hello_world.js 
// @require  http://localhost/~#######/hello_world.js  // EITHER WAY
// ==/UserScript==
alert('activated');
hello_world();

# hello_world.js

function hello_world(){
    alert('Hello World!');
}

Either as a "remote" address or a local file, it worked fine in GreaseMonkey and failed in Safari. It's hard to get the ins-and-outs of NinjaKit currently, in my experience.

  • I am only addressing the NinjaKit for Safari, a table I saw listed NinjaKit as having require, but that may be the Chrome NinjaKit only. http://ss-o.net/safari/extension/NinjaKit.safariextz – David Pennell Dec 29 '15 at 00:54
0

You need to read relevant docs before using the jQuery plugin.

First,

Create an entry in your style sheet for the highlight class.

.highlight { background-color: yellow }

In Greasemonkey, the equivalent of that is GM_addStyle('.highlight { background-color: yellow }');.

Second,

To highlight all occurrances of “bla” (case insensitive) in all li elements, use the following code:

$('li').highlight('bla');

You should have left out the brackets, i.e. $("body p").highlight("a");.

Third, I don't think you need $(document).ready() as Greasemonkey scripts are, by default, executed upon DOMContentLoaded event.

Putting it all together:

// ==UserScript==
// @name          demo
// @namespace     http://dailymed.nlm.nih.gov/
// @include       http://dailymed.nlm.nih.gov/dailymed/*
// @require       http://code.jquery.com/jquery-1.11.0.min.js
// @require       http://johannburkard.de/resources/Johann/jquery.highlight-4.closure.js
// @grant         GM_addStyle
// ==/UserScript==
GM_addStyle('.highlight { background-color: yellow }');
document.title = 'Hello!' + document.title;
$("body p").highlight("a");
Community
  • 1
  • 1
zanetu
  • 3,740
  • 1
  • 21
  • 17
  • @Salvatore Di Fazio It works for me at the moment. (No error in my console.) What's the complete error message did you get and what browser (including version) are you using? – zanetu Jul 25 '14 at 02:03
  • @Salvatore Di Fazio Another question: are you testing my code on http://dailymed.nlm.nih.gov or another website? – zanetu Jul 25 '14 at 02:17