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

8

26

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.

Achondrite answered 24/8, 2011 at 6:52 Comment(4)
I wonder... would this be possible to do without an extension?Phip
@bhuga, can you change the accepted answer please? dotjs is no longer maintained, and your answer about tampermonkey should be the accepted oneTribunate
Done. Thanks for the suggestion.Achondrite
Is this possible to do without an extension? as extensions has rights to read all data and websites we visit.Selie
A
18

The answer is to use the Tampermonkey chrome extension.

https://chrome.google.com/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo

Achondrite answered 22/9, 2011 at 16:9 Comment(0)
B
13

Why not dotjs http://defunkt.io/dotjs/ ? It's local, you can version it with git, you can easily take it to another computer...

Basidium answered 22/9, 2011 at 21:28 Comment(3)
Sadly this is only OSX though.Programmer
Sadly this extension is no longer maintained.Doorbell
Dotjs now mentions Witchcraft as its successor.Haftarah
I
6

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.

Custom JavaScript for websites example

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.

Isabellaisabelle answered 25/4, 2016 at 16:48 Comment(1)
curious what's the advantage of this vs tampermonkey.Tensible
U
4

Custom JavaScript for Websites 2 is an alternative to Custom JavaScript for Websites, with some bug fixes and sync scripts across devices feature.

Unpaidfor answered 11/10, 2017 at 3:21 Comment(0)
H
4

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.

Witchcraft toolbar menu

Haftarah answered 24/12, 2019 at 14:52 Comment(0)
S
3

Snippets are available directly in Chrome Devtools

https://developers.google.com/web/tools/chrome-devtools/javascript/snippets

enter image description here

Sherasherar answered 29/4, 2019 at 14:33 Comment(0)
B
1

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.

Burrows answered 24/8, 2011 at 7:1 Comment(3)
Firefox is great for having Greasemonkey, but it's so cool that Chrome supports those user-scripts natively. Much easier to manage them as add-ons than in a separate Greasemonkey interface.Burrows
This isn't quite what I want, unfortunately. There's no easy way to edit those in a hurry, or create a new one from scratch. I'm not really interested in community user scripts--this is about personal customization.Achondrite
You can make them really quickly (see this one), and make a simple HTML file that hosts them, and open them locally. What's so hard about it?Burrows
G
1

In 2024: Violentonkey is open source alternative to the now-proprietary Tampermonkey

Gustie answered 4/1 at 0:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.