Giter VIP home page Giter VIP logo

dotjs's Introduction

This project is archived and no longer mainted.

Check out its successor, which is way better and runs on all platforms:

Witchcraft

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.

On subdomains such as http://gist.github.com dotjs will try to load ~/.js/gist.github.com.js as well as ~/.js/github.com.js and ~/.js/com.js.

Bonus: files in ~/.js have jQuery 1.9 loaded, regardless of whether the site you're hacking uses jQuery.

Double bonus: ~/.js/default.js is loaded on every request, meaning you can stick plugins or helper functions in it.

GreaseMonkey user scripts are great, but you need to publish them somewhere and re-publish after making modifications. With dotjs, just add or edit files in ~/.js.

Example

$ cat ~/.js/github.com.js
// swap github logo with trollface
$('a[class^=header-logo-]').html(
    $('<img>')
        .attr('src', '//bit.ly/ghD24e')
        .css({'width': 'auto', 'height': '22px'})
    );

How It Works

Chrome extensions can't access the local filesystem, so dotjs runs a tiny web server on port 3131 that serves files out of ~/.js.

You don't have to worry about starting or stopping this web server because we put a pretty great plist into ~/Library/LaunchAgents that handles all that for us.

The dotjs Chrome extension then makes ajax requests to http://localhost:3131/convore.com.js any time you hit a page on convore.com, for example, and executes the returned JavaScript.

Requires

  • OS X
  • Ruby 1.8
  • rake (gem install rake)
  • Google Chrome
  • /usr/local/bin in your $PATH

Install it

git clone http://github.com/defunkt/dotjs
cd dotjs
rake install

Now open https://localhost:3131 in Chrome and follow these steps:

  • Click the "X" Padlock icon in the address bar
  • Click "Certificate Information"
  • Drag the large cert icon to your desktop
  • Open it with Keychain
  • Configure its Trust section as shown: http://cl.ly/Pdny

Finally install the Google Chrome extension:

http://bit.ly/dotjs

Uninstall it

rake uninstall

Credits

"I almost wish you could just stick JavaScript in ~/.js. Do you know what I'm saying?"

Linux

Windows

Other Browsers

dotjs's People

Contributors

adamvduke avatar arvindsv avatar byroot avatar capitalist avatar chris123457 avatar cobracmder avatar crzidea avatar danp avatar defunkt avatar efrane avatar fukayatsu avatar hujinpu avatar jaw6 avatar jayproulx avatar jc00ke avatar jdan avatar jimbly avatar johan avatar josh avatar maena avatar schacon avatar smgt avatar stroborobo avatar surma avatar theshortcut avatar tmuellerleile avatar to1ne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dotjs's Issues

Only listen on localhost

There's no reason to have WEBrick listen on all IP addresses. As-is, any JS containing sensitive information could be exposed. While keeping credentials in the JS isn't a great practice, it's one thing for a user to store it in their home directory, and another to potentially have it exposed to anyone on the same network.

Updating dotjs

