Is greasemonkey a built-in extension of Google's Chrome? - javascript

I'm trying both greasemonkey and Google's Chrome extensions. And found that Chrome seems to be using the same API names as GM. (I seem to be having the same bug...)
Just wondering whether greasemonkey is already a Google Chrome extension?

Yes, I believe you can just add Greasemonkey scripts and Chrome installs them as an 'extension' like all the other native extensions.
Checkout this article:
http://lifehacker.com/5461675/chrome-4-supports-greasemonkey-userscripts-without-an-extension
Note, however that some scripts seem to be supported on GreaseMonkey for Firefox only and can be a little buggy in Chrome. I'm not sure of the exact differences in implementation.
Simon.

#Simon pretty much hit it, but I wanted to make sure that this point is super-clear.
Google Chrome supports Greasemonkey scripts natively, using the same API so as to make existing scripts compatible. There's no Greasemonkey extension required.

Yes, Chrome supports userscripts but not fully as Greasemonkey. For example check out this userscript
Docs Online Viewer: http://userscripts.org/scripts/show/127774
It works well with Greasemonkey (in Firefox) but not with Chrome natively. There are many Greasemonkey functions that Chrome does not support yet.

I copy and paste a post from GreaseMonkey:
There is no greasemonkey extension for google chrome. What actually happened is chromium (the project which google chrome is based) developed it's own extension system and one component of that extension mechanism (probably inspired heavily by greasemonkey in the first place) works in almost exactly the same way (an external javascript interacting with a page purely through it's DOM) as greasemonkey. The chromium system uses a completely different api but effectively does the same thing. This large overlap in purpose and functionality combined with the popularity of greasemonkey on firefox meant they decided to implement the greasemonkey api (the majority of it anyway) natively within chromium. From there they went one step further and had the browser automatically wrap any greasemonkey scripts inside a chromium extension automatically and effectively made greasemonkey scripts a first class citizen.

Related

Automatically run JavaScript code upon loading a specific website

I've written scripts to filter out threads and posts in a programming forum by author.
But you need to post the code into the web console for each page individually.
I was wondering if it were possible and if so how (using either firefox or chrome), to set your browser up to run a specific script upon loading a specific site? Is it possible as an extension or plugin?
You can use Tampermonkey for Google Chrome
Tampermonkey is the most popular userscript manager for Google Chrome.
Greasemonkey for Firefox:
Allows you to customize the way a web page displays or behaves, by using small bits of JavaScript.
You can use dotjs.
dotjs is a Google Chrome extension that executes JavaScript files in ~/.js based on their filename.
If you navigate to http://www.google.com/, dotjs will execute ~/.js/google.com.js.
This makes it super easy to spruce up your favorite pages using JavaScript.

How can I convert a Greasemonkey script into a restartless Firefox addon?

I need to convert a Greasemonkey script into a restartless Firefox addon.
It used to be possible to do this very easily using the Scriptify extension, but the extension has not been kept up to date with the latest changes to the Firefox browser, and no longer works.
Is there an alternate way to accomplish this?
It turns out, the developer of the Scriptify extension has updated his extension for compatibility with the newer Firefox browsers. Hooray! :)
UPDATE Now that Firefox has implemented the WebExtensions API for Firefox Extensions, it means its very easy to create restartless Firefox extensions from Greasemonkey scripts, as Firefox extensions built with the "Web Extensions" API are by default restartless, and you can include the gm script as a content script in the Firefox extension.
For an example of how to create a Firefox Extension using the new WebExtensions API, see here: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Your_first_WebExtension

Difference between JavaScript Extensions and NPAPI plugins with respect to performance

I have written a windowless NPAPI plugin which binds to a shared library for accessing my native resources. The plugin is loaded by a web Application running in Firefox browser.
Recently, I have seen in net, that using Java Script extensions, one can also make native code function calls.But these Java Script extensions are specific to browsers.
Can some one please tell me that if I use a Java Script extension instead of NPAPI plugin for calling my native code, will there be any performance improvement in terms of latency in making native library API calls?
Kindly note: My query is generic and not specifically for Firefox browser.
There is no generic answer to a question like this, the mechanisms implemented by different browsers have nothing in common.
Firefox: A native library can be called via js-ctypes. This mechanism should be more light-weight than the communication with an NPAPI plugin. Even more importantly, you don't have the overhead of inter-process communication (newer Firefox versions run plugins in separate processes).
Chrome: AFAIK the only way to access operating system functionality (such as writing files to a random location on disk) is via NPAPI, Chrome won't allow extensions to use system libraries. However, if you use a native library only to speed up execution and don't mind having this code run in a sandbox - the native client might work for you. Due to sandboxed execution it will probably be slower than an NPAPI plugin but it won't trigger huge scary warnings when your extension is installed.
Safari: From what I know, Safari doesn't let you use native libraries, not even via NPAPI plugins.
Internet Explorer: As of MSIE 9.0, Internet Explorer still doesn't have anything resembling JavaScript-based extensions.

What's a simple way in Google Chrome to insert Javascript into sites?

I would like to be able to add custom snippets of javascript to any site that matches a regex. This is mostly because of sites that I use daily because of specialized content, but which have a poor design. I want to be able to do something like:
Visit site See that sidebar overwrites content
Whip out developer tools, find div id for sidebar
Edit a snippet of javascript which is executed on document.ready for this domain:
$('#sidebar-right').remove();
A bit of searching for user scripts tells me that I need to be writing a Chrome extension, which seems unfortunate and overkill. Is there not an easier way, or an extension which is nothing but a javascript editor that assigns snippets to domains? I'd really like to be able to edit in Chrome itself, or at least have a file that I can just leave open in MacVim all the time. An extension requires unloading/installing to update as far as I can tell.
If I just had one big javascript file, that would be fine. I'd just wrap my customizations in domain checks.
Bonus love if I can write in CoffeeScript.
The answer is to use the Tampermonkey chrome extension.
https://chrome.google.com/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo
Why not dotjs http://defunkt.io/dotjs/ ? It's local, you can version it with git, you can easily take it to another computer...
Another alternative that neatly solves the problem is Custom JavaScript for websites. You just need to install the extension, which takes around 2 seconds, and then you can immediately start typing your custom JavaScript for the specified website.
The extension automatically recognizes the current website, so all you need to do is write your code and click on Save. You can also easily import jQuery or your external scripts for convenience.
Custom JavaScript for Websites 2 is an alternative to Custom JavaScript for Websites, with some bug fixes and sync scripts across devices feature.
Snippets are available directly in Chrome Devtools
https://developers.google.com/web/tools/chrome-devtools/javascript/snippets
Witchcraft is another Google Chrome extension for loading custom Javascript and CSS, and it is supposedly for more avanced users. The older dotjs project repository lists Witchcraft as its successor.
What you're looking for is Greasemonkey. But wait, Greasemonkey is for Firefox only, right? Turns out, you can install Greasemonkey user-scripts as native Chrome add-ons. Just go to userscripts.org and hit the Install button on one of them, and Chrome will automatically convert it into a native add-on. Then, write your own and install it using Chrome.
Note: This only works in Chrome 4.0.

How to create a browser plug in?

I have to create a plug-in that will have to display information when user hovers over certain terms. Can anyone show me the direction how to do it?
I do not have much ideas about creating plug-ins. I know what i want to do can be done by java script. But can a java script file be installed as a browser plug in? any ideas on this will be appreciated! Thanks!
What you want to do is create a userscript. It's exactly what you're describing: a piece of javascript code installed in the browser as a plugin.
Userscripts are supported:
By Firefox using Greasemonkey
By IE with its own version of Greasemonkey
Natively (soon) by Google Chrome
Natively by Opera
And even by Safari
So support is on almost every major browser.
A userscript is the easiest solution for what you're trying to do.
Kango's Content Scripts are similar to userscripts, with perhaps better support for all browsers, and the extension (and thus also the user script) can be installed with one click if self-hosted instead of installing Greasemonkey separately.

Categories