#!/usr/bin/env perl use strict; use warnings; my $fullpathname; my $filename; my $prefix; my $script_content = ''; if ( $ENV{SERVER_NAME} ) { use CGI; print "Content-Type: text/plain\n\n"; my $q = new CGI; my $fh = $q->upload('jsa'); while (<$fh>) { $script_content .= $_; } $filename = $q->param('jsa'); $prefix = $filename; $prefix =~ s/(\.uc)?\.js$//; $prefix = quotemeta $prefix; } else { $fullpathname = shift @ARGV; -e $fullpathname or die "file $fullpathname does not exist."; my @path = split m|/|, $fullpathname; $filename = pop @path; $prefix = $filename; $prefix =~ s/(\.uc)?\.js$//; $prefix = quotemeta $prefix; open F, "<$fullpathname" or die "$!:$fullpathname"; } print <<"__JS__"; // ==UserScript== // \@name converted JSActions script $filename // \@version 0.0.1 // \@description this script is converted from $filename with jsa2uc // \@namespace http://ido.nu/kuma/ // \@homepage http://ido.nu/kuma/ // \@compatibility Firefox 2.0 3.0 // \@include chrome://browser/content/browser.xul // \@Note // ==/UserScript== /* This uc.js script is converted from JSActions script $filename with jsa2uc http://ido.nu/kuma/ . */ var menu = document.createElement("menuitem"); menu.setAttribute("label", "$prefix"); // setup jsactions global variables. menu.addEventListener("command", function () { let ( document = gContextMenu.target.ownerDocument, window = gContextMenu.target.ownerDocument.defaultView ) (function () { $script_content; } )(); } , false); var contextMenu = document.getElementById('contentAreaContextMenu'); var separator = document.getElementById('context-bookmarklink'); contextMenu.insertBefore(menu, separator); if ( 1 ) { contextMenu.insertBefore( document.createElement("menuseparator"), separator ); } /* if ( top.Firebug && top.Firebug.Console && top.Firebug.Console.log ) { console = { log: function () { top.Firebug.Console.log(arguments); } } } else if ( Application && Application.Console ) { console = { log: function () { Application.Console.log.apply(this, arguments); } } } else { console = { log: function () {} } } */ __JS__