Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created August 11, 2009 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netsi1964/166127 to your computer and use it in GitHub Desktop.
Save netsi1964/166127 to your computer and use it in GitHub Desktop.
/* This is a template command. */
CmdUtils.CreateCommand({
names: ["links-on-page"],
icon: "http://www.netsi.dk/favicon.ico",
description: "Shows the no of links on current page",
help: "When you visit a page simple fire up <b>links-on-page</b> to see a count of links on current page.",
author: {name: "Sten Hougaard", email: "netsi1964@gmail.com"},
license: "GPL",
homepage: "http://www.netsi.dk/ubiquity",
preview: function preview(pblock, args) {
try {
pblock.innerHTML = getInformation();
} catch(e) {
pblock.innerHTML = e.message;
}
},
execute: function execute(args) {
//displayMessage(getInformation(), this);
}
});
var document = Application.activeWindow.activeTab.document;
var aLinks;
function getInformation() {
var sResult = "";
try {
var aLinks = document.getElementsByTagName('a');
sResult = "This page has " + aLinks.length.toString() + " links.<br />";
sResult+='<ol>';
for(var i=0; i<aLinks.length; i++) {
sResult+='<li>'+aLinks[i].innerHTML+'</li>';
}
sResult+='</ol>';
} catch(e) {
sResult = "Error in getInformation()"+e.message;
}
return sResult;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment