// ==UserScript== // @name phpBBv3 Quick Reply // @description Adds a primitive quick reply form to a phpBBv3 topic page // @namespace http://glenncarr.com/greasemonkey/phpbb // @include *viewtopic.php* // @include *posting.php* // @author Glenn Carr (glenn at glenncarr dot com) // $LastChangedRevision$ // $LastChangedDate$ // ==/UserScript== /* about:config options attach_signature - default: true disable_bbcode - default: false disable_smilies - default: false disable_parse_urls - default: false notify_on_reply - default: false */ /* Updates: 25-Jul-2007 - Bugfix 25-Jul-2007 - Bugfix: Quick Reply wasn't being inserted on topics with only one post; Also added 'Save' button 25-Jul-2007 - Yet another bugfix: Quick Reply wasn't being inserted in other situation 25-Jul-2007 - Make tab order match the regular post page; Change button text 26-Jul-2007 - Add posting options (attach sig, etc.) 26-Jul-2007 - Added ability to quote posts by holding down ALT key when 'Quote' is clicked; Made height of TEXTAREA taller 27-Jul-2007 - Added ability to increase/decrease message area dynamically with little buttons on the right 27-Jul-2007 - Added keybindings for Alt-PageUp and Alt-PageDown to resize message area; Fixed bug where height wasn't limited 27-Jul-2007 - Added client-side POST so that there's no intermediate page after replying 29-Jul-2007 - Display errors when a post a made too soon after posting 29-Jul-2007 - Add keybinding to use Alt-Enter to submit the post 29-Jul-2007 - Removed experimental 'View Smilies' link 31-Jul-2007 - Stop default behavior of downloading link when Alt-clicking on Quote buttons 31-Jul-2007 - Only handle Alt-Enter if quick reply textarea has focus 01-Aug-2007 - Added subject; Removed resize buttons from tab traversal 03-Aug-2007 - Added smiley support 08-Aug-2007 - Shortened help tip 14-Sep-2007 - Fixed bug where topic ID wasn't found 20-Nov-2007 - Was broken by RC6,7. Fixed by including valid values for new form field values. 27-Nov-2007 - Allow Alt-Enter to work on regular posting page. 16-Dec-2007 - Fixes due to certain board mods 19-Dec-2007 - Fix bug introduced with last 'fix'. */ (function() { // As well as adding quick reply functionality, also take the liberty to add the same // keyboard shortcut (Alt-Enter) to submit posts for the regular posting page used to reply/edit/post. // (I was constantly annoyed that hitting Alt-Enter didn't work on those pages after becoming so // accustomed to hitting with the Quick Reply/Edit scripts. if ( /posting\.php/i.test( location.href ) ) { var textarea = document.getElementById( 'message' ); if ( textarea == null ) return; // Find first 'Submit' button and fire a click on it. var submitButton = document.evaluate("//input[@type='submit'][@value='Submit']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if ( submitButton.snapshotLength == 0 ) return; submitButton = submitButton.snapshotItem( 0 ); textarea.addEventListener('keydown', function(e) { if ( e.altKey && e.keyCode == 13 && confirm( 'Submit message?' ) ) { // Thanks to Mihai Parparita for the simulateClick function: // http://googlereader.blogspot.com/2005/11/warning-geekery-ahead.html var event = submitButton.ownerDocument.createEvent("MouseEvents"); event.initMouseEvent("click", true, // can bubble true, // cancellable submitButton.ownerDocument.defaultView, 1, // clicks 50, 50, // screen coordinates 50, 50, // client coordinates false, false, false, false, // control/alt/shift/meta 0, // button, submitButton); submitButton.dispatchEvent(event); } return false; }, false); return; } 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"; var sidanchors = document.evaluate("//a[contains(@href,'sid=')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if ( sidanchors.snapshotLength == 0 ) return; var sid = sidanchors.snapshotItem( 0 ).href.replace( /^.*&sid=([^&]+)/, '$1' ); var elementToPrecede = document.getElementById( 'viewtopic' ); if ( !elementToPrecede || elementToPrecede.tagName != 'FORM' ) { var topicActions = document.evaluate("//div[@class='topic-actions']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if ( topicActions.snapshotLength != 2 ) return; elementToPrecede = topicActions.snapshotItem( 1 ); } var forumId = location.href.replace( /^.*[?&]f=(\d+).*$/, '$1' ); if ( !forumId || !/^\d+$/.test( forumId ) ) { var f = document.evaluate("//a[contains(@href,'viewforum.php?f=')][contains(.,'Return to ')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if ( f.snapshotLength == 0 ) return; forumId = f.snapshotItem( 0 ).href.replace( /^.*[?&]f=(\d+).*$/, '$1' ); if ( !forumId || !/^\d+$/.test( forumId ) ) return; } var t = document.evaluate("//h2/a[contains(@href,'viewtopic.php?t=')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if ( t.snapshotLength == 0 ) { t = document.evaluate("//h2/a[contains(@href,'viewtopic.php?f=')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if ( t.snapshotLength == 0 ) return; } var topicId = t.snapshotItem( 0 ).href.replace( /^.*[?&]t=(\d+).*$/, '$1' ); if ( !topicId || !/^\d+$/.test( topicId ) ) return; var subject = t.snapshotItem( 0 ).innerHTML; t = document.evaluate( "//a[contains(@href,'posting.php?mode=reply')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if ( t.snapshotLength == 0 ) return; var postReplyUrl = t.snapshotItem( 0 ).href; GM_addStyle( '\ *::-moz-any-link input, *::-moz-any-link textarea { /* FX only disappearing caret anyone? */ overflow: auto; }\ .gncQuoteHelp { font-style: italic }\ FORM#gncQuickReply { text-align: center }\ FORM#gncQuickReply > div { padding: 3px 3px }\ FORM#gncQuickReply TEXTAREA { font-size: 1.3em; height: 150px; }\ li.gncQuickReplyNote { font-style: italic; padding-top: 2px; color: #666; }\ ' ); var ATTACH_SIG = GM_getValue( 'attach_signature', true ); GM_setValue( 'attach_signature', ATTACH_SIG ); var DISABLE_BBCODE = GM_getValue( 'disable_bbcode', false ); GM_setValue( 'disable_bbcode', DISABLE_BBCODE ); var DISABLE_SMILIES = GM_getValue( 'disable_smilies', false ); GM_setValue( 'disable_smilies', DISABLE_SMILIES ); var DISABLE_PARSE_URLS = GM_getValue( 'disable_parse_urls', false ); GM_setValue( 'disable_parse_urls', DISABLE_PARSE_URLS ); var NOTIFY_ON_REPLY = GM_getValue( 'notify_on_reply', false ); GM_setValue( 'notify_on_reply', NOTIFY_ON_REPLY ); var qrForm = document.createElement( 'form' ); qrForm.id = 'gncQuickReply'; qrForm.method = 'post'; qrForm.action = './posting.php?mode=reply&f=' + forumId + '&sid=' + sid + '&t=' + topicId; var IMAGE_URL_DECREASE = 'data:image/gif;base64,R0lGODlhFQAJAIABAE1NTQAAACH5BAEAAAEALAAAAAAVAAkAAAIUjI%2Bpe8BvgIRLWlpxnbpZ14UiUgAAOw%3D%3D'; var IMAGE_URL_INCREASE = 'data:image/gif;base64,R0lGODlhFQAJAIABAE1NTQAAACH5BAEAAAEALAAAAAAVAAkAAAIUjI%2Bpy50AoVtxMmBVlPnUjmAgWAAAOw%3D%3D'; qrForm.style.display = 'none'; qrForm.innerHTML = '\