-
-
Save gialloporpora/38205 to your computer and use it in GitHub Desktop.
Ubiquity Digg Command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* I prefere to define the Digg Topic in a variable to avoid to slow command calling the Digg API | |
* to make this I use a little bookmarklet to make easy this operation. Go to this page to find the complete Digg containers | |
* http://services.digg.com/containers?appkey=http%3A%2F%2Fapidoc.digg.com */ | |
var digg_dict={ "Apple" : "apple", "Design" : "design", "Gadgets" : "gadgets", "Hardware" : "hardware", "Tech Industry News" : "tech_news", "Linux/Unix" : "linux_unix", "Microsoft" : "microsoft", "Mods" : "mods", "Programming" : "programming", "Security" : "security", "Software" : "software", "Business & Finance" : "business_finance", "World News" : "world_news", "Political News" : "politics", "Political Opinion" : "political_opinion", "US Elections 2008" : "2008_us_elections", "Environment" : "environment", "General Sciences" : "general_sciences", "Space" : "space", "Gaming Industry News" : "gaming_news", "PC Games" : "pc_games", "Playable Web Games" : "playable_web_games", "Nintendo" : "nintendo", "PlayStation" : "playstation", "Xbox" : "xbox", "Arts & Culture" : "arts_culture", "Autos" : "autos", "Educational" : "educational", "Food & Drink" : "food_drink", "Health" : "health", "Travel & Places" : "travel_places", "Celebrity" : "celebrity", "Movies" : "movies", "Music" : "music", "Television" : "television", "Comics & Animation" : "comics_animation", "Baseball" : "baseball", "Basketball" : "basketball", "Extreme" : "extreme_sports", "American & Canadian Football" : "football", "Golf" : "golf", "Hockey" : "hockey", "Motorsport" : "motorsport", "Olympics" : "olympics", "Soccer" : "soccer", "Tennis" : "tennis", "Other Sports" : "other_sports", "Comedy" : "comedy", "Odd Stuff" : "odd_stuff", "People" : "people", "Pets & Animals" : "pets_animals"}; | |
var digg_array=[]; | |
for (i in digg_dict) digg_array.push(i); | |
var noun_type_diggmedia= new CmdUtils.NounType( "diggmedia", | |
["video","image"] | |
); | |
var noun_type_diggcategories = new CmdUtils.NounType( "diggtopic", | |
digg_array | |
); | |
/* messages displayed by this command */ | |
var digg_command_msg={ | |
"default" : "Submit or digg this page. Checking if this page has already been submitted...", | |
"already_digged_story" : "Digg this page. This page already has <b>${diggs_number}</b> diggs.", | |
"submit_page" : "Submit this page to Digg", | |
"submit_description" : " with the description:<br/> <i style='padding:10px;color: #CCC;display:block;'>${selected_text}</i>", | |
"submit_truncated_description" :"<br/> Description can only be 375 characters. The last <b>${truncated}</b> characters will be truncated." | |
}; | |
CmdUtils.CreateCommand({ | |
name: "dugg", | |
synonyms: ["dugg-this-story"], | |
icon: "http://digg.com/favicon.ico", | |
homepage: "http://www.gialloporpora.netsons.org", | |
description: "If not yet submitted, submits the page to Digg. Otherwise, it takes you to the story's Digg page.", | |
author: { name: "Sandro Della Giustina", email: "[email protected]"}, | |
license: "MPL,GPL", | |
takes: {input: noun_arb_text}, | |
modifiers: {in: noun_type_diggcategories, media: noun_type_diggmedia}, | |
preview: function(pblock, input) { | |
var doc = CmdUtils.getDocument(); | |
var selected_text=input.text; | |
var api_url="http://services.digg.com/stories" | |
var link=doc.location.href; | |
var params = Utils.paramsToString({ | |
appkey: "http://www.gialloporpora.netsons.org", | |
link: link | |
}); | |
pblock.innerHTML = digg_command_msg["default"]; | |
CmdUtils.previewAjax(pblock, { | |
type: "GET", | |
url: api_url+params, | |
error: function(){ | |
//pblock.innerHTML= 'Digg API seems to be unavailable or the URI is incorrect.<br/>'; | |
}, | |
success: function(xml){ | |
var el = jQuery(xml).find("story"); | |
var diggs = el.attr("diggs"); | |
if (diggs == null){ | |
html =digg_command_msg["submit_page"]; | |
if (selected_text.length > 0) { | |
html +=CmdUtils.renderTemplate(digg_command_msg["submit_description"],{"selected_text" : selected_text.substring(0,375)}); | |
if (selected_text.length > 375){ | |
html +=CmdUtils.renderTemplate(digg_command_msg["submit_truncated_description"], {"truncated" : (selected_text.length - 375)}); | |
} | |
} | |
} | |
else { | |
html=CmdUtils.renderTemplate(digg_command_msg["already_digged_story"], {"diggs_number": diggs}); | |
} | |
pblock.innerHTML=html; | |
} | |
}); | |
}, | |
execute: function( input , modifiers) { | |
var doc = CmdUtils.getDocument(); | |
var sel = input.text.substring(0,375); | |
var link= doc.location.href; | |
var digg_tp=digg_dict[modifiers.in.text] || ""; | |
var digg_md=modifiers.media.text || "news"; | |
var params = Utils.paramsToString({ | |
phase: "2", | |
url: link, | |
title: doc.title, | |
bodytext: sel, | |
topic: digg_tp, | |
media: digg_md | |
}); | |
story_url='http://digg.com/submit' + params; | |
Utils.openUrlInBrowser(story_url); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment