// ==UserScript==
// @name          FIQL MIP Import Linker
// @namespace     http://www.musicip.com/
// @description   script to expose MIP links on FIQL.com
// @include       http://fiql.com/*
// @include       http://www.fiql.com/*
// ==/UserScript==

var menulink;
var fiqlid;

//try to find the FIQL 'toolbar'
var alinks = document.getElementsByTagName('a');

for (var i = 0; i < alinks.length; i++) {
	if (alinks[i].href.match(/plid=/)) {
		foo = /plid=([0-9]*)/;
		var result;
		if ((result = foo.exec(alinks[i].href)) != null) {
			fiqlid = result[1];
		}
	}
	if (alinks[i].href.match(/\/myfiql\/save.php.*/i)) {
		menulink = alinks[i];
	}
}

mipLink = document.createElement('a');
mipLink.href = "mip:import?fiql="+fiqlid;
mipLink.innerHTML = "MusicIP";
menulink.parentNode.appendChild(document.createTextNode(" | "));
menulink.parentNode.appendChild(mipLink);
