eBay New Community Custom Buttons

By thorbenhauer Last update May 15, 2008 — Installed 226 times.

Add Syntax Highlighting (this will take a few seconds, probably freezing your browser while it works)

// eBay New Community Custom Buttons user script
// version 0.1.4
// 2008-05-14
// Copyright 2006-2008, thorbenhauer
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// -----------------------------------------------------------------------------
//
// Icon: Humility Icon Set
// by Andrew Fitzsimon and Chad 'gonZo' Rodrigue
// http://art.gnome.org/themes/icon/1136
// Released under the GPL license
//
// -----------------------------------------------------------------------------
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// -----------------------------------------------------------------------------
//
// ==UserScript==
// @name          eBay New Community Custom Buttons
// @namespace     http://userscripts.org/users/9022
// @description   http://userscripts.org/scripts/show/13648
// @include       http://community.ebay.de/forum/ebay/post!reply.jspa?*
// ==/UserScript==
//
// -----------------------------------------------------------------------------
(function () {

var anchor = document.evaluate("//div[@id = 'editor-panel-wrapper']", document,
    null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
anchor.addEventListener('DOMNodeInserted',
    function (event) {
        if (event.target.id == "mce_editor_0") {
            location.href = 'javascript:(' + encodeURI(uneval(function() {
                setTimeout("setEditorMode('text');",500);
                })) + ')();';
        }
        if (event.target.id == "wysiwyg-panel") {
            window.setTimeout(tweak, 500);
        }
    }, false);
   
function tweak() {

// Constants
const PNGS = new Array(
'data:image/png;base64,' +
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI' +
'WXMAAAsTAAALEwEAmpw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HPMF73w5UsCyCGQj0BeAHm0YYd0f/30+M9n' +
'XdtEBLU2+X86cXRr6V/Rkk9LyrbsXF6xShdDseRW5+1Ti6GF74+81/tG9t3f7h26+REWMWIAAAAA' +
'SUVORK5CYII=',

'data:image/png;base64,' +
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI' +
'WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1QgXEjEyYrEi9wAAAiJJREFUOMudkr1PU1EYxn/n3ksv' +
'1FuJLV+C4AchGI1lQCcIDiaG6MLE6uDirMAmfiwlxsF/gJHov2B0MiSaQEKaGLBBSmgUbVKk4IVb' +
'Ws55HaCFAmHwWc4Z3vM7z3OeozzPG+nv748BiAgiovb3lVUpZeXz66WZmdkp4CuHNTg4mJBTVRTR' +
'vqz9WtYvXzx/D8QPn3cABRB/+I7NoEBJC5aCSNil1q1hq1Ak7+8yNnTFejr+7O52ULAnJiaeAMky' +
'AIDs2l/GH/TS1RqlNmRhRGCfXigZLjaHAUgkEncaYtE3I6Njj4G5CiB+tZVA28ws/cGIIEjFptbC' +
'Utbly1yKdDrN7RvXBnp6eoaTyeQBoCHqMZvO7+U5IhFhYXUbURYbQSePuputaDQaqorQGPUwWnDs' +
'kxAHcreE1kvt2LatAZxyXWG3hqBoE7JDoBRGdjFSwoiGQ3GwDOCglJIqBw21HoWwTyr3FnQdHZFe' +
'zp+7juucYdfsoKWECJzd2gFqqmoEYPL7MDe7LhBra2G9uMan31Ok5r8RU53cahuiMXKZHe2Tya8C' +
'r44DupvaGWi+j9YaZVkMNN3DxA0/gxVS2QXmtz8TclwiLfV79R6NsLKR4UPmI0ZMpX+lLGxl4zh1' +
'NNV3YERYXk9z4k/8kctgi0JxeguLucWTHeSyOfxNH6VOAQgEG0EZUP0GMin8j5TneaN9fX2Nx+86' +
'Mrhvuazp6emc7/uv/wGevf+VIy0RVgAAAABJRU5ErkJggg==',

'data:image/png;base64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nGpEQtPHsXSo7W9NXvv/8w391oby6MBvL9V+RIpxMxM1k' +
'NCLRJGgCBG1oe9Sqldajcun87HefffS/bQToPXZKT1rpd3K57PF4hzmiIsrwXOdaZbvxe73ZuHR9' +
'5qsH+/V/AyFIUFKVf8baAAAAAElFTkSuQmCC',

'data:image/png;base64,' +
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBI' +
'WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1QcWDioBW4ci2wAAAW1JREFUOMvFk7uKIkEUhr8q69KC' +
'mqkgKhgIE+w7+EC+ho/gGwi+hdnGBhM6qYIoeIm6XeuywXTXtrPZbLA/HKjzU/+pcyv4R4jdbve+' +
'2WzeYozETwDEEELlxxDCJ1mey7thNpv9ZLlc/orfxGKxuCvnHAD9fp8YI8YYsizDWvtiX7nVaoVz' +
'Lsjn8xkAhsMhp9OJw+Hwpz4hktXhvQfAOYeqnPv9jhCCGCPT6TSJQgicz2eu1yt5npPnOUVRsF6v' +
'8d6jnHMRoNFoEGNkPB5jreXxeHA8HrndbunFr/DehxTgcrkwGo3Y7/eUkyDLMpRSKKVSSXXEGGUK' +
'0G63kVLS6/XodrsAdDqd15kLgZQSa22iUg+azSZFUdBqtV4E9XM1IWNMlYFQzrkAoLVGa51EdbEx' +
'BmstxphkJWTKQEr5V5O01klsrUVrnQLVMwBgu91+6yuowWDwPp/Pf1SdLxdHiLKG2jIlruInk8kH' +
'/x2/AVt+9U9omNQ7AAAAAElFTkSuQmCC',

'data:image/gif;base64,' +
'R0lGODlhEAAQAIABAAAAAP///yH5BAEAAAEALAAAAAAQABAAAAIgjI+py60AI2zR1HXvm0F3CYZI' +
'xm2AVSbkaYLOC8dyUwAAOw==',

'data:image/png;base64,' +
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QAAAAAAAD5Q7t/AAAACXBI' +
'WXMAAAsTAAALEw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BAA7';

const TITLES = new Array(
    'Click for emoticons',
    'Click for img tag',
    'Click for a tag',
    'Click for fixed width font',
    'Click for strike',
    'Decode selection',
    'Color selection',
    'Clear all'
);
const ALTS = new Array(
    'Click for emoticons',
    'Click for img tag',
    'Click for a tag',
    'Click for fixed width font',
    'Click for strike',
    'Decode selection',
    'Color selection',
    'Clear all'
);
const FUNC = new Array(
    showEmoticons,
    postImgTag,
    postATag,
    postFWFTag,
    postStrikeTag,
    decodeHTML,
    showColors,
    clearAll
);

// Custom Buttons
var tarea = document.getElementById("textEditor");
var textPanel = document.getElementById("text-panel-links");
var emoticonsDiv = initEmoticons();
var elem;
for (var i = 0; i < PNGS.length; i++) {
    if (i != 4) { // No Strike
        elem = createImg(PNGS[i], TITLES[i], ALTS[i], FUNC[i]);
        textPanel.appendChild(elem);
    }
}
textPanel.appendChild(emoticonsDiv);
var img = document.evaluate("//img[@title='Color selection']", document, null, 
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
var imgParent = img.parentNode;
var box = document.createElement("div");
box.style.display = "inline";
imgParent.replaceChild(box, img);
box.appendChild(img);
var colorDiv = initColors();
box.appendChild(colorDiv);

elem = document.evaluate("//img[@id='jive-img-quote']", document, null, 
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).parentNode;
elem.addEventListener("click",
    function(event) {
	    tarea.value = tarea.value.replace(/\{quote:title=/g,
	        "<span class=\"jive-quote-header\">");
	    tarea.value = tarea.value.replace(/\}\{quote\}/g,
	        "</span>");
    }, false
);

// Accesskey
tarea.setAttribute("accesskey", "i");
var form = document.evaluate("//form[@name='postform']", document, null, 
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
var newLabel = document.createElement("label");
newLabel.setAttribute("for", "textEditor");
newLabel.setAttribute("accesskey", "i");
form.appendChild(newLabel);

// Ctrl Enter Submits
var input = document.evaluate("//input[@id='postButton']", document, null, 
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);   
tarea.addEventListener("keydown",
    function(event) {
	    if (event.keyCode == 13 && event.ctrlKey) {
	        input.click();
	    }
    }, false
);

// Functions
function postFWFTag(event) {
    postTag('<span style="font:medium monospace;">', '</span>');
}

function postStrikeTag(event) {
    postTag('<span style="text-decoration:line-through">', '</span>');
    //postTag('<span class="line-through">', '</span>');
}

function postImgTag(event) {
    postTag('<img src="', '" alt="" />');
}

function postATag(event) {
    postTag('<a href="', '"></a>');
}

function postColorTag(event) {
    colorDiv.style.display = "none";
    postTag('<span style="color:' +
        event.target.style.background.replace(/\s/g, "") + ' !important">',
        '</span>');
}

function decodeHTML(event) {
    var strings = getStrings();
    strings[1] = strings[1].replace(/</g, "&lt;");
    strings[1] = strings[1].replace(/>/g, "&gt;");
    // strings[1] = strings[1].replace(/\"/g, "&quot;");
    //strings[1] = strings[1].replace(/\(/g, "&#x0028;");
    //strings[1] = strings[1].replace(/\)/g, "&#x0029;");
    tarea.value = strings[0] + strings[1] + strings[2];
    tarea.focus();
}

function clearAll(event) {
    tarea.value = "";
    tarea.focus();
}

function getStrings() {
    var selLength = tarea.textLength;
    var selStart = tarea.selectionStart;
    var selEnd = tarea.selectionEnd;
    if (selEnd == 1 || selEnd == 2) {
      selEnd = selLength;
    }
    var strings = new Array(3);
    strings[0] = tarea.value.substring(0, selStart);
    strings[1] = tarea.value.substring(selStart, selEnd)
    strings[2] = tarea.value.substring(selEnd, selLength);
    return strings;
}

function postTag(startTag, endTag) {
    var strings = getStrings();
    tarea.value = strings[0] + startTag + strings[1] + endTag + strings[2];
    tarea.focus();
}

function initColors() {
    var head = document.getElementsByTagName("head")[0];
    var style = document.createElement("style");
    style.innerHTML = "div#colorDiv {z-index:10; position:absolute; " +
        "display: inline;} " +
        "div.wrapper {width: 88px; clear: both;}" +
        "div.color {float: left; border: 1px solid #808080; height: 9px; " +
        "overflow: hidden; width: 9px; cursor: pointer;}";
    head.appendChild(style);
    var div = document.createElement("div");
    div.id = "colorDiv";
    div.style.display = "none";
    div.innerHTML =
        '<div class="wrapper">' +
        '<div class="color" style="background-color: #000000;"></div>' +
        '<div class="color" style="background-color: #993300;"></div>' +
        '<div class="color" style="background-color: #333300;"></div>' +
        '<div class="color" style="background-color: #003300;"></div>' +
        '<div class="color" style="background-color: #003366;"></div>' +
        '<div class="color" style="background-color: #000080;"></div>' +
        '<div class="color" style="background-color: #333399;"></div>' +
        '<div class="color" style="background-color: #333333;"></div>' +
        '</div><div class="wrapper">' +
        '<div class="color" style="background-color: #800000;"></div>' +
        '<div class="color" style="background-color: #FF6600;"></div>' +
        '<div class="color" style="background-color: #808000;"></div>' +
        '<div class="color" style="background-color: #008000;"></div>' +
        '<div class="color" style="background-color: #008080;"></div>' +
        '<div class="color" style="background-color: #0000FF;"></div>' +
        '<div class="color" style="background-color: #666699;"></div>' +
        '<div class="color" style="background-color: #808080;"></div>' +
        '</div><div class="wrapper">' +
        '<div class="color" style="background-color: #FF0000;"></div>' +
        '<div class="color" style="background-color: #FF9900;"></div>' +
        '<div class="color" style="background-color: #99CC00;"></div>' +
        '<div class="color" style="background-color: #339966;"></div>' +
        '<div class="color" style="background-color: #33CCCC;"></div>' +
        '<div class="color" style="background-color: #3366FF;"></div>' +
        '<div class="color" style="background-color: #800080;"></div>' +
        '<div class="color" style="background-color: #999999;"></div>' +
        '</div><div class="wrapper">' +
        '<div class="color" style="background-color: #FF00FF;"></div>' +
        '<div class="color" style="background-color: #FFCC00;"></div>' +
        '<div class="color" style="background-color: #FFFF00;"></div>' +
        '<div class="color" style="background-color: #00FF00;"></div>' +
        '<div class="color" style="background-color: #00FFFF;"></div>' +
        '<div class="color" style="background-color: #00CCFF;"></div>' +
        '<div class="color" style="background-color: #993366;"></div>' +
        '<div class="color" style="background-color: #C0C0C0;"></div>' +
        '</div><div class="wrapper">' +
        '<div class="color" style="background-color: #FF99CC;"></div>' +
        '<div class="color" style="background-color: #FFCC99;"></div>' +
        '<div class="color" style="background-color: #FFFF99;"></div>' +
        '<div class="color" style="background-color: #CCFFCC;"></div>' +
        '<div class="color" style="background-color: #CCFFFF;"></div>' +
        '<div class="color" style="background-color: #99CCFF;"></div>' +
        '<div class="color" style="background-color: #CC99FF;"></div>' +
        '<div class="color" style="background-color: #FFFFFF;"></div>' +
        '</div>';
    var divs = document.evaluate(".//div[@class='color']", div, null, 
        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    for (var i = 0; i < divs.snapshotLength; i++) {
        divs.snapshotItem(i).addEventListener('click', postColorTag, false);
    }
    return div;
}   

function initEmoticons() {
    var iconDiv = document.createElement("div");
    iconDiv.style.display = "none";
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/happy.gif",
        "happy", ":-)", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/sad.gif",
        "sad", ":-(", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/grin.gif",
        "grin", ":D", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/love.gif",
        "love", ":x", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/cool.gif",
        "cool", "B-)", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/devil.gif",
        "devil", "]:)", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/silly.gif",
        "silly", ":p", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/angry.gif",
        "angry", "X-(", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/laugh.gif",
        "laugh", ":^0", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/wink.gif",
        "wink", ";-)", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/blush.gif",
        "blush", ":8}", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/cry.gif",
        "cry", ":_|", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/confused.gif",
        "confused", "?:|", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/shocked.gif",
        "shocked", ":0", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/plain.gif",
        "plain", ":|", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/mischief.gif",
        "mischief", ";\\", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/info.gif",
        "info", " (i) ", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/alert.gif",
        "alert", " (!) ", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/plus.gif",
        "plus", " (+) ", postEmoticons));
    iconDiv.appendChild(createImg("/forum/static/gfx/forum/emoticons/minus.gif",
        "minus", " (-) ", postEmoticons));
    iconDiv.appendChild(createImg(CLOSEGIF, "close", "close",
        closeEmoticons));
    return iconDiv;
}

function createImg(URL, title, alt, func) {
    var img =  document.createElement("img");
    img.src = URL;
    img.title = title;
    img.alt = alt;
    img.setAttribute("style", "border: 0px; cursor: pointer; " +
        "margin: 0px 5px 3px;" );
    img.addEventListener('click', func, false);
    return img;
}

function postEmoticons(event) {
    var strings = getStrings();
    tarea.value = strings[0] + event.target.alt + strings[2];
    emoticonsDiv.style.display = "none";
    tarea.focus();
}

function closeEmoticons(event) {
    emoticonsDiv.style.display = "none";
    tarea.focus();
}

function showEmoticons(event) {
    emoticonsDiv.style.display = "";
    tarea.focus();
}

function showColors(event) {
    if (colorDiv.style.display == "") {
        colorDiv.style.display = "none";
    } else {
        colorDiv.style.display = "";
    }
    tarea.focus();
}

}

})();