I'm trying to build a greasemonkey script, Chrome's debugger doesn't even like my first few lines?
-
06-07-2019 - |
Question
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Hijack Example</title>
<script type="text/javascript" src="./jquery-1.2.1.js"></script>
<script type="text/javascript">
var preventDefaultAction = true; //TODO-U
var cmdSpecStr = 'C-l'; //TODO-U
...and that's where its getting stuck. Soo frustrating. Is there actually anything wrong with my syntax?
Btw, the complaint its giving me is
Uncaught ReferenceError: cmdSpecString is not defined
Solution
I've used Greasemonkey frequently, but only in Firefox. Immediately I notice a few things:
- Greasemonkey scripts are written in pure JS, using the syntax of this example. You're writing in HTML.
- Following from pure JS, there is no (direct) way to include another script.
- cmdSpecStr does not match cmdSpecString.
- There is no mention of cmdSpecString in the code you've posted.
EDIT: As noted, you can include other scripts using the DOM method, though it's usually not worth it.
OTHER TIPS
Regarding including other scripts, it's possible by adding script tags into DOM. Here's an example of adding jQuery into a greasemonkey script. http://joanpiedra.com/jquery/greasemonkey/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow