Skip to content

Instantly share code, notes, and snippets.

@zeke
Created November 18, 2008 00:08
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 zeke/25983 to your computer and use it in GitHub Desktop.
Save zeke/25983 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name delicious.com legacy bookmarklet fix
// @namespace Decafbad
// @include http://delicious.com/save*
// ==/UserScript==
(function() {
function $(id) {
return document.getElementById(id);
};
return {
init: function() {
var qparams = this.parseQueryString();
var param_field_map = {
'url': 'url',
'description': 'title',
'extended': 'notes',
'tags': 'tags',
'jump': 'jump'
};
for (k in param_field_map) {
if (!param_field_map.hasOwnProperty(k))
continue;
var field = $(param_field_map[k]);
if (qparams[k] && field) {
field.value = qparams[k].pop();
}
}
},
/**
* see: http://www.safalra.com/web-design/javascript/parsing-query-strings/parseQueryString.js
*/
parseQueryString: function(queryString){
// define an object to contain the parsed query data
var result = {};
// if a query string wasn't specified, use the query string from the URI
if (queryString == undefined){
queryString = location.search ? location.search : '';
}
// remove the leading question mark from the query string if it is present
if (queryString.charAt(0) == '?') queryString = queryString.substring(1);
// replace plus signs in the query string with spaces
queryString = queryString.split('+').join(' ');
// split the query string around ampersands and semicolons
var queryComponents = queryString.split(/[&;]/g);
// loop over the query string components
for (var i = 0; i < queryComponents.length; i++){
// extract this component's key-value pair
var keyValuePair = queryComponents[i].split('=');
var key = decodeURIComponent(keyValuePair[0]);
var value = decodeURIComponent(keyValuePair[1]);
// update the parsed query data with this component's key-value pair
if (!result[key]) result[key] = [];
result[key].push((keyValuePair.length == 1) ? '' : value);
}
// return the parsed query data
return result;
},
EOF:null
};
}()).init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment