Greasemonkey: QuickEdit + CorrectTitleDM
Das als *.js abspeichern und in Greasemonkey "reininstallieren".
Code: Alles auswählen
// phpBB Quick Edit user script
// version 0.2
// 2006-03-12
// Copyright (c) 2006, xamm
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
// modified by Dr. Evil <firefox>
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script. To install it, you need
// Greasemonkey 0.3 or later: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "phpBB Quick Edit", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ChangeLog
// 2006-??-?? - 0.3 - take over the normal edit button instead of using a custom link
// 2006-03-12 - 0.2 - Fixed the code for encoding the form data that was corrupted by GM downloading it which I'd never known before
// which means my quick reply script has been broken for months and I never knew.
// 2006-03-12 - 0.1 - Initial release
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name phpBB Quick Edit
// @namespace http://www.otsegolectric.com/greasemonkey/
// @description Adds a feature allowing you to quickly edit your posts on a phpBB forum
// @include */viewtopic.php*
// ==/UserScript==
(function() {
function encodeFormData(formData) {
var encodedData = '';
var t;
for(i = 0; i < formData.length; i++) {
t = '' + formData.charCodeAt(i).toString(16).toUpperCase();
if(t.length == 1)
encodedData += "%0" + formData.charCodeAt(i).toString(16).toUpperCase();
else
encodedData += "%" + formData.charCodeAt(i).toString(16).toUpperCase();
}
return encodedData;
}
var addQuickEdit = function(event) {
var editHREF = event.currentTarget.href;
var editHREFPart = editHREF.substring(editHREF.indexOf("posting.php"), editHREF.length);
var postBody = document.evaluate("//a[@href='" + editHREFPart + "']/../../..//*[@class='postbody']/..", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
postBody = postBody.snapshotItem(0);
if(postBody.getElementsByTagName('textarea').length == 0) {
var allElements = postBody.getElementsByTagName('*');
for(j = 0; j < allElements.length; j++)
allElements[j].style.display = 'none';
var qeTextArea = document.createElement('textarea');
var qeSubmit = document.createElement('input');
var qeIFrame = document.createElement("iframe");
qeTextArea.style.width = '90%';
qeTextArea.style.height = '200px';
qeTextArea.style.border = '1px solid #000000';
qeTextArea.style.paddingLeft = '2px';
qeTextArea.style.paddingBottom = '2px';
qeTextArea.value = '\n\n\n\n\n\t\t\tGetting post contents...';
qeTextArea.disabled = true;
qeSubmit.type = 'submit';
qeSubmit.value = 'Post';
qeSubmit.style.border = '1px solid #000000';
qeSubmit.style.position = 'absolute';
qeSubmit.addEventListener('click', editPost, true);
qeSubmit.setAttribute('editHREF', editHREF);
qeIFrame.style.width = '1px';
qeIFrame.style.height = '1px';
qeIFrame.style.display = 'none';
qeIFrame.src = editHREF;
qeIFrame.addEventListener('load',
function() {
var qeDoc = qeIFrame.contentDocument;
if(qeDoc.body.getElementsByTagName('textarea').length != 0) {
qeTextArea.value = qeDoc.body.getElementsByTagName('textarea')[0].value;
qeTextArea.disabled = false;
qeDoc = qeDoc.getElementsByTagName('input');
var formData = '';
for(var i = 0; i < qeDoc.length; i++)
if(qeDoc[i].name.indexOf('addbbcode') == -1 && qeDoc[i].name.indexOf('helpbox') == -1 && qeDoc[i].name != '')
if(qeDoc[i].type != 'checkbox' || qeDoc[i].checked != '')
formData += qeDoc[i].name + '=' + encodeFormData(qeDoc[i].value) + '&';
qeSubmit.setAttribute('formData', formData);
qeDoc = null;
} else {
qeTextArea.value = '\n\n\n\n\n\t\t\tGetting post contents failed, refresh the page and try again.';
}
},
false);
postBody.insertBefore(qeSubmit, postBody.firstChild);
postBody.insertBefore(qeTextArea, postBody.firstChild);
document.body.appendChild(qeIFrame);
} else {
var allElements = postBody.getElementsByTagName('*');
for(i = 0; i < allElements.length; i++)
if(allElements[i].style.display == 'none')
allElements[i].style.display = '';
else
allElements[i].style.display = 'none';
}
event.preventDefault();
};
var editPost = function(event) {
var editHREF = event.target.getAttribute('editHREF').split('?')[0];
var formData = event.target.getAttribute('formData');
var postContents = encodeFormData(event.target.previousSibling.value);
event.target.value = 'Submitting...'
GM_xmlhttpRequest({
method: 'POST',
url: editHREF,
data: formData + 'message=' + postContents,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
onload: function(responseDetails) {
window.location.reload(false);
}
});
};
var editLinks = document.evaluate("//a[contains(@href, 'posting.php?mode=editpost')]", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for(var i = 0; i < editLinks.snapshotLength; i++) {
//var qeLink = document.createElement('b');
//qeLink.setAttribute('title', "click to edit this post");
//qeLink.style.fontSize = "7pt";
//qeLink.style.cursor = 'pointer';
editLinks.snapshotItem(i).addEventListener('click', function(e) { addQuickEdit(e); e.preventDefault(); return false; }, true);
//qeLink.innerHTML = ' [ QE ]';
//editLinks.snapshotItem(i).parentNode.insertBefore(qeLink, editLinks.snapshotItem(i).nextSibling);
}
})();