/* bugmenot.js Queries bugmenot.com for the current page, populates login information and submits. Written by Victor Shih (vshih at yahoo.com, http://blog.vicshih.com/2009/04/bugmenot-command-for-ubiquity.html) Initial idea and some code from Onur Yalazı (onur@yalazi.org, http://www.yalazi.org/ubiquity) and Brandon Goldsworthy. */ const MIN_RATE_PERCENT = 50; // only show entries that rate 50% or more CmdUtils.CreateCommand({ names: ['bugmenot'], icon: 'http://www.bugmenot.com/favicon.gif', homepage: 'http://blog.vicshih.com/2009/04/bugmenot-command-for-ubiquity.html', author: {name: 'Victor Shih', email: 'vshih at yahoo.com'}, license: 'MPL', description: 'Queries bugmenot.com for the current page, populates login information and submits.', help: 'Enter the desired index of the bugmenot.com entry; defaults to top entry.', arguments: [ {role: 'object', nountype: /\d*/, label: 'entry number'} ], preview: function(pblock, args) { var url = this._getUrl(); pblock.innerHTML = 'Passwords for ' + url + ':
'; this._showEntries(pblock, url, args.object.text); }, execute: function(args) { var url = this._getUrl(); var entryID = parseInt(args.object.text) - 1; if (isNaN(entryID)) entryID = 0; var proxy = this; this._getEntries(url, function(entries) { if (entries.length == 0) { displayMessage(_('Bugmenot.com - no entries found.')); return; } if (entryID >= entries.length) entryID = entries.length - 1; proxy._submit(entries[entryID]); }); }, // Private members _entries: {}, _decode: function(data, key) { var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; var o11 = '', o21 = '', o31 = ''; var h11 = '', h21 = '', h31 = '', h41 = ''; var bits1 = '', i1 = 0, enc1 = ''; do { h11 = b64.indexOf(data.charAt(i1++)); h21 = b64.indexOf(data.charAt(i1++)); h31 = b64.indexOf(data.charAt(i1++)); h41 = b64.indexOf(data.charAt(i1++)); bits1 = h11 << 18 | h21 << 12 | h31 << 6 | h41; o11 = bits1 >> 16 & 255; o21 = bits1 >> 8 & 255; o31 = bits1 & 255; if (h31 == 64) { enc1 += String.fromCharCode(o11); } else if (h41 == 64) { enc1 += String.fromCharCode(o11, o21); } else { enc1 += String.fromCharCode(o11, o21, o31); } } while (i1 < data.length); var strInput = enc1; var strOutput = ''; var intOffset = (key + 112) / 12; for (i1 = 4; i1 < strInput.length; ++i1) { var thisLetter = strInput.charAt(i1); var thisCharCode = strInput.charCodeAt(i1); var newCharCode = thisCharCode - intOffset; strOutput += String.fromCharCode(newCharCode); } return strOutput; }, _getUrl: function() { var url = Application.activeWindow.activeTab.document.location.toString(); var i = url.indexOf('://'); if (i != -1) url = url.substr(i + 3); var i = url.indexOf('/'); if (i != -1) url = url.substr(0, i); return url; }, _getEntries: function(url, callback) { if (this._entries[url]) { callback.call(this, this._entries[url]); } else { var proxy = this; jQuery.ajax({ url: 'http://www.bugmenot.com/view/' + url, success: function(html) { var key = parseInt(html.match(/key.=.(-?[0-9]*)/)[1]); var ps = html.split('
' + index + (index.length == 1 ? ' ' : '') + ' ' + entry.username + ' ' + entry.password + ' ' + entry.rate + '%
'; }, _submit: function(entry) { var ins = jQuery(CmdUtils.getDocument()).find(':text,:password'); var pass = ins.filter(':password:eq(0)'); ins.slice(0, ins.index(pass)).filter(':text:last').val(entry.username); pass.val(entry.password)[0].form.submit(); } });