Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ubiquity commands
// -----------------------------------------------------------------
// Description page for these Ubiquity commands: http://www.endolith.com/ubiquity_commands.html
// -----------------------------------------------------------------
// I guess only one link rel="commands" works per page, so for now, at least, all commands are in one gist, separated into files based on subject.
// Some of these ain't workin since 0.5. Need to fix them.
// For http://www.jslint.com/ :
/*global CmdUtils, Utils, context, displayMessage, noun_arb_text, noun_type_url, _*/
// -----------------------------------------------------------------
// Google site: search
// -----------------------------------------------------------------
// Derivative of http://hondje.mine.nu/ubiquity/?get=google-site-search
// Another variant: http://gist.github.com/47637
// Example URL to try: http://www.labor.state.ny.us/workerprotection/publicwork/PWContents.shtm
// Can use accesskeys like Alt+3 to select an option.
// Should also allow "using domain.com" or "using 4"?
// Add translation things
if (CmdUtils.parserVersion == 2) {
CmdUtils.CreateCommand({
names: ["Google site search"],
description: "Search with Google within this site.",
help: "Searches within the current site for your search term. Pressing Enter searches inside the entire hostname, or you can click in the list of other variants to search within a certain subdomain/subdirectory.",
icon: "http://www.google.com/favicon.ico",
version: "1.3",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
license: "MPL",
contributors: ["Tim van Heugten"],
arguments: [{role: "object",
nountype: noun_arb_text,
label: "search terms"}],
preview: function( pblock, args ) {
var doc = CmdUtils.getDocument();
var host = doc.location.host;
var hostbits = host.split('.');
var pathbits = doc.location.pathname.split('/');
var searchTerm = escape(args.object.text);
// I am not a real JavaScript programmer.
// This is a super-kludge!
var template = 'Search Google for <strong>' + args.object.summary + '</strong> only within this site:<ol>';
// Create the list of subdomains
var site = hostbits[hostbits.length - 1];
var x = 1;
for (var i = hostbits.length - 2; i >= 1; i--) {
site = hostbits[i] + '.' + site;
template = template + '<li value = ' + x + '><a accesskey="' + x + '" href="http://www.google.com/search?q=site:' + site + '%20' + searchTerm + '">' + site + '</a></li>';
x++;
}
// Add the full host to the list, bolded since it's the default
template = template + '<li value = ' + x + '><strong><a accesskey="' + x + '" href="http://www.google.com/search?q=site:' + host + '%20' + searchTerm + '">' + host + '</a></strong></li>';
x++;
// Create the list of subdirectories
site = host + '/';
for (var i = 1; i <= pathbits.length - 2; i++) {
site += pathbits[i] + '/';
template = template + '<li value = ' + x + '><a accesskey="' + x + '" href="http://www.google.com/search?q=site:' + site + '%20' + searchTerm + '">' + site + '</a></li>';
x++;
}
template = template + "</ol><small>Tip: You can go to one of these searches directly by using its number as an access key. (Linux and Windows: Alt-number, Mac: Control-number)</small>";
pblock.innerHTML = template;
},
execute: function(args) {
var doc = CmdUtils.getDocument();
var siteHost = doc.location.host;
var query = "site:" + siteHost + " " + args.object.text;
var urlString = "http://www.google.com/search?q=" + query;
Utils.openUrlInBrowser(urlString);
CmdUtils.setLastResult( urlString );
}
});
} else {
CmdUtils.CreateCommand({
name: "google-site-search",
description: "Search with Google within this site.",
help: "Searches within the current site for your search term. Pressing Enter searches inside the entire hostname, or you can click in the list of other variants to search within a certain subdomain/subdirectory.",
icon: "http://www.google.com/favicon.ico",
version: "1.3",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { name: "Endolith", email: "endolith@gmail.com" },
license: "MPL",
contributors: ["Tim van Heugten"],
takes: {"search term": noun_arb_text},
preview: function( pblock, directObject ) {
var doc = CmdUtils.getDocument();
var host = doc.location.host;
var hostbits = host.split('.');
var pathbits = doc.location.pathname.split('/');
var searchTerm = escape(directObject.text);
// I am not a real JavaScript programmer.
// This is a super-kludge!
var template = 'Search Google for <strong>' + directObject.summary + '</strong> only within this site:<ol>';
// Create the list of subdomains
var site = hostbits[hostbits.length - 1];
var x = 1;
for (var i = hostbits.length - 2; i >= 1; i--) {
site = hostbits[i] + '.' + site;
template = template + '<li value = ' + x + '><a accesskey="' + x + '" href="http://www.google.com/search?q=site:' + site + '%20' + searchTerm + '">' + site + '</a></li>';
x++;
}
// Add the full host to the list, bolded since it's the default
template = template + '<li value = ' + x + '><strong><a accesskey="' + x + '" href="http://www.google.com/search?q=site:' + host + '%20' + searchTerm + '">' + host + '</a></strong></li>';
x++;
// Create the list of subdirectories
site = host + '/';
for (var i = 1; i <= pathbits.length - 2; i++) {
site += pathbits[i] + '/';
template = template + '<li value = ' + x + '><a accesskey="' + x + '" href="http://www.google.com/search?q=site:' + site + '%20' + searchTerm + '">' + site + '</a></li>';
x++;
}
template = template + "</ol><small>Tip: You can go to one of these searches directly by using its number as an access key. (Linux and Windows: Alt-number, Mac: Control-number)</small>";
pblock.innerHTML = template;
},
execute: function(directObject, modifiers) {
var doc = CmdUtils.getDocument();
var siteHost = doc.location.host;
var query = "site:"+siteHost+" "+directObject.text;
var urlString = "http://www.google.com/search?q="+query;
Utils.openUrlInBrowser(urlString);
CmdUtils.setLastResult( urlString );
}
});
}
// -----------------------------------------------------------------
// Miscellaneous commands
// -----------------------------------------------------------------
CmdUtils.CreateCommand({
names: ["zap stylesheets"],
description: "Remove CSS styles from the current page. Adapted from the squarefree.com bookmarklet",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
preview: "Remove CSS styles from the current page.",
icon: "http://www.famfamfam.com/lab/icons/silk/icons/page_white_lightning.png",
execute: function() {
var doc = CmdUtils.getDocument();
var i, x;
for (var i = 0; x = doc.styleSheets[i]; ++i) {
x.disabled = true;
}
}
});
CmdUtils.makeBookmarkletCommand({
name: "note in Google Reader",
description: "Converted from a bookmarklet from Google Reader",
icon: "http://www.google.com/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
url: "javascript:var%20b=document.body;var%20GR________bookmarklet_domain='https://www.google.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='https://www.google.com/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}"
});
// -----------------------------------------------------------------
// Resurrect dead page commands
// -----------------------------------------------------------------
// Should all be combined into one "resurrect" command
// "resurrect ______ using Google's text-only cache"
// "retrieve cache of ______ using Google (text-only)"
// Default to ____,
// If a plain text URL is highlighted, it should resurrect that URL
// If HTML with a link inside it is highlighted, it should resurrect that link
// What about image URLs, etc?
// If current page is a 404 or other error, try to figure out what it was supposed to be
// Existing page --> Link to dead page --> redirect to 404
// In this case we should resurrect the dead page
// Referrer doesn't work
// Otherwise it will resurrect the current page
// Should check if cached version exists first and only show engines that have a result, maybe showing a preview of each
if (CmdUtils.parserVersion == 2) {
function get_target(input) {
var doc = CmdUtils.getDocument();
if (input.object.text) { // Typed-in target or selected URL
this.name = input.object.summary;
var a = doc.createElement('a'); // http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
a.href = input.object.text;
this.location = a;
}
else if (0) { // Link contained in selected HTML
/*
targetLocation = link text;
url = link ;
*/
}
else if (0) { // Current page is a 404
/*
location = referring page title
url = referring page URL
*/
}
else { // Current page
if (doc.title) {
this.name = doc.title + " (" + doc.location.hostname + ")"; // Won't be accurate if 404ed, though
}
else {
this.name = "this page";
}
this.location = doc.location;
}
}
CmdUtils.CreateCommand({
names: ["Wayback Machine latest"],
description: "View the most recently archived version of a page using the Internet Archive's Wayback Machine.",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://web.archive.org/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
license: "GPL",
arguments: {object: noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = _("Opens the most recent archived version of <b>" + target.name + "</b> using the Internet Archive's Wayback Machine");
},
execute: function(input) {
var target = new get_target(input);
Utils.openUrlInBrowser("http://web.archive.org/" + escape(target.location.href));
}
});
CmdUtils.CreateCommand({
names: ["Wayback Machine list"],
description: "View the list of archived versions of a page on the Internet Archive's Wayback Machine.",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://web.archive.org/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
license: "GPL",
arguments: {object: noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = _("Opens the Wayback Machine's list of archived versions of <b>" + target.name + "</b>");
},
execute: function(input) {
var target = new get_target(input);
Utils.openUrlInBrowser("http://web.archive.org/web/*/" + escape(target.location.href));
}
});
CmdUtils.CreateCommand({
names: ["Google cache"], /* Should be a verb? */
description: "View Google's cached version of a URL or the current page",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://www.google.com/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
license: "GPL",
arguments: {object: noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = _("Opens Google's cached version of <b>" + target.name + "</b>");
},
execute: function(input) {
var target = new get_target(input);
Utils.openUrlInBrowser("http://www.google.com/search?q=cache:" + escape(target.location.href));
}
});
CmdUtils.CreateCommand({
names: ["Google cache text-only"],
description: "View Google's text-only cached version of a page",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://www.google.com/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
license: "GPL",
arguments: {object: noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = _("Opens Google's text-only cached version of <b>" + target.name + "</b>");
},
execute: function(input) {
var target = new get_target(input);
Utils.openUrlInBrowser("http://www.google.com/search?strip=1&q=cache:" + escape(target.location.href));
}
});
CmdUtils.CreateCommand({
names: ["Webcite cache"],
description: "View WebCite's archived version of a page.",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://www.webcitation.org/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
license: "GPL",
arguments: {object: noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = _("Opens WebCite's cached version of <b>" + target.name + "</b>");
},
execute: function(input) {
var target = new get_target(input);
Utils.openUrlInBrowser("http://webcitation.org/query.php?url=" + escape(target.location.href));
}
});
CmdUtils.CreateCommand({
names: ["Coral cache"],
description: "View CoralCDN's cached version of the current page.",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://www.coralcdn.org/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
arguments: {object: noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = _("Opens the CoralCDN cached version of <b>" + target.name + "</b>");
},
execute: function(input) {
var target = new get_target(input);
var loc = target.location;
if (loc.protocol == "http:"){
var coralizedhost = loc.host.replace(':','.') + '.nyud.net';
Utils.openUrlInBrowser(loc.href.replace(loc.host, coralizedhost));
}
else {
displayMessage(loc.protocol + _(" URLs cannot be Coralized"));
}
}
});
} else {
function get_target(input) {
var doc = CmdUtils.getDocument();
if (input.text) { // Typed-in target or selected URL
this.name = input.summary;
var a = doc.createElement('a'); // http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
a.href = input.text;
this.location = a;
}
else { // Current page
if (doc.title) {
this.name = doc.title + " (" + doc.location.hostname + ")"; // Won't be accurate if 404ed, though
}
else {
this.name = "this page";
}
this.location = doc.location;
}
}
CmdUtils.CreateCommand({
name: "wayback-machine-latest",
description: "View the most recently archived version of a page using the Internet Archive's Wayback Machine.",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://web.archive.org/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { name: "Endolith", email: "endolith@gmail.com" },
license: "GPL",
takes: {"URL": noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = "Opens the most recent archived version of <b>" + target.name + "</b> using the Internet Archive's Wayback Machine";
},
execute: function(input) {
var target = new get_target(input);
Utils.openUrlInBrowser("http://web.archive.org/" + escape(target.location.href));
}
});
CmdUtils.CreateCommand({
name: "wayback-machine-list",
description: "View the list of archived versions of a page on the Internet Archive's Wayback Machine.",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://web.archive.org/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { name: "Endolith", email: "endolith@gmail.com" },
license: "GPL",
takes: {"URL": noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = "Opens the Wayback Machine's list of archived versions of <b>" + target.name + "</b>";
},
execute: function(input) {
var target = new get_target(input);
Utils.openUrlInBrowser("http://web.archive.org/web/*/" + escape(target.location.href));
}
});
CmdUtils.CreateCommand({
name: "google-cache",
description: "View Google's cached version of a URL or the current page",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://www.google.com/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { name: "Endolith", email: "endolith@gmail.com" },
license: "GPL",
takes: {"URL": noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = "Opens Google's cached version of <b>" + target.name + "</b>";
},
execute: function(input) {
var target = new get_target(input);
Utils.openUrlInBrowser("http://www.google.com/search?q=cache:" + escape(target.location.href));
}
});
CmdUtils.CreateCommand({
name: "google-cache-text-only",
description: "View Google's text-only cached version of a page",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://www.google.com/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { name: "Endolith", email: "endolith@gmail.com" },
license: "GPL",
takes: {"URL": noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = "Opens Google's text-only cached version of <b>" + target.name + "</b>";
},
execute: function(input) {
var target = new get_target(input);
Utils.openUrlInBrowser("http://www.google.com/search?strip=1&q=cache:" + escape(target.location.href));
}
});
CmdUtils.CreateCommand({
name: "webcite-cache",
description: "View WebCite's archived version of a page.",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://www.webcitation.org/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { name: "Endolith", email: "endolith@gmail.com" },
license: "GPL",
takes: {"URL": noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = "Opens WebCite's cached version of <b>" + target.name + "</b>";
},
execute: function(input) {
var target = new get_target(input);
Utils.openUrlInBrowser("http://webcitation.org/query.php?url=" + escape(target.location.href));
}
});
CmdUtils.CreateCommand({
name: "coral-cache",
description: "View CoralCDN's cached version of the current page.",
help: "If no URL is entered in Ubiquity, it will default to the currently-viewed page.",
icon: "http://www.coralcdn.org/favicon.ico",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { name: "Endolith", email: "endolith@gmail.com" },
takes: {"URL": noun_type_url},
preview: function(pblock, input) {
var target = new get_target(input);
pblock.innerHTML = "Opens the CoralCDN cached version of <b>" + target.name + "</b>";
},
execute: function(input) {
var target = new get_target(input);
var loc = target.location;
if (loc.protocol == "http:"){
var coralizedhost = loc.host.replace(':','.') + '.nyud.net';
Utils.openUrlInBrowser(loc.href.replace(loc.host, coralizedhost));
}
else {
displayMessage(loc.protocol + " URLs cannot be Coralized");
}
}
});
}
// -----------------------------------------------------------------
// Text formatting commands
// -----------------------------------------------------------------
// These all use execcommand instead of adding HTML tags manually, so they only work on rich text editing areas
CmdUtils.CreateCommand({
names: ["strikethrough", "strike through"],
description: "If you're in a rich-text-edit area, strikes through the selected text, like <s>this</s>.",
help: "Select some text and apply the command to <s>strike through the text</s>, or to toggle it back to normal.",
icon: "http://www.famfamfam.com/lab/icons/silk/icons/text_strikethrough.png",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
license: "GPL",
preview: function(pblock, input) {
pblock.innerHTML = cmd_strikethrough.description;
},
execute: function(input) {
var doc = context.focusedWindow.document; // change to CmdUtils.getDocument() ?
if (doc.designMode == "on") {
doc.execCommand("strikethrough", false, null);
}
else {
displayMessage(_("You're not in a rich text editing field."), this);
}
}
});
CmdUtils.CreateCommand({
names: ["monospace"],
description: "If you're in a rich-text-edit area, changes your current selection to a monospace font, like <tt>this</tt>.",
help: "Select some text and apply the command to <tt>make it monospace</tt>.",
icon: "http://www.famfamfam.com/lab/icons/silk/icons/text_letterspacing.png",
homepage: "http://www.endolith.com/ubiquity_commands.html",
author: { email: "endolith@gmail.com" },
license: "GPL",
preview: function(pblock, input) {
pblock.innerHTML = cmd_monospace.description;
},
execute: function(input) {
var doc = context.focusedWindow.document; // change to CmdUtils.getDocument() ?
if (doc.designMode == "on") {
doc.execCommand("fontname", false, "monospace");
}
else {
displayMessage(_("You're not in a rich text editing field."), this);
}
}
});
function cmd_highlight() {
var doc = context.focusedWindow.document;
if (doc.designMode == "on") {
doc.execCommand("hilitecolor",false,"yellow");
}
else {
displayMessage(_("You're not in a rich text editing field."), this);
}
}
cmd_highlight.preview = function(pblock) {
pblock.innerHTML = cmd_monospace.description;
};
cmd_highlight.description = "If you're in a rich-text-edit area, highlights your current selection, like <span style='background: yellow; color: black;'>this</span>.";
cmd_highlight.homepage = "http://www.endolith.com/ubiquity_commands.html";
cmd_highlight.icon = "chrome://ubiquity/skin/icons/textfield_rename.png";
// -----------------------------------------------------------------
// UWO library proxy
// -----------------------------------------------------------------
if (CmdUtils.parserVersion == 2) {
//parser 2 command here
CmdUtils.CreateCommand({
names: ["UWO", "University of Western Ontario"],
description: "Access this scientific paper through the University of Western Ontario library",
preview: "Access this scientific paper through the University of Western Ontario library",
icon: "http://www.uwo.ca/local_files/favicon.ico",
execute: function() {
var doc = CmdUtils.getDocument();
var loc = doc.location;
var newhost = loc.host.replace(':','.') + '.proxy2.lib.uwo.ca:2048';
loc.href = loc.href.replace(loc.host, newhost);
}
});
}
else {
//parser 1 command here
CmdUtils.CreateCommand({
name: "uwo",
description: "Access this scientific paper through the University of Western Ontario library",
preview: "Access this scientific paper through the University of Western Ontario library",
icon: "http://www.uwo.ca/local_files/favicon.ico",
execute: function() {
var doc = CmdUtils.getDocument();
var loc = doc.location;
var newhost = loc.host.replace(':','.') + '.proxy2.lib.uwo.ca:2048';
loc.href = loc.href.replace(loc.host, newhost);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.