// ==UserScript== // @name DazeyMod // @namespace www.lucky13games.com // @description Allows changes to various BGG pages // @include http://www.boardgamegeek.com/* // @include http://boardgamegeek.com/* // @version 1.0 // @grant GM_registerMenuCommand // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @grant GM_listValues // @downloadURL none // ==/UserScript== // Changelog // v1.0 - 5/12/2014 // - Converted from localStorage to GreaseMonkey storage // - Added Username Tag functionality // - Added tabbed settings // - Fixed icons not showing up in Geekbuddy views // - Fixed icons not showing up in Geekmail // v0.9 - 5/3/2014 // - Began adding functionality for other "modules" to interact with DazeyMod // v0.8 - 4/25/2014 // - Added larger size thumbnail option for list views, doesn't work on AJAX requests, need to fix this. // v0.7 - 4/16/2014 // - Added icon refreshing after saving the settings // - Added option to move QuickBar down // - Prettied up the settings window // - Redid popup text for settings and manual buttons to use simpler title attribute // - Code Cleanup // v0.6 - 4/15/2014 // - Added "loading" icons and text so page wouldn't change size when loading // - Added Setting to enable/disable context menu // - Fixed Manual load duplication bug //--- Check if GreaseMonkey variables exist, create them with defaults if not ---// if(typeof GM_getValue("DM_LS_Settings")==='undefined'){ console.log("DM_LS_Settings not set"); var tmpObj = new Object; tmpObj["showLoginText"]="always"; tmpObj["showLoginTextGeeklists"]=true; tmpObj["showLoginTextTrades"]=true; tmpObj["showLoginTextForums"]=true; tmpObj["showLoginIcon"]="always"; tmpObj["showLoginIconGeeklists"]=true; tmpObj["showLoginIconTrades"]=true; tmpObj["showLoginIconForums"]=true; tmpObj["showLoginIconHover"]=true; tmpObj["iconPack"]="D10"; tmpDays=new Array(0, 1.5, 7, 30, 180, 365); tmpObj["iconDays"]=JSON.stringify(tmpDays); tmpObj["showContextMenu"]=false; GM_setValue("DM_LS_Settings", JSON.stringify(tmpObj)); } var DM_LS_Settings = JSON.parse(GM_getValue("DM_LS_Settings")); if(typeof GM_getValue("DM_LS_Users")==='undefined'){ console.log("DM_LS_Users not set"); var tmpObj = new Object; tmpObj["dazeysan.lastChecked"]="0"; GM_setValue("DM_LS_Users", JSON.stringify(tmpObj)); } var DM_LS_Users = JSON.parse(GM_getValue("DM_LS_Users")); if(typeof GM_getValue("DM_LT_Settings")==='undefined'){ console.log("DM_LT_Settings not set"); var tmpObj = new Object; tmpObj["largeThumbnail"]=false; tmpObj["largeThumbnailSize"]="90"; GM_setValue("DM_LT_Settings", JSON.stringify(tmpObj)); } var DM_LT_Settings = JSON.parse(GM_getValue("DM_LT_Settings")); if(typeof GM_getValue("DM_QB_Settings")==='undefined'){ console.log("DM_QB_Settings not set"); var tmpObj = new Object; tmpObj["moveQuickBar"]=false; GM_setValue("DM_QB_Settings", JSON.stringify(tmpObj)); } var DM_QB_Settings = JSON.parse(GM_getValue("DM_QB_Settings")); if(typeof GM_getValue("DM_UT_Settings")==='undefined'){ console.log("DM_UT_Settings not set"); var tmpObj = new Object; tmpObj["showUsernameTag"]=false; tmpObj["defaultIcon"]="8"; GM_setValue("DM_UT_Settings", JSON.stringify(tmpObj)); } var DM_UT_Settings = JSON.parse(GM_getValue("DM_UT_Settings")); if(typeof GM_getValue("DM_UT_Users")==='undefined'){ console.log("DM_UT_Users not set"); var tmpObj = new Object; tmpObj["dazeysan"]="Maker of DazeyMod"; tmpObj["dazeysan.icon"]="3"; GM_setValue("DM_UT_Users", JSON.stringify(tmpObj)); } var DM_UT_Users = JSON.parse(GM_getValue("DM_UT_Users")); //--- End GreaseMonkey Storage Set Up ---// //--- Set up some other variables ---// var usernameTagIcons=new Array("2014491.png","2014492.png","2014493.png","2014494.png","2014495.png","2014496.png","2014497.png","2014498.png","2014499.png","2014500.png","2014501.png","2014502.png"); var tmp=DM_LS_Settings["iconDays"]; var loginDays=JSON.parse(tmp); var tList; // QuickBar Moving stuff document.getElementById('quickbar_status').parentNode.parentNode.id="QBParent"; quickBar = document.getElementById('quickbar_status').parentNode; // Set up an array of other module's save functions window.saveFunctions = [ ]; // Arrays of file names for the LastSeen Icons var loginIconD10=new Array("1990299.png","1990300.png","1990303.png","1990301.png","1990302.png","1990298.png","1992653.png"); var loginIconHex=new Array("1990348.png","1990349.png","1990350.png","1990352.png","1990353.png","1990354.png","1992652.png"); var loginIconHour=new Array("1992646.jpg","1992647.jpg","1992648.jpg","1992649.jpg","1992650.jpg","1992651.jpg","1992654.png"); if(DM_LS_Settings["iconPack"]=="D10") { loginIcons = loginIconD10; } if(DM_LS_Settings["iconPack"]=="Hex") { loginIcons = loginIconHex; } if(DM_LS_Settings["iconPack"]=="Hour") { loginIcons = loginIconHour; } var showText = false; var showIcon = false; var uList = document.getElementsByClassName("avatarblock js-avatar"); var avatarAdded=0; var now = new Date(); var days; if(DM_LS_Settings["showLoginText"]=="always") { //console.log("Always Text"); showText = true; } if(DM_LS_Settings["showLoginIcon"]=="always") { //console.log("Always Icon"); showIcon = true; } // Check what sort of page we're on and show text or icons as needed if(document.baseURI.indexOf("/geeklist/") > -1) { // Geeklist console.log("Page is in Geeklists"); if(DM_LS_Settings["showLoginTextGeeklists"]==true && DM_LS_Settings["showLoginText"]=="selected") { showText = true; } if(DM_LS_Settings["showLoginIconGeeklists"]==true && DM_LS_Settings["showLoginIcon"]=="selected") { showIcon = true; } } if(document.baseURI.substr(-10) == "fortrade=1") { // Trades Collection page console.log("Page is in Trades"); if(DM_LS_Settings["showLoginTextTrades"]==true && DM_LS_Settings["showLoginText"]=="selected") { showText = true; } if(DM_LS_Settings["showLoginIconTrades"]==true && DM_LS_Settings["showLoginIcon"]=="selected") { showIcon = true; } } if(document.baseURI.indexOf("/article/") > -1) { // Forums console.log("Page is in Forums"); if(DM_LS_Settings["showLoginTextForums"]==true && DM_LS_Settings["showLoginText"]=="selected") { showText = true; } if(DM_LS_Settings["showLoginIconForums"]==true && DM_LS_Settings["showLoginIcon"]=="selected") { showIcon = true; } } //--- End Other Variable Set Up ---// //--- Move QuickBar if needed ---// if(DM_QB_Settings["moveQuickBar"]==true){ //console.log("moving QuickBar"); document.getElementById('main_content').insertBefore(quickBar, document.getElementById('main_content').childNodes[0]); } //--- End of moving Quickbar ---// //--- Make a "bluebox" at the top of the content for our use ---// tmpDiv = document.createElement('div'); tmpDiv.id = "DazeyModSettings"; tmpDiv.setAttribute("class", "bluebox"); tmpDiv.appendChild(document.createTextNode("DazeyMod\u00A0\u00A0\u00A0")); // Add a settings button tmpElm=document.createElement('a'); tmpElm.addEventListener("click", showHideSettingsLoad, false); tmpImg=document.createElement('img'); tmpImg.id="DazeyMod.SettingsIcon"; tmpImg.src="http://cf.geekdo-images.com/images/pic1991213.png"; tmpImg.style.cursor="pointer"; tmpImg.title="DazeyMod Settings"; tmpElm.appendChild(tmpImg); tmpDiv.appendChild(tmpElm); tmpDiv.appendChild(document.createTextNode("\u00A0\u00A0\u00A0")); // Add a manual button tmpElm=document.createElement('a'); tmpElm.addEventListener("click", function(){showLoginDates("manual");}, false); tmpImg=document.createElement('img'); tmpImg.src="http://cf.geekdo-images.com/images/pic"+loginIcons[0]; tmpImg.style.cursor="pointer"; tmpImg.id="DazeyMod.ManualIcon"; tmpImg.title="Manually Load Last Login Data"; tmpElm.appendChild(tmpImg); tmpDiv.appendChild(tmpElm); // Stick our bluebox at the top of main_content document.getElementById('main_content').insertBefore(tmpDiv, document.getElementById('main_content').childNodes[0]); //--- End of the DazeyMod "bluebox" ---// // Insert the place holder images above the avatar function modAvatars() { console.log("modAvatars()"); uList = document.getElementsByClassName("avatarblock js-avatar"); for(av=0; av -1) { iconRow = uList[av].childNodes[5].childNodes[1].childNodes[1].childNodes[0]; } else { iconRow = uList[av].childNodes[7].childNodes[1].childNodes[1].childNodes[0]; } dCell = iconRow.insertCell(-1); dCell.setAttribute("data-DazeyMod", "temp"); tmpImg=document.createElement('img'); tmpImg.id = "DazeyMod.LSIcon."+av; tmpImg.src = "http://cf.geekdo-images.com/images/pic2015885.png"; dCell.appendChild(tmpImg); dCell = iconRow.insertCell(-1); tmpImg=document.createElement('img'); tmpImg.id = "DazeyMod.UTIcon."+av; tmpImg.src = "http://cf.geekdo-images.com/images/pic2015885.png"; dCell.appendChild(tmpImg); uList[av].setAttribute("data-dazeymod", "modded"); } else { if(document.baseURI.indexOf("/geekbuddy.php") > -1) { iconRow = uList[av].childNodes[5].childNodes[1].childNodes[1].childNodes[0]; } else { iconRow = uList[av].childNodes[7].childNodes[1].childNodes[1].childNodes[0]; } iconRow.childNodes[7].childNodes[0].id = "DazeyMod.LSIcon."+av; iconRow.childNodes[8].childNodes[0].id = "DazeyMod.UTIcon."+av; } } if(showText || showIcon) { showLoginDates("automatic"); } if(DM_UT_Settings["showUsernameTag"]==true) { refreshUsernameTags(); } } // End modAvatars() modAvatars(); // Geekmail support, add an onClick to each message so we can refresh the icons gmList = document.getElementsByClassName('gm_label'); for (gm=0; gm 0) { for(i=1; i tmpHt) { tmpRat = tmpHt/tmpWd; tList[i].childNodes[1].childNodes[0].style.width=DM_LS_Settings["largeThumbnailSize"]+"px"; tList[i].childNodes[1].childNodes[0].style.height=(DM_LS_Settings["largeThumbnailSize"]*tmpRat)+"px"; } else { tmpRat = tmpWd/tmpHt; tList[i].childNodes[1].childNodes[0].style.width=(DM_LS_Settings["largeThumbnailSize"]*tmpRat)+"px"; tList[i].childNodes[1].childNodes[0].style.height=DM_LS_Settings["largeThumbnailSize"]+"px"; } } } // End updateThumbnailSize() function showLoginDates(src) { uList = document.getElementsByClassName("avatarblock js-avatar"); if (src == "manual") { if(DM_LS_Settings["showLoginText"]=="manual" || DM_LS_Settings["showLoginText"]=="always") { showText = true; } if(DM_LS_Settings["showLoginIcon"]=="manual" || DM_LS_Settings["showLoginIcon"]=="always") { showIcon = true; } } avatarAdded=0; if(uList.length > 0) { if(showText || showIcon) { ShowDateTemp(); window.setTimeout(getLast, 1000); } else { getLast(); } } } // End showLoginDates() function getLast() { // Loop through the detected avatars and display text or icons as chosen in settings //console.log("getLast()" + avatarAdded); uList = document.getElementsByClassName("avatarblock js-avatar"); var uName=uList[avatarAdded].getAttribute("data-username"); if(typeof DM_LS_Users[""+uName+".lastLogin"]==='undefined' || (now.getTime() - DM_LS_Users[""+uName+".lastChecked"]) > (3600000*6)){ console.log("Request "+uName+" via XMLAPI2"); var oReq = new XMLHttpRequest(); oReq.onload = function(){ var lastLogin=oReq.responseXML.getElementsByTagName("lastlogin")[0].getAttribute("value"); if(lastLogin==""){ lastLogin="2000-01-01"; } DM_LS_Users[""+uName+".lastLogin"]=lastLogin; var then = new Date(lastLogin); days = (((now.getTime()-(now.getTimezoneOffset()*60000))-then.getTime())/(86400000)); //Get number of days between now and then console.log("Days since "+uName+"'s last login: "+days); if (showText) { showDateText(avatarAdded, lastLogin); } if (showIcon) { showDateIcon(avatarAdded, lastLogin, days); } avatarAdded++; if(avatarAdded= loginDays[1]) { li = 1; } if (dy >= loginDays[2]) { li = 2; } if (dy >= loginDays[3]) { li = 3; } if (dy >= loginDays[4]) { li = 4; } if (dy >= loginDays[5]) { li = 5; } loginImg = loginIcons[li]; avDiv=document.getElementById('DazeyMod.LSIcon.'+av); avDiv.src="http://cf.geekdo-images.com/images/pic"+loginImg; avDiv.title=ll; avDiv.setAttribute("data-DazeyMod", "done"); avDiv.setAttribute("data-iconLevel", li); } } // End showDateIcon() function ShowDateTemp() { // Insert the grey icons and "Loading..." text before loading the actual content //console.log("Inserting Temp Dates"); uList = document.getElementsByClassName("avatarblock js-avatar"); for (av=0; av0){ for (i=0; i users."; // Set the cursors back to non-spinning as the settings are loaded document.getElementById('main_content').style.cursor=""; document.getElementById('DazeyMod.SettingsIcon').style.cursor="pointer"; } else { // The settings are visible, so hide them document.getElementById('settingsDiv').style.visibility = "hidden"; } } // End showHideSettings() // Create DIV for UsernameTag hover text tmpDiv=document.createElement('div'); tmpDiv.id="DazeyMod.UTText"; tmpDiv.style.visibility="hidden"; tmpDiv.style.zindex="200"; tmpDiv.style.position="absolute"; tmpDiv.style.backgroundColor="#99BEFF"; tmpDiv.style.border="1px Solid Black"; tmpDiv.style.padding="3px"; document.getElementById("main_content").appendChild(tmpDiv); // Create DIV for UsernameTag Editor tmpDiv=document.createElement('div'); tmpDiv.id="DazeyMod.UTEdit"; tmpDiv.style.visibility="hidden"; tmpDiv.style.zindex="200"; tmpDiv.style.position="absolute"; tmpDiv.style.backgroundColor="#99BEFF"; tmpDiv.style.border="1px Solid Black"; tmpDiv.style.padding="2px 4px"; tmpDiv.addEventListener("keypress", function(e) { if(e.keyCode==13){saveUsernameTag();} }, false); tmpFld=document.createElement('input'); tmpFld.setAttribute("type", "text"); tmpFld.id = "DazeyMod.UTFieldText"; tmpFld.size="40"; tmpFld.style.border="1px solid black"; tmpFld.style.padding="2px"; tmpDiv.appendChild(tmpFld); tmpDiv.appendChild( document.createTextNode("\u00A0\u00A0") ); tmpFld=document.createElement('input'); tmpFld.setAttribute("type", "button"); tmpFld.setAttribute("value", "Save"); tmpFld.addEventListener("click", function() { saveUsernameTag(); }, false); tmpDiv.appendChild(tmpFld); tmpFld=document.createElement('input'); tmpFld.setAttribute("type", "button"); tmpFld.setAttribute("value", "Close"); tmpFld.addEventListener("click", function() { document.getElementById('DazeyMod.UTEdit').style.visibility="hidden"; }, false); tmpDiv.appendChild(tmpFld); tmpFld=document.createElement('input'); tmpFld.setAttribute("type", "hidden"); tmpFld.id = "DazeyMod.UTFieldUser"; tmpDiv.appendChild(tmpFld); tmpFld=document.createElement('input'); tmpFld.setAttribute("type", "hidden"); tmpFld.id = "DazeyMod.UTIconPick"; tmpDiv.appendChild(tmpFld); tmpDiv.appendChild( document.createElement('br') ); for(i=0; i