There shouldn't be a better way of updating process for updating the dots daemon? For what I know the procedure is: git pull, then uninstall it and install it again... wouldn't it be better to have an 'atomic' process like a rake task, or perform the whole installing/updating process via homebrew (don't know if this is possible because of permissions and stuff)?

Permission denied launching agent on OS X 10.8

Running rake without sudo:

~/code/dotjs: rake install
(in /Users/morgan/code/dotjs)
dotjs
-----
I will install:

1. djsd(1) in /usr/local/bin
2. com.github.dotjs in ~/Library/LaunchAgents

Ok? (y/n) y
cp -p bin/djsd /usr/local/bin
chmod 644 /Users/morgan/Library/LaunchAgents/com.github.dotjs.plist
starting djdb...
launchctl load -w /Users/morgan/Library/LaunchAgents/com.github.dotjs.plist
Could not open job overrides database at: /private/var/db/launchd.db/com.apple.launchd/overrides.plist: 13: Permission denied
launch_msg(): Socket is not connected

IMPORTANT! Drag builds/dotjs.crx to Google Chrome.
Chrome won't let me install it for you :(

dotjs installation failed
check console.app or open an issue

Running rake with sudo:

~/code/dotjs: sudo rake install
(in /Users/morgan/code/dotjs)
dotjs
-----
I will install:

1. djsd(1) in /usr/local/bin
2. com.github.dotjs in ~/Library/LaunchAgents

Ok? (y/n) y
cp -p bin/djsd /usr/local/bin
chmod 644 /Users/morgan/Library/LaunchAgents/com.github.dotjs.plist
starting djdb...
launchctl load -w /Users/morgan/Library/LaunchAgents/com.github.dotjs.plist
launchctl: Dubious ownership on file (skipping): /Users/morgan/Library/LaunchAgents/com.github.dotjs.plist
nothing found to load
rake aborted!
Command failed with status (1): [launchctl load -w /Users/morgan/Library/La...]
/Users/morgan/code/dotjs/Rakefile:54
(See full trace by running task with --trace)

I am using Terminal.app on a fresh install of Mountain Lion and I am not logged in remotely.

jquery hotkeys?

If people are constantly adding keyboard shortcuts, it'd be nice to provide a helper.

Chrome extension does not appear installed

Hey there. I'm running on:

OS X 10.7
latest Chrome 18.0.1025.142
Ruby 1.8.7

I cloned dotjs into ~/src
I ran rake install

~/src/dotjs: rake install
dotjs
-----
I will install:

1. The 'dotjs' Google Chrome Extension
2. djsd(1) in /usr/local/bin
3. com.github.dotjs in ~/Library/LaunchAgents

Ok? (y/n) y
Installing Google Chrome extension...
open -a 'Google Chrome' builds/dotjs.crx &
cp -p bin/djsd /usr/local/bin
cp com.github.dotjs.plist /Users/msutherl/Library/LaunchAgents/com.github.dotjs.plist
starting djdb...
launchctl load -w /Users/msutherl/Library/LaunchAgents/com.github.dotjs.plist
dotjs installation worked
drop files like google.com.js in ~/.js and enjoy hacking the web

In ~/.js I have a file called: github.com.js. Its contents are:

~: cat ~/.js/github.com.js 
$('#header .logo img')
        .css('width', '100px')
        .css('margin-top', '-15px')
        .attr('src', '//bit.ly/ghD24e')

And it doesn't work. Console.log shows the server is running with no errors. Nothing shows up in the Chrome console.

My hunch is that the extension is not installed. When I look in the Chrome extensions page, there's no mention of dotjs.

I've tried uninstalling and reinstalling. I've tried manually double-clicking on the extension file. When I do so, "open -a Chrome" appears to work, but the extension is not installed to my knowledge.

Any idea why this might be happening?

log: no dotjs server found at localhost:3131

My .js isn't getting executed and I found this in the log:

no dotjs server found at localhost:3131

I guess the tiny webserver isn't getting started, I tried rebooting and shutting down other webservers and any other crazy proxy shit like Charles, just to make sure the port wasn't already being listened on.. Also checked netstat and I couldn't see anything using :3131.

I feel like a dummy but I'm out of ideas, any thoughts on how to resolve this?

Maybe not related, but I got this same origin policy notice as well, just above the "no dotjs server" line:

XMLHttpRequest cannot load http://localhost:3131/github.com.js. Origin https://github.com is not allowed by Access-Control-Allow-Origin.

jQuery update

jQuery (i.6.?) is pretty old, and there's a lot of updated/better functionality in newer versions.

Internal Server Error and not running at all?

I installed it, then made a directory in my home folder called .js like: ~/.js and then added your sample github.com.js file and code but nothing is happening. Also tried a google.com.js file and still nothing.

I asked around on Twitter and Google+ and some others had this exact same issue. Here's a snap:
screenshot

I really want to start hacking on this, but I have no idea what to do. The install seemed to have gone perfectly:

Cloning into dotjs...
remote: Counting objects: 236, done.
remote: Compressing objects: 100% (110/110), done.
remote: Total 236 (delta 119), reused 210 (delta 99)
Receiving objects: 100% (236/236), 344.72 KiB | 56 KiB/s, done.
Resolving deltas: 100% (119/119), done.
Oscar-Godsons-Mac-mini:Dropbox oscargodson$ cd dotjs/
Oscar-Godsons-Mac-mini:dotjs oscargodson$ rake install
(in /Users/oscargodson/Dropbox/dotjs)
dotjs
-----
I will install:

1. The 'dotjs' Google Chrome Extension
2. djsd(1) in /usr/local/bin
3. com.github.dotjs in ~/Library/LaunchAgents

Ok? (y/n) y
Error: Can't write to /usr/local/bin. Try again using `sudo`.
Oscar-Godsons-Mac-mini:dotjs oscargodson$ sudo rake install
Password:
(in /Users/oscargodson/Dropbox/dotjs)
dotjs
-----
I will install:

1. The 'dotjs' Google Chrome Extension
2. djsd(1) in /usr/local/bin
3. com.github.dotjs in ~/Library/LaunchAgents

Ok? (y/n) y
cp -p bin/djsd /usr/local/bin
chmod 644 /Users/oscargodson/Library/LaunchAgents/com.github.dotjs.plist
starting djdb...
Installing Google Chrome extension...
dotjs installation worked
drop files like google.com.js in ~/.js and enjoy hacking the web

Lastly the Chrome extension seems to be there:
screenshot

Any ideas? I'm getting antsy to hack on Google+ and their redesign

rake install: ~/.js/ owner is root by default

You need to be root to write to /usr/local/bin/, so rake install needs to be executed as root. But the installation process also creates ~/.js/ if it doesn't exist, therefore the dir will be owned by root and the normal user can't write to it unless he uses sudo or (sudo+) chown.

Include stylesheets from .css

Could you provide the same functionality, but for .css files? (in ~/.css).

I'd like this feature, primarily because it's safer to include unknown CSS files than JS, and it's hard to add additional styles solely in .js files.

dotjs - very dynamic sites

I've been trying to mess around with Gmail using dotjs, since I'm trying to get rid of my greasemonkey and stylish scripts (cross-browser rocks!). However, it looks like the ~/.js scripts are loaded too early. So, the scripts don't work.

I think that this is because ~/.js scripts are loaded before the Gmail javascripts finish changing some things dynamically. Also, in the Chrome extension, it says something about loading the content script at document_start. Looking at this, should it be document_end, or is dotjs not the right option for what I'm doing? What do you think?

Stylish works, in this case.

Security hole where a site may steal user scripts

Due to Access-Control-Allow-Origin: *, any site may fetch any user script that exists on the user's system. A malicious site may try many domains to scrape as many user scripts as possible. Besides, site-specific scripts, they'll always be able to get the contents of default.js, which likely isn't as important as securing the site-specific user scripts.

For example, if I create a ~/.js/example.com.js file and then go to any site and do an XHR request from the command line to http://localhost:3131/example.com.js, I will be able to get the response with the default.js appended with whatever I put in example.com.js

Might a solution be for the WEBrick server to check the Referer header and verify that the request is authorized? Alternatively, there could be a secret key that the Chrome extension sends along with the request which must be validated by WEBrick.

Latest Chrome (18) not supported?

Chrome 18.0.1010.0 dev, as of writing on OSX 10.7, using git master.

jQuery fails to load now, preventing dotjs from ever succeeding in doing anything.

These errors show up in the js console on every page load:

Uncaught TypeError: Cannot read property 'firstChild' of null        chrome-extension://bddflceddabhdabcnlilghjgcfenejpa/jquery.js:16
Uncaught ReferenceError: $ is not defined                            chrome-extension://bddflceddabhdabcnlilghjgcfenejpa/dotjs.js:1

Any thoughts on what might be the problem?

Redirect with window.location doesn't work

I have the following situation:

I want to do a redirect after the change of a select input, but window.location doesn't work.

I have something like this

$("select").change(function(){
  window.location = "http://google.com"
});

Is there a reason for this?

Thanks for the feedback

dotjs installation failed

Got errors when trying to install:

edge/dotjs[master]% rake install
(in /Users/josh/code/edge/dotjs)
dotjs
-----
I will install:

1. The 'dotjs' Google Chrome Extension
2. djsd(1) in /usr/local/bin
3. com.github.dotjs in ~/Library/LaunchAgents

Ok? (y/n) y
Installing Google Chrome extension...
open -a 'Google Chrome' builds/dotjs.crx &
cp bin/djsd /usr/local/bin
cp com.github.dotjs.plist /Users/josh/Library/LaunchAgents/com.github.dotjs.plist
starting djdb...
launchctl load -w /Users/josh/Library/LaunchAgents/com.github.dotjs.plist
dotjs installation failed
check console.app or open an issue

And here is the console.app output:

https://img.skitch.com/20110219-t6yb5qey2g9ttrntw7dnd2ij25.jpg

Broken in latest Chrome?

Last week I upgraded from v11. to 13.0.782.112. Ever since then dotjs has stopped working. I looked into it and the issue seems to be caused by Chrome no longer sending Origin headers inside of extensions.

Has anyone else noticed this happening or is it just me?

Violation to Content Security Policy

I don't really know what the problem is and if it can be fixed, but I tried to add a js file for Facebook and it did an error in the console log before loading successfully the file (twice though, I don't know if it's normal, I just installed dotjs for the first time)

Console error:

Refused to connect to 'https://localhost:3131/facebook.com.js' because it violates the following Content Security Policy directive: "connect-src https://.facebook.com http://.facebook.com https://.fbcdn.net http://.fbcdn.net .facebook.net *.spotilocal.com: https://.akamaihd.net ws://.facebook.com:* http://*.akamaihd.net".

launch_msg(): Socket is not connected

I get the following output when attempting rake install:

rake install
(in /Users/max/Documents/Workspace/scratch/dotjs)
dotjs
-----
I will install:

1. The 'dotjs' Google Chrome Extension
2. djsd(1) in /usr/local/bin
3. com.github.dotjs in ~/Library/LaunchAgents

Ok? (y/n) y
Installing Google Chrome extension...
open -a 'Google Chrome' builds/dotjs.crx &
cp -p bin/djsd /usr/local/bin
cp com.github.dotjs.plist /Users/max/Library/LaunchAgents/com.github.dotjs.plist
chmod 644 /Users/max/Library/LaunchAgents/com.github.dotjs.plist
starting djdb...
launchctl load -w /Users/max/Library/LaunchAgents/com.github.dotjs.plist
Bug: launchctl.c:2325 (23930):13: (dbfd = open(g_job_overrides_db_path, O_RDONLY | O_EXLOCK | O_CREAT, S_IRUSR | S_IWUSR)) != -1
launch_msg(): Socket is not connected
dotjs installation failed
check console.app or open an issue

If I run ls -l /usr/local/bin/djsd I get the following output:
-rwxr-xr-x 1 max staff 918 Apr 29 11:52 /usr/local/bin/djsd

But running launchctl list | grep github gives no results.

Wildcard support

Right now I'd like it to work on domain and all of it's sub domains - examples:

foo.domain.com
bar.domain.com

It seems as if I need to have two seperate js files:

foo.domain.com.js
bar.domain.com.js

It would be cool if there were wildcard support where all subdomains were included by default by having a file: domain.com.js and then if you want target sub domains only you would have foo.domain.com.js

Though I suppose this could be achieved by looking for regex's in the url using javascript...

Don't include jQuery

So I've been using dotjs for a while now and I love the concept of it and how it works. Having said that, I'm on the fence about it auto including jQuery. I write a lot of my code without jQuery, and am more than ok with loading it myself if it is needed.

It seems like an unnecessary extra resource to load in some cases (which sometimes may cause a slight delay in my dotjs script in executing).

Also what happens if a website is already using jQuery... does that mean it's loading it twice - and if it is, is it being overwritten with the old version of jQuery (1.6.2 last I checked) that dotjs loads?

The latest chrome won't install dotjs from the command line

I just got a new mac with retina display, downloaded the latest chrome, and I was trying to install dotjs, but chrome gives me the message "Extensions, apps, and user scripts can only be added from the Chrome Web Store." When I click on "Learn more" it takes me to this site: http://support.google.com/chrome_webstore/bin/answer.py?hl=en&answer=2664769&p=crx_warning
apparently they did this for security reasons to prevent installations from other sites, but it doesn't say anything about installing from your own computer. Is this something we can work around? Or does the new chrome kill dotjs?

The ruby server constantly stays over 1% cpu usage

PID COMMAND %CPU TIME #TH #WQ #PORT #MREG RPRVT RSHRD RSIZE
64589 top 5.6 00:00.37 1/1 0 24 33 936K 264K 1516K
0- kernel_task 1.6 02:26:40 67/2 0 2 1006 17M 0B 257M
64583 ruby 1.3 00:00.26 2/1 0 20 60 4892K 244K 5936K
217 mongod 1.2 28:46.78 8 0 41 48 1468K 244K 3468K

Perhaps switching to another server would be better?

Chrome 21 doesn't allow extensions to be installed by hand

I tried to upgrade from dotjs 1.5 to 1.6 today, and to my dismay:

Extensions, apps, and user scripts can only be added from the Chrome Web Store" - http://cl.ly/image/3Z2v3g2K2W3x

My short-term solution was to unpack the extension:

git clone http://github.com/defunkt/dotjs
cd dotjs
rake install
# (prompt)
cd builds
cp dotjs.crx dotjs.zip
unzip dotjs.zip
# (load unpacked extension in chrome)

Support traditional user scripts with @include/@match

I found myself putting all of the behaviors needing to be applied globally into the one default.js. This caused the file to get quite messy; same goes for sites that I have multiple independent user scripts that I want to get applied. I would prefer to be able to stick traditional *.user.js files into my ~/.js directory and have their @include/@match metadata checked against the requested domain to determine whether they get concatenated in the response.

In addition to passing the domain to the local web server, perhaps the entire URL should then be passed so that user scripts can match more granularly at the path level, not just by domain.

Scripts are being loaded twice?

I have no idea why, but it appears each script for the associated site is being run twice for me.

[~] cat ~/.js/github.com.js 
console.debug("Loaded ~/.js/github.com.js");

// From README
$('#header .logo img')
  .css('width', '100px')
  .css('margin-top', '-15px')
  .attr('src', '//bit.ly/ghD24e')

[~] ps aux | grep djsd
tsigo      441   0.3  0.2  2506740  10040   ??  S     4:01AM   0:00.75 ruby /usr/local/bin/djsd
tsigo      515   0.0  0.0  2425712    280 s000  R+    4:07AM   0:00.00 grep djsd

And the extension is only installed once.

When I load a github.com page, I see the message twice in my console output. I'm using Chrome and the latest version of the code in your repository.

I had an idea that it was probably a bad interaction with some other extension, but I just disabled every extension except dotjs and the problem persists.

Uninstall/reinstall didn't work either.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.