// ==UserScript== // @name MsgHelp inline post editing (wdz rewrite) // @namespace http://msghelp.net/ // @include http://msghelp.net/* // @include http://*.msghelp.net/* // @date 2009-10-20 // ==/UserScript== var x = document.getElementsByTagName('a'); for(var i = 0; i < x.length; i++) { // Not all tags have href attributes if(!x[i].hasAttribute('href')) continue; var match = x[i].href.match(/editpost\.php\?pid=([0-9]+)/); if(!match) continue; var pid = match[1]; var tDiv = getId('pid_'+pid); // Create a div to hold the inline editor var oDiv = document.createElement('div'); oDiv.setAttribute('id', 'pid_inline_'+pid); oDiv.setAttribute('style', 'display:none; margin:5px;'); tDiv.parentNode.insertBefore(oDiv, tDiv); // Create an "i-edit" button var iEdit = document.createElement('img'); iEdit.setAttribute('src', 'data:image/gif;base64,R0lGODlhNwAPAP8AAP///0JrjPf37/f39+/v5///9+/n1lqEpSlajFp7pe/v7+fe1iFShNbe3iFahO/37+/3/97e1jljlM7W3kpznOfv797e3u/n3sbW3ufn1sbO3pStxpy1xkJrlFJ7pZy9zr3G1r3O1rXGzrXG1t7n5//3997v/0prjJy93t7n797WzoSctc7Gva29zq29xu/391KEpc7e3mOcznOMnDlrnIStzs7n95ycpSlzve/v95StvbW9va3O5+fn3lJznEJznEJ7rVqt797e59bW1iFajGOMref3/6WtrcbO1ilztYycrb3n//f/9zFjjKXO5zFjlClrrVqErSFjrWOEpWSDqqVza+///4x7hJxKMYxSUmtza0prlGuElITO/87v/87n/zlrlIy996XO97XO1q3O1q3W95S1zpy91t7eznu1963W587e53u152u15+fn5+fv59be52ul3nuUtSFrtYSltXuctXucrWuMra2trZSlrZyttd7v95ytxoytzsbGxiFrvb29tYylvYSlvc7t3AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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Ow=='); iEdit.setAttribute('alt', 'Inline Edit'); iEdit.setAttribute('title', 'Inline Edit'); iEdit.setAttribute('style', 'border:0; margin-right:4px; cursor:pointer;'); iEdit.setAttribute('onclick', 'toggleInlineEditor('+pid+')'); x[i].parentNode.insertBefore(iEdit, x[i]); } // Preload the activity indicator image var activityImg = new Image(); activityImg.setAttribute('src', '/images/ajax_activity.gif'); var inlineEditorCache = {}; function toggleInlineEditor(pid) { var postDiv = getId('pid_'+pid); var inlineEditor = getId('pid_inline_'+pid); if(inlineEditor.style.display == 'none') { // Inline editor is currently hidden; need to show it // First make sure the required information is cached var isCached = (typeof inlineEditorCache[pid] != 'undefined'); if(!isCached) { // Prepare "loading" message inlineEditor.innerHTML = '
'+ 'Loading Loading inline editor...'+ '
'; } // Show inline editor or "loading" message inlineEditor.style.display = ''; postDiv.style.display = 'none'; if(isCached || cacheInlineEditor(pid)) { var cached = inlineEditorCache[pid]; // This is reset even if it's already been set, so that any changes made in the textarea will be discarded after the user clicks "Cancel Edit" inlineEditor.innerHTML = '
'+ ''+ ''+ ''+ ''+ ''+ '
'+ '
'; return; // All OK } alert("Failed to set up inline editor!"); } // Hide the inline editor (or the "loading" message) postDiv.style.display = ''; inlineEditor.style.display = 'none'; } function cacheInlineEditor(pid) { var url = 'http://'+window.location.host+'/editpost.php?pid='+pid; var xmlhttp = new XMLHttpRequest(); xmlhttp.open('GET', url, false); xmlhttp.send(null); if(xmlhttp.readyState !== 4 || xmlhttp.status !== 200) { return false; } var postKeyMatch = xmlhttp.responseText.match(/name="post_key"[^>]* value="([a-f0-9]+)"/); if(!postKeyMatch) return false; var subjectMatch = xmlhttp.responseText.match(/name="subject"[^>]* value="([^"]*)"/); if(!subjectMatch) return false; var messageMatch = xmlhttp.responseText.match(/name="message"[^>]*>([^<>]+)<\/textarea>/); if(!messageMatch) return false; inlineEditorCache[pid] = {'subject': subjectMatch[1], 'rawMessage': messageMatch[1], 'postKey': postKeyMatch[1]}; // The required information is now cached return true; } function getId(id) { return document.getElementById(id); } var w = (this.unsafeWindow || window); w.toggleInlineEditor = toggleInlineEditor;