Cathode Tan - Games, Media and Geek Stuff
logo design by man bytes blog

Thursday, July 06, 2006


PeaceNik is a javascript bookmarklet I just got working. It's essentially greasemonkey without greasemonkey. It makes peace, I guess you could say, between a site and your remote javascript code. I'm not sure how many Cathode tan readers would have an interest in this kind of thing. I plan on using it to make some handy blogging functions, though, so I might have more useful stuff down the way.

You need FireFox or Safari, doesn't seem to work in IE right now. To test it, simply create a new bookmark. Make the name of the bookmark "PeaceNik" or something similar and make the following the location:

Make sure it's all one line.

Then just travel to some site and click the bookmark. You should see "BG GREEN" in the upper corner. Clicking on that will change the bg color of the body tag of that current site to green.

Granted, that's not too thrilling. Green is a nice color and all, but not that great. The gist here though is that you can run pretty much whatever javascript you want. Here is the bgtest.js sample:

var pbtn = document.createElement("div");
var pbtntxt = document.createTextNode("PeaceNik");
var bmenu = false;

function actions() {

with( {
position = "absolute";
top = "0px";
left = "0px";
color = "black";
background = "white";
border = "1px solid";
padding = "3px";
font = "10px sans-serif";
cursor = "pointer";
MozOpacity = ".4";

AddNewMenuItem("BG Green",MakeBGGreen);

function AddNewMenuItem(title,afunction) {
newdiv = document.createElement("div");
newdiv.innerHTML = title;
with( {
color = "white";
background = "black";
border = "1px solid #009";
padding = "3px";
font = "10px sans-serif";
cursor = "pointer";
newdiv.onmousedown = afunction;

function MakeBGGreen() {
document.getElementsByTagName("body")[0].style.background = "green";

The actions function is what PeaceNik eventually triggers, so you can toss your custom javascript in there. You'll need access to your own web server, of couse, and you'll have to update the "nikloc" var in the bookmarklet to point to your script. With that, though, you could write your own custom library for dealing with sites, similar to how FireFox extensions work. Except these could be extremely site specific as to reference elements just for that page. For example, you could build a textarea which would report all the headlines on Cathode Tan by running through H elements and pushing them into another div.

Bloggery wise, I could use some functions which make a handy quote section for me based on highlighted text on a page and perhaps send that to the Blogger post page in a new window.

edit: just noticed that humorously, the sample doesn't work so well on if it has that tool div at the top...

No comments: