// ==UserScript== // @name Yahoo Fantasy Baseball Expand Recent Activity // @namespace http://glenncarr.com/greasemonkey/yahoofantasy // @description Adds more recent transactions and messages to the league home page (currently just handles messages) // @include *baseball.fantasysports.yahoo.com/* // $LastChangedRevision$ // $LastChangedDate$ // ==/UserScript== /* Updates: 18-May-2007 - Added Reply link to each message; Made message headers the same color 18-May-2007 - Fixed prepending duplicate 'Re: ' when replying; Increased message composition box width and font size 29-May-2007 - Changed include path to allow http://beta. */ (function() { // Increase width and font of message textarea... if ( location.href.match(/baseball\.fantasysports\.yahoo\.com\/b\d\/\d+\/postmessage/i) ) { var ta = document.getElementsByTagName( 'TEXTAREA' ); if ( !ta ) return; ta = ta[ 0 ]; ta.style.width = "100%"; ta.style.fontSize = "130%"; return; } if (!location.href.match(/baseball\.fantasysports\.yahoo\.com\/b\d\/\d+/i)) return; var divMessages = document.getElementById( 'recentmessages' ); if ( divMessages == null ) return; var msgTable = divMessages.getElementsByTagName( 'TABLE' ); if ( msgTable == null ) return; msgTable = msgTable[ 0 ]; var MAX_MESSAGES_TO_DISPLAY = GM_getValue("message_count", 10); GM_setValue("message_count", MAX_MESSAGES_TO_DISPLAY); var WORKING_IMG_URL = "data:image/gif,GIF89a%0A%00%0A%00%91%03%00%CC%CC%CC%FFff%FF%00%00%FF%FF%FF!%FF%" + "0BNETSCAPE2.0%03%01%00%00%00!%F9%04%05%00%00%03%00%2C%00%00%00%00%0A%00%0A%00%00%02%17%9C'r%06%80%1A%" + "02s'%AE%3Bqk%9A%E2%C3%81%14Gz%D9Q%00%00!%F9%04%05%00%00%03%00%2C%01%00%00%00%08%00%03%00%00%02%0A%9C%" + "136%22%83%03%00S%10%14%00!%F9%04%05%00%00%03%00%2C%00%00%00%00%06%00%06%00%00%02%0C%9C%070%11%A8%7C%A" + "2%11%22%D2X%00%00!%F9%04%05%00%00%03%00%2C%00%00%01%00%03%00%08%00%00%02%0A%1C%608%13%C1%BE%96%10c%16" + "%00!%F9%04%05%00%00%03%00%2C%00%00%04%00%06%00%06%00%00%02%0A%04%86c%C9%1C%E1%A0%10l%16%00!%F9%04%05%" + "00%00%03%00%2C%01%00%07%00%08%00%03%00%00%02%0A%04%86%23b%13%A1Dz%A9%00%00!%F9%04%05%00%00%03%00%2C%0" + "4%00%04%00%06%00%06%00%00%02%0C%9C'r%A8%BB%11%06%00%03Jz%0A%00!%F9%04%09%00%00%03%00%2C%07%00%01%00%0" + "3%00%08%00%00%02%0A%94f%A3%1A1%BD%00%18r%14%00%3B"; GM_xmlhttpRequest({ method: 'GET', url: location.href.match( /(^.*baseball\.fantasysports\.yahoo\.com\/b\d\/\d+)/i )[1] + '/messages', onload: getAllMessagesHandler( handleAllMessages, msgTable ), }); function handleAllMessages( responseText, msgTable ) { var tables = responseText.split( /\]+\>|\<\/table\>/i ); for ( var i = 0; i < tables.length; i++ ) { if ( tables[ i ].match( /Date\<\/th\>/i ) ) { var rows = tables[ i ].split( /\ (MAX_MESSAGES_TO_DISPLAY + 2) /* header rows */ ) rows.splice( MAX_MESSAGES_TO_DISPLAY + 2, rows.length - (MAX_MESSAGES_TO_DISPLAY + 2) ); msgTable.innerHTML = rows.join( ''; row.parentNode.insertBefore( newRow, row.nextSibling ); for ( var iCell = 0; iCell < row.cells.length; iCell++ ) { var cell = row.cells[ iCell ]; var a = cell.getElementsByTagName( 'A' ); if ( a != null && a.length > 0 ) { a = a[ 0 ]; var hrefMessage = a.getAttribute( 'href' ).replace( /^\//, 'http://baseball.fantasysports.yahoo.com/' ); GM_xmlhttpRequest({ method: 'GET', url: hrefMessage, onload: getMessageContentHandler( messageContentHandler, msgCell, msgSubject ) }); break; } } if ( msgCount == MAX_MESSAGES_TO_DISPLAY ) return; } } } } function messageContentHandler( responseText, msgCell, msgSubject ) { var tables = responseText.split( /\]+\>|\<\/table\>/i ); for ( var i = 0; i < tables.length; i++ ) { if ( tables[ i ].match( /Message:.*\d+ of \d+/i ) ) { msgCell.innerHTML = '' + tables[ i ] + '
'; var table = msgCell.childNodes[ 0 ]; table.rows[ 0 ].innerHTML = ''; //'' + table.rows[0].cells[0].getElementsByTagName('B')[0].innerHTML + ''; var cell = table.rows[ 1 ].cells[ 0 ]; cell.style.fontSize = "inherit"; var url = location.href.replace( /(.*\/\d+$)/i, '$1/postmessage?subject=Re:+' + msgSubject.replace( /^re:[\+\s+]/i, '' ) ); cell.innerHTML = '
[ Reply ]
' + cell.innerHTML.replace( /\/gi, '' ); return; } } } function getAllMessagesHandler( responseHandler, msgTable ) { return function ( responseDetails ) { if ( responseDetails.status == 200 ) responseHandler( responseDetails.responseText, msgTable ); } } function getMessageContentHandler( responseHandler, msgCell, msgSubject ) { return function ( responseDetails ) { if ( responseDetails.status == 200 ) responseHandler( responseDetails.responseText, msgCell, msgSubject ); } } function getClassName( el ) { var className = el.getAttribute( 'class' ); if ( className == null ) className = el.getAttribute( 'className' ); return className; } function stripTags(s) { return s.replace(/<\/?[^>]+>| /gi,''); } })();