// ==UserScript== // @name SBSP Inventory Shortcuts // @namespace http://websterrf.com/SP // @description Adds shortcuts section to Inventory // @include http://*spybattle.*/inventory.php* // @include http://*spybattle.*/equip.php* // @include http://*spybattle.*/sellitem.php* // @include http://*starpirates.*/inventory.php* // @include http://*starpirates.*/equip.php* // @include http://*spybattle.*/putonmarket.php?id=*&put=true // @author not V (version 0.5), previous versions: Blaine Moore (Keyser Soze / WebsterRF / Matthew Murdock / Tobias Gregson / Faron Yoder) // @homepage http://www.runtowin.com/ // @version 0.5.3 // ==/UserScript== /*******************************************************************************************************/ // User Script Options: ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // These are the colors of the shortcut links var AddLinkColor = "lime"; // This is the color to add a shortcut. var RemoveLinkColor = "red"; // This is the color to remove a shortcut. // These are the widths of the shortcut columns and must add up to 100% var UseWidth = "35%"; // This is the width of the "Send" shortcuts column var SendWidth = "25%"; // This is the width of the "Send" shortcuts column var EquipWidth = "40%"; // This is the width of the "Send" shortcuts column // This is the position of the shortcut links. // Valid Values: 0 - Top of the page // 1 - Above "Equipped" (Below "Inventory") // 2 - Above "Items in Storage" (Below "Equipped") var LinkPosition = "1"; // This is the order of the Use/Equip/Send links // Valid Values: "e" "s" and "u" in any order, e.g. "seu" or "ues" etc. // All 3 letters must appear once. var ShortcutOrder = "esu"; ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //TODO: find a more reliable reusable fallback; current one gets confused when multiple scripts are working on the same page. Maybe create USERSCRIPT_NAME_set_Value() (and friends) and inject it in the page. var prefix = getGameName(); const USERSCRIPT_NAME = "INVENTORY SHORTCUTS"; //delete GM_log; delete GM_getValue; delete GM_setValue; delete GM_deleteValue; var gvar=function() {} // Global variables //GM_ApiBrowserCheck(); //delete GM_log; delete GM_getValue; delete GM_setValue; delete GM_deleteValue; //var gvar=function() {} // Global variables //function GM_ApiBrowserCheck() { const GMSTORAGE_PATH = 'SPSBGM_'+USERSCRIPT_NAME; // You can change it to avoid conflict with others scripts if(typeof(unsafeWindow)=='undefined') { unsafeWindow=window; } if(typeof(GM_log)=='undefined') { GM_log=function(msg) { try { unsafeWindow.console.log('GM_log: '+msg); } catch(e) {} }; } // if(typeof(GM_log)=='undefined') GM_clog=function(msg) { if(arguments.callee.counter) { arguments.callee.counter++; } else { arguments.callee.counter=1; } // if(arguments.callee.counter) GM_log('('+arguments.callee.counter+') '+msg); } // GM_clog=function(msg) GM_addGlobalStyle=function(css) { // Redefine GM_addGlobalStyle with a better routine var sel=document.createElement('style'); sel.setAttribute('type','text/css'); sel.appendChild(document.createTextNode(css)); var hel=document.documentElement.firstChild; while(hel && hel.nodeName!='BODY') { hel=hel.nextSibling; } if(hel && hel.nodeName=='BODY') { hel.appendChild(sel); } else { document.body.insertBefore(sel,document.body.firstChild); } // if(hel && hel.nodeName=='BODY') return sel; } // GM_addGlobalStyle=function(css) var needApiUpgrade=false; if(window.navigator.appName.match(/^opera/i) && typeof(window.opera)!='undefined') { needApiUpgrade=true; gvar.isOpera=true; GM_log=window.opera.postError; //GM_log('Opera detected...'); } // if(window.navigator.appName.match(/^opera/i) && typeof(window.opera)!='undefined') if(typeof(GM_setValue)!='undefined') { var gsv; try { gsv=GM_setValue.toString(); } catch(e) { gsv='staticArgs'; } if(gsv.indexOf('staticArgs')>0) { // test GM_hitch gvar.isGreaseMonkey=true; //GM_log('GreaseMonkey API detected...'); } else if(gsv.match(/not\s+supported/)) { needApiUpgrade=true; gvar.isBuggedChrome=true; //GM_log('Bugged Chrome GM API detected...'); } // if(gsv.indexOf('staticArgs')>0) // // test GM_hitch } else { needApiUpgrade=true; //GM_log('No GM API detected...'); } // if(typeof(GM_setValue)!='undefined') if(needApiUpgrade) { //GM_log('Trying to recreate needed GM API...'); var ws=null; try { ws=typeof(unsafeWindow.localStorage); unsafeWindow.localStorage.length; } catch(e) { ws=null; } // Catch Security error function COOKIE_setValue( cookieName, cookieValue, lifeTime ) { if( !cookieName ) { return; } if( lifeTime == "delete" ) { lifeTime = -10; } else { lifeTime = 31536000; } switch (typeof(cookieValue)) { case 'string': cookieValue = 'S]'+cookieValue; break; case 'number': if(cookieValue.toString().indexOf('.')<0) { cookieValue = 'N]'+cookieValue.toString(); } break; case 'boolean': cookieValue = 'B]'+cookieValue; break; } // switch (typeof(cookieValue)) document.cookie = escape(GMSTORAGE_PATH)+ escape( cookieName ) + "=" + escape( cookieValue ) + ";expires=" + ( new Date( ( new Date() ).getTime() + ( 1000 * lifeTime ) ) ).toGMTString() + ";path=/"; } function COOKIE_getValue( cookieName, oDefault ) { var cookieJar = document.cookie.split( "; " ); for( var x = 0; x < cookieJar.length; x++ ) { var oneCookie = cookieJar[x].split( "=" ); if( oneCookie[0] == escape(GMSTORAGE_PATH)+ escape( cookieName ) ) { try { // eval('var footm = '+unescape( oneCookie[1] )); var footm = unescape( oneCookie[1] ); } catch(e) { return oDefault; } //return footm; switch(footm.substr(0,2)) { case 'S]': return footm.substr(2); case 'N]': return parseInt(footm.substr(2)); case 'B]': return footm.substr(2)=='true'; } // switch(footm.substr(0,2)) } } return oDefault; } COOKIE_setValue("GM_implementation", "COOKIES"); if(ws=='object') { //GM_log('Using localStorage for GM API.'); localStorage_getValue=function(name,defValue) { var value=unsafeWindow.localStorage.getItem(GMSTORAGE_PATH+name); if(value==null) { return defValue; } else { switch(value.substr(0,2)) { case 'S]': return value.substr(2); case 'N]': return parseInt(value.substr(2)); case 'B]': return value.substr(2)=='true'; } // switch(value.substr(0,2)) } // if(value==null) return value; } // localStorage_getValue=function(name,defValue) localStorage_setValue=function(name,value) { switch (typeof(value)) { case 'string': unsafeWindow.localStorage.setItem(GMSTORAGE_PATH+name,'S]'+value); break; case 'number': if(value.toString().indexOf('.')<0) { unsafeWindow.localStorage.setItem(GMSTORAGE_PATH+name,'N]'+value); } break; case 'boolean': unsafeWindow.localStorage.setItem(GMSTORAGE_PATH+name,'B]'+value); break; } // switch (typeof(value)) } // localStorage_setValue=function(name,value) localStorage_deleteValue=function(name) { unsafeWindow.localStorage.removeItem(GMSTORAGE_PATH+name); } // localStorage_deleteValue=function(name) base_get_Value = localStorage_getValue; base_set_Value = localStorage_setValue; base_delete_Value = localStorage_deleteValue; } else if( "COOKIES" == COOKIE_getValue("GM_implementation", "no cookies") ) { //GM_log('Using cookies for GM API.'); function COOKIE_deleteValue( oKey ) { //yes, they didn't seem to provide a way to delete variables in Greasemonkey, and the user must use about:config to //delete them - so the stored variables will pile up forever ... COOKIE_setValue( oKey, '', 'delete' ); } base_get_Value = COOKIE_getValue; base_set_Value = COOKIE_setValue; base_delete_Value = COOKIE_deleteValue; } else if(!gvar.isOpera || typeof(GM_setValue)=='undefined') { //GM_log('Using temporarilyStorage for GM API.'); gvar.temporarilyStorage=new Array(); tempStorage_getValue=function(name,defValue) { if(typeof(gvar.temporarilyStorage[GMSTORAGE_PATH+name])=='undefined') { return defValue; } else { return gvar.temporarilyStorage[GMSTORAGE_PATH+name]; } // if(typeof(gvar.temporarilyStorage[GMSTORAGE_PATH+name])=='undefined') } // tempStorage_getValue=function(name,defValue) tempStorage_setValue=function(name,value) { switch (typeof(value)) { case "string": case "boolean": case "number": gvar.temporarilyStorage[GMSTORAGE_PATH+name]=value; } // switch (typeof(value)) } // tempStorage_setValue=function(name,value) tempStorage_deleteValue=function(name) { delete gvar.temporarilyStorage[GMSTORAGE_PATH+name]; }; // tempStorage_deleteValue=function(name) base_get_Value = tempStorage_getValue; base_set_Value = tempStorage_setValue; base_delete_Value = tempStorage_deleteValue; } // if(ws=='object') if(typeof(GM_registerMenuCommand)=='undefined') { function GM_registerMenuCommand(name,cmd) { // Dummy //GM_log("Notice: GM_registerMenuCommand is not supported."); } // GM_registerMenuCommand=function(name,cmd) // Dummy } // if(typeof(GM_registerMenuCommand)=='undefined') } //if(needApiUpgrade) else if(typeof(GM_deleteValue)=='undefined') { function dummy_deleteValue( oKey ) { //GM_log("Notice: GM_deleteValue is not supported."); } base_get_Value = GM_getValue; base_set_Value = GM_setValue; base_delete_Value = dummy_deleteValue; } else { base_get_Value = GM_getValue; base_set_Value = GM_setValue; base_delete_Value = GM_deleteValue; } if(typeof GM_listValues != "undefined") { //GM_log("GM_listValues found.") //get_Value = base_get_Value; function get_Value( Name, Value) { return base_get_Value(prefix+Name, Value); } //set_Value = base_set_Value; function set_Value( Name, Value) { base_set_Value(prefix+Name, Value); } //delete_Value = base_delete_Value; function delete_Value( Name) { base_delete_Value(prefix+Name); } //list_Values = GM_listValues; function list_Values() { var list = GM_listValues(); var filteredlist ; for(var i=list.length-1;i>=0;--i) if(0==list[i].indexOf(prefix)) filteredlist.push(list[i].substr(prefix.length)); return filteredlist; } } else { //GM_log("GM_listValues undefined. Attempting to recreate...") //get_Value = base_get_Value; function get_Value( Name, Value) { return base_get_Value(prefix+Name, Value); } function set_Value( Name, Value) { var list = base_get_Value(prefix+"GM_listValues",""); if(list == "") base_set_Value(prefix+"GM_listValues", Name ); else { //check if Name is already in the list var splitlist = list.split("SEPARATOR"); for(var i = splitlist.length-1; i>=0; --i) { if(splitlist[i] == Name) { base_set_Value(prefix+Name, Value); return; } } //add new Name to the list base_set_Value(prefix+"GM_listValues", list + "SEPARATOR" + Name ); } base_set_Value(prefix+Name, Value); } function delete_Value( Name) { var list = base_get_Value(prefix+"GM_listValues",""); if( list == Name ) base_set_Value(prefix+"GM_listValues", "" ); else { var regex = new RegExp("SEPARATOR" + Name,"g"); var matches = list.match(regex); if(matches.length == 1) base_set_Value(prefix+"GM_listValues", list.replace("SEPARATOR" + Name,"") ); else { var newlist = ""; var list = list.split("SEPARATOR"); for(var i = list.length-1; i>=0; --i) { if(list[i] != Name) { if(newlist == "") newlist = list[i]; else newlist = newlist + "SEPARATOR" + list[i]; } } base_set_Value(prefix+"GM_listValues", newlist ); } } base_delete_Value( prefix+Name); } function list_Values() { var list = base_get_Value(prefix+"GM_listValues","").split("SEPARATOR"); return list; } } //} // function GM_ApiBrowserCheck() ///////////////////////////////////////////////////////////////////////////////////////////////////////////// var newHTMLs = ""; var newHTMLe = ""; var newHTMLu = ""; var cells = document.getElementsByTagName('td'); var addLink; var linkInfo; var linkActionAdd = 1; var linkActionRemove = 2; var shortCuts = "e536&loaned=false::e44&loaned=true::e46&loaned=false::e47&loaned=false::e23&loaned=false::u62::u63::u68::u61::s66::e512&loaned=false::e20::"; // shortCuts = get_Value("ShortcutCommands", shortCuts); //GM_log("shortcuts="+shortCuts); //set_Value("ShortcutCommands", "e20::"); //var sRegex = new RegExp('(?!table).a href="senditem.php.id=([0-9]+)(?!&.+)?" title="(.+)(?!Shortcut)"..Send.<.a>(?!)'); var sRegex = new RegExp('(?!table).a (?:class="button" )?href="senditem.php.id=(.+)" title="(.+)(?!Shortcut)"..?Send.?<.a>(?!<.td>)',"i"); var uRegex = new RegExp('(?!table).a (?:class="button" )?href="inventory.php.use=([0-9]+)".+title="(.+)(?!Shortcut)"..?Use.?<.a>(?!<.td>)',"i"); var eRegex = new RegExp('(?!table).a (?:class="button" )?href="equip.php.install=([0-9]+.+loaned=(?:false|true))" title="(.+)(?!Shortcut)"..?(?:Equip|Install).?<.a>(?!<.td>)',"i"); var tableTest = new RegExp('table',"i"); for(var i = 28 ; i < cells.length; i++) { if(!tableTest.test(cells[i].innerHTML)) { if(sRegex.test(cells[i].innerHTML)) { linkInfo = sRegex.exec(cells[i].innerHTML); cells[i].innerHTML = cells[i].innerHTML.replace(/(>\[?Send\]?)/, '$1' + createLink("s", linkInfo[1], linkInfo[2])); } // if(sRegex.test(cells[i].innerHTML)) // Check for Send Links if(uRegex.test(cells[i].innerHTML)) { linkInfo = uRegex.exec(cells[i].innerHTML); cells[i].innerHTML = cells[i].innerHTML.replace(/(>\[?Use\]?)/, '$1' + createLink("u", linkInfo[1], linkInfo[2])); cells[i].style.minWidth = '325px'; cells[i].previousSibling.style.minWidth = '100px'; } // if(uRegex.test(cells[i].innerHTML)) // Check for Use Links if(eRegex.test(cells[i].innerHTML)) { linkInfo = eRegex.exec(cells[i].innerHTML); cells[i].style.minWidth = '325px'; cells[i].previousSibling.style.minWidth = '100px'; if("SB" == getGameName() ) cells[i].innerHTML = cells[i].innerHTML.replace(/(>\[?Equip\]?)/, '$1' + createLink("e", linkInfo[1], linkInfo[2])); else cells[i].innerHTML = cells[i].innerHTML.replace(/(>\[?Install\]?)/, '$1' + createLink("e", linkInfo[1], linkInfo[2])); } // if(eRegex.test(cells[i].innerHTML)) // Check for Equip and Install Links } // Keep from executing when I don't want to. } // for(var i = 30; i < cells.length; i++) // List of all table cells in the game //Placement of the Shortcuts section var above_header; switch(LinkPosition.toString()) { case "0": above_header = "
| ' +
'
| ' +
'
| ' +
'