// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: 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 "Myspace formatting shortcuts", and click Uninstall.
//
// --------------------------------------------------------------------
//
// Myspace formatting shortcuts
// By Jonatron - sjhu52i02@sneakemail.com - http://www.myspace.com/negatron
// Heavily based on Tim Babych's "Ctrl+Enter Submits" 0.3
// version 0.005
// 2005-11-30
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// Instructions: http://userscripts.org/scripts/show/780
//
// Summary: Type special things like **bold text** or <3 hearts,
// press Ctrl+Enter, and they will be converted into HTML and submitted.
//
// This a very hackish hack of another person's script, and I really
// don't know what I'm doing. This is my first ever use of regular
// expressions. If you know how to fix a bug, let me know.
//
// This could very easily be modified for other sites that allow HTML
// input in comments and such (livejournal, fark). Only a few of the tags
// are really exclusive to myspace, though some of the bug fixing things
// should be removed first.
//
// I am not a coder; I am just fed up with myspace's crappy functionality.
//
// You should copy your submission to the clipboard before you push
// Ctrl+Enter, because it modifies the text right there, and if you
// try to come back and edit it again before submission, you are stuck
// with the post-conversion text. This should be coded around but I
// have no idea how.
//
// Future:
//
// All of these can be more robust.
//
// It should be able to parse links with and without the http://, and
// add it when necessary.
//
// It should be able to do bulleted and ordered lists, a la Wikipedia:
// * Item
// * Second item
//
// or
//
// # Item
// # second item
//
// It would be nice if we could get around myspace's forbidden
// characters, like # or \, but I don't know how.
//
// Need to fix the thing in which tables create huge chunks of empty space above them
// in other words, the newlines between > and < in HTML tags need to be removed before submit
//
// ==UserScript==
// @name Myspace formatting shortcuts
// @namespace http://mysite.verizon.net/negatron/
// @description Adds wiki-like formatting for myspace (and other sites that accept HTML) and Ctrl+Enter submitting in any textarea input
// @include http://*.myspace.com/*
// ==/UserScript==
function myspacefmt(text) {
s = text
// Turn special characters back into HTML entities so they don't get stripped
// List is from the tables at http://www.htmlhelp.com/reference/html40/entities/
s = s.replace(/\uA0/g, ' ');
s = s.replace(/\uA1/g, '¡');
s = s.replace(/\uA2/g, '¢');
s = s.replace(/\uA3/g, '£');
s = s.replace(/\uA4/g, '¤');
s = s.replace(/\uA5/g, '¥');
s = s.replace(/\uA6/g, '¦');
s = s.replace(/\uA7/g, '§');
s = s.replace(/\uA8/g, '¨');
s = s.replace(/\uA9/g, '©');
s = s.replace(/\uAA/g, 'ª');
s = s.replace(/\uAB/g, '«');
s = s.replace(/\uAC/g, '¬');
s = s.replace(/\uAD/g, '­');
s = s.replace(/\uAE/g, '®');
s = s.replace(/\uAF/g, '¯');
s = s.replace(/\uB0/g, '°');
s = s.replace(/\uB1/g, '±');
s = s.replace(/\uB2/g, '²');
s = s.replace(/\uB3/g, '³');
s = s.replace(/\uB4/g, '´');
s = s.replace(/\uB5/g, 'µ');
s = s.replace(/\uB6/g, '¶');
s = s.replace(/\uB7/g, '·');
s = s.replace(/\uB8/g, '¸');
s = s.replace(/\uB9/g, '¹');
s = s.replace(/\uBA/g, 'º');
s = s.replace(/\uBB/g, '»');
s = s.replace(/\uBC/g, '¼');
s = s.replace(/\uBD/g, '½');
s = s.replace(/\uBE/g, '¾');
s = s.replace(/\uBF/g, '¿');
s = s.replace(/\uC0/g, 'À');
s = s.replace(/\uC1/g, 'Á');
s = s.replace(/\uC2/g, 'Â');
s = s.replace(/\uC3/g, 'Ã');
s = s.replace(/\uC4/g, 'Ä');
s = s.replace(/\uC5/g, 'Å');
s = s.replace(/\uC6/g, 'Æ');
s = s.replace(/\uC7/g, 'Ç');
s = s.replace(/\uC8/g, 'È');
s = s.replace(/\uC9/g, 'É');
s = s.replace(/\uCA/g, 'Ê');
s = s.replace(/\uCB/g, 'Ë');
s = s.replace(/\uCC/g, 'Ì');
s = s.replace(/\uCD/g, 'Í');
s = s.replace(/\uCE/g, 'Î');
s = s.replace(/\uCF/g, 'Ï');
s = s.replace(/\uD0/g, 'Ð');
s = s.replace(/\uD1/g, 'Ñ');
s = s.replace(/\uD2/g, 'Ò');
s = s.replace(/\uD3/g, 'Ó');
s = s.replace(/\uD4/g, 'Ô');
s = s.replace(/\uD5/g, 'Õ');
s = s.replace(/\uD6/g, 'Ö');
s = s.replace(/\uD7/g, '×');
s = s.replace(/\uD8/g, 'Ø');
s = s.replace(/\uD9/g, 'Ù');
s = s.replace(/\uDA/g, 'Ú');
s = s.replace(/\uDB/g, 'Û');
s = s.replace(/\uDC/g, 'Ü');
s = s.replace(/\uDD/g, 'Ý');
s = s.replace(/\uDE/g, 'Þ');
s = s.replace(/\uDF/g, 'ß');
s = s.replace(/\uE0/g, 'à');
s = s.replace(/\uE1/g, 'á');
s = s.replace(/\uE2/g, 'â');
s = s.replace(/\uE3/g, 'ã');
s = s.replace(/\uE4/g, 'ä');
s = s.replace(/\uE5/g, 'å');
s = s.replace(/\uE6/g, 'æ');
s = s.replace(/\uE7/g, 'ç');
s = s.replace(/\uE8/g, 'è');
s = s.replace(/\uE9/g, 'é');
s = s.replace(/\uEA/g, 'ê');
s = s.replace(/\uEB/g, 'ë');
s = s.replace(/\uEC/g, 'ì');
s = s.replace(/\uED/g, 'í');
s = s.replace(/\uEE/g, 'î');
s = s.replace(/\uEF/g, 'ï');
s = s.replace(/\uF0/g, 'ð');
s = s.replace(/\uF1/g, 'ñ');
s = s.replace(/\uF2/g, 'ò');
s = s.replace(/\uF3/g, 'ó');
s = s.replace(/\uF4/g, 'ô');
s = s.replace(/\uF5/g, 'õ');
s = s.replace(/\uF6/g, 'ö');
s = s.replace(/\uF7/g, '÷');
s = s.replace(/\uF8/g, 'ø');
s = s.replace(/\uF9/g, 'ù');
s = s.replace(/\uFA/g, 'ú');
s = s.replace(/\uFB/g, 'û');
s = s.replace(/\uFC/g, 'ü');
s = s.replace(/\uFD/g, 'ý');
s = s.replace(/\uFE/g, 'þ');
s = s.replace(/\uFF/g, 'ÿ');
s = s.replace(/\u192/g, 'ƒ');
s = s.replace(/\u391/g, 'Α');
s = s.replace(/\u392/g, 'Β');
s = s.replace(/\u393/g, 'Γ');
s = s.replace(/\u394/g, 'Δ');
s = s.replace(/\u395/g, 'Ε');
s = s.replace(/\u396/g, 'Ζ');
s = s.replace(/\u397/g, 'Η');
s = s.replace(/\u398/g, 'Θ');
s = s.replace(/\u399/g, 'Ι');
s = s.replace(/\u39A/g, 'Κ');
s = s.replace(/\u39B/g, 'Λ');
s = s.replace(/\u39C/g, 'Μ');
s = s.replace(/\u39D/g, 'Ν');
s = s.replace(/\u39E/g, 'Ξ');
s = s.replace(/\u39F/g, 'Ο');
s = s.replace(/\u3A0/g, 'Π');
s = s.replace(/\u3A1/g, 'Ρ');
s = s.replace(/\u3A3/g, 'Σ');
s = s.replace(/\u3A4/g, 'Τ');
s = s.replace(/\u3A5/g, 'Υ');
s = s.replace(/\u3A6/g, 'Φ');
s = s.replace(/\u3A7/g, 'Χ');
s = s.replace(/\u3A8/g, 'Ψ');
s = s.replace(/\u3A9/g, 'Ω');
s = s.replace(/\u3B1/g, 'α');
s = s.replace(/\u3B2/g, 'β');
s = s.replace(/\u3B3/g, 'γ');
s = s.replace(/\u3B4/g, 'δ');
s = s.replace(/\u3B5/g, 'ε');
s = s.replace(/\u3B6/g, 'ζ');
s = s.replace(/\u3B7/g, 'η');
s = s.replace(/\u3B8/g, 'θ');
s = s.replace(/\u3B9/g, 'ι');
s = s.replace(/\u3BA/g, 'κ');
s = s.replace(/\u3BB/g, 'λ');
s = s.replace(/\u3BC/g, 'μ');
s = s.replace(/\u3BD/g, 'ν');
s = s.replace(/\u3BE/g, 'ξ');
s = s.replace(/\u3BF/g, 'ο');
s = s.replace(/\u3C0/g, 'π');
s = s.replace(/\u3C1/g, 'ρ');
s = s.replace(/\u3C2/g, 'ς');
s = s.replace(/\u3C3/g, 'σ');
s = s.replace(/\u3C4/g, 'τ');
s = s.replace(/\u3C5/g, 'υ');
s = s.replace(/\u3C6/g, 'φ');
s = s.replace(/\u3C7/g, 'χ');
s = s.replace(/\u3C8/g, 'ψ');
s = s.replace(/\u3C9/g, 'ω');
s = s.replace(/\u3D1/g, 'ϑ');
s = s.replace(/\u3D2/g, 'ϒ');
s = s.replace(/\u3D6/g, 'ϖ');
s = s.replace(/\u2022/g, '•');
s = s.replace(/\u2026/g, '…');
s = s.replace(/\u2032/g, '′');
s = s.replace(/\u2033/g, '″');
s = s.replace(/\u203E/g, '‾');
s = s.replace(/\u2044/g, '⁄');
s = s.replace(/\u2118/g, '℘');
s = s.replace(/\u2111/g, 'ℑ');
s = s.replace(/\u211C/g, 'ℜ');
s = s.replace(/\u2122/g, '™');
s = s.replace(/\u2135/g, 'ℵ');
s = s.replace(/\u2190/g, '←');
s = s.replace(/\u2191/g, '↑');
s = s.replace(/\u2192/g, '→');
s = s.replace(/\u2193/g, '↓');
s = s.replace(/\u2194/g, '↔');
s = s.replace(/\u21B5/g, '↵');
s = s.replace(/\u21D0/g, '⇐');
s = s.replace(/\u21D1/g, '⇑');
s = s.replace(/\u21D2/g, '⇒');
s = s.replace(/\u21D3/g, '⇓');
s = s.replace(/\u21D4/g, '⇔');
s = s.replace(/\u2200/g, '∀');
s = s.replace(/\u2202/g, '∂');
s = s.replace(/\u2203/g, '∃');
s = s.replace(/\u2205/g, '∅');
s = s.replace(/\u2207/g, '∇');
s = s.replace(/\u2208/g, '∈');
s = s.replace(/\u2209/g, '∉');
s = s.replace(/\u220B/g, '∋');
s = s.replace(/\u220F/g, '∏');
s = s.replace(/\u2211/g, '∑');
s = s.replace(/\u2212/g, '−');
s = s.replace(/\u2217/g, '∗');
s = s.replace(/\u221A/g, '√');
s = s.replace(/\u221D/g, '∝');
s = s.replace(/\u221E/g, '∞');
s = s.replace(/\u2220/g, '∠');
s = s.replace(/\u2227/g, '∧');
s = s.replace(/\u2228/g, '∨');
s = s.replace(/\u2229/g, '∩');
s = s.replace(/\u222A/g, '∪');
s = s.replace(/\u222B/g, '∫');
s = s.replace(/\u2234/g, '∴');
s = s.replace(/\u223C/g, '∼');
s = s.replace(/\u2245/g, '≅');
s = s.replace(/\u2248/g, '≈');
s = s.replace(/\u2260/g, '≠');
s = s.replace(/\u2261/g, '≡');
s = s.replace(/\u2264/g, '≤');
s = s.replace(/\u2265/g, '≥');
s = s.replace(/\u2282/g, '⊂');
s = s.replace(/\u2283/g, '⊃');
s = s.replace(/\u2284/g, '⊄');
s = s.replace(/\u2286/g, '⊆');
s = s.replace(/\u2287/g, '⊇');
s = s.replace(/\u2295/g, '⊕');
s = s.replace(/\u2297/g, '⊗');
s = s.replace(/\u22A5/g, '⊥');
s = s.replace(/\u22C5/g, '⋅');
s = s.replace(/\u2308/g, '⌈');
s = s.replace(/\u2309/g, '⌉');
s = s.replace(/\u230A/g, '⌊');
s = s.replace(/\u230B/g, '⌋');
s = s.replace(/\u2329/g, '⟨');
s = s.replace(/\u232A/g, '⟩');
s = s.replace(/\u25CA/g, '◊');
s = s.replace(/\u2660/g, '♠');
s = s.replace(/\u2663/g, '♣');
s = s.replace(/\u2665/g, '♥');
s = s.replace(/\u2666/g, '♦');
s = s.replace(/\u152/g, 'Œ');
s = s.replace(/\u153/g, 'œ');
s = s.replace(/\u160/g, 'Š');
s = s.replace(/\u161/g, 'š');
s = s.replace(/\u178/g, 'Ÿ');
s = s.replace(/\u2C6/g, 'ˆ');
s = s.replace(/\u2DC/g, '˜');
s = s.replace(/\u2002/g, ' ');
s = s.replace(/\u2003/g, ' ');
s = s.replace(/\u2009/g, ' ');
// Blanking these four because they screw things up:
s = s.replace(/\u200C/g, ' ');
s = s.replace(/\u200D/g, ' ');
s = s.replace(/\u200E/g, ' ');
s = s.replace(/\u200F/g, ' ');
s = s.replace(/\u2020/g, '†');
s = s.replace(/\u2021/g, '‡');
s = s.replace(/\u2030/g, '‰');
s = s.replace(/\u2039/g, '‹');
s = s.replace(/\u203A/g, '›');
s = s.replace(/\u20AC/g, '€');
replacements = [
// [//g, ''],
// Cyrillic quotes
// [/(\s+|^)"([^"]+?)"(\s+|$|\.|\,)/g, '$1\u00ab$2\u00bb$3'],
// Latin quotes: "test" become smart quotes
[/(\s+|^)"([^\"]+?)"(\s+|$|\.|\,)/g, '$1“$2”$3'],
[/(\s+|^)'([^\']+?)'(\s+|$|\.|\,)/g, '$1‘$2’$3'],
// Trademark: (TM)
[/\((tm|TM|\u0422\u041C|\u0442\u043C)\)/g, '™'],
// Copyright: (C)
[/\([cC\u0421\u0441]\)/g, '©'],
// Registered: (R)
[/\([rR\u0420\u0440]\)/g, '®'],
// Hearts, of course! <3
[/(\s)(<3)(\s)/g, '$1\♥$3'],
// Section symbol, by request: {SS}
[/\{SS\}/g, '§'],
// Arrows ==> <-- <==> and so on
[/([^<])-{2}>/g, '$1→'],
[/<-{2}([^>])/g, '←$1'],
[/<-{1,2}>/g, '↔'],
[/([^<])={2}>/g, '$1⇒'],
[/<={2}([^>])/g, '⇐$1'],
[/<={1,2}>/g, '⇔'],
// Horizontal rules: ---- becomes <hr>
[/\n----+\n/g, '<hr>'],
// Degree sign: degC becomes °C (K does not have a degree sign!)
[/degC(\s)/g, '°C$1'],
[/degF(\s)/g, '°F$1'],
// TeX subs and supers: x squared: x^{2} carbon dioxide: CO_{2}
[/\^\{(.*?)\}/g, '<sup>$1</sup>'],
[/_\{(.*?)\}/g, '<sub>$1</sub>'],
// Scientific notation: 3.5E2 becomes 3.5×10<sup>2</sup>
[/(\d)E(\d+)/g, '$1×10<sup>$2</sup>'],
// Plus or minus sign +-5 becomes ±5
[/\+-(\d)/g, '±$1'],
// Censorship is evil.
// [/A(IM\s*)\:/gi, 'Â$1:'],
// These screw up your posts if you've got 'em (Myspace sucks). It converts to something similar looking. :-\ Best I can do...
// [/\#/gi, '‡‡'],
[/\\/gi, '⌊'],
// Em dash -- two minuses surrounded by spaces
[/(\s+|^)--(\s+)/g, '$1\u2014$2'],
// **bold**
[/\*{2}(.+?)\*{2}/g, '<b>$1</b>'],
// '''Wikipedia strong emphasis''' (rendered as bold usually)
[/\'{3}(.+?)\'{3}/g, '<strong>$1</strong>'],
// //italic//
[/([^\:]|^)\/{2}(.+?)\/{2}/g, '$1<i>$2</i>'],
// ''Wikipedia emphasis'' (rendered as italics usually)
[/\'{2}(.+?)\'{2}/g, '<em>$1</em>'],
// --strikethrough--
[/-{2}(.+?)-{2}/g, '<s>$1</s>'],
// __underlined__
[/_{2}(.+?)_{2}/g, '<u>$1</u>'],
// A few colors? [blue]text[/color] becomes <font color="0000BB">text</font> (will also accept [bl]text[/bl] or whatever)
[/\[(bk|k|black)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="black">$2</font>'],
[/\[(n|navy)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="navy">$2</font>'],
[/\[(gn|green)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="green">$2</font>'],
[/\[(tl|teal)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="teal">$2</font>'], // [t] would conflict with quote tags
[/\[(s|silver)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="silver">$2</font>'],
[/\[(bl|be|bu|blue)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="blue">$2</font>'],
[/\[(l|lime)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="lime">$2</font>'],
[/\[(a|aq|aqua|c|cy|cyan)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="aqua">$2</font>'],
[/\[(m|maroon)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="maroon">$2</font>'],
[/\[(p|purple|v|violet)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="purple">$2</font>'],
[/\[(o|olive)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="olive">$2</font>'],
[/\[(gy|gray|grey)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="gray">$2</font>'],
[/\[(r|red)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="red">$2</font>'],
[/\[(f|fuschia|magenta)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="fuschia">$2</font>'],
[/\[(y|yw|yellow)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="yellow">$2</font>'],
[/\[(w|wh|white)\]([\s\S]*?)\[\/(\1|c|color)?\]/gim, '<font color="white">$2</font>'],
// En dash for number ranges: 1995-2005
[/(\d+)-(\d+)/g, '$1\u2013$2'],
// Ellipsis
// [/\.\.\./g, '\u2026'],
// [quote] tags [/quote] (or [q] or [Q] or [t] or whatever)
// First replace the SomeoneWrote: bit with legend tags
[/\[(quote|q|t)\](\s*\n?)([^\n]*)Wrote:(\s*\n)([\s\S]*?)\[\/(quote|q|t)\]/gim, '[$1]<legend>$3 wrote:</legend>$5[/$6]'],
// Then replace the rest with fieldset tags
[/\[(quote|q|t)\]([\s\S]*?)\[\/(quote|q|t)\]/gim, '<fieldset style="border: 1px solid; border-color: aaaaaa; padding: 1em; margin: 1em 2em;">$2</fieldset>'],
// (This way it can handle nested quotes and optional "Wrote:" sections.)
// Old version of quotes based directly on Myspace's quote markup:
// [/\[(quote|q|t)\]([\s\S]*?)\[\/(quote|q|t)\]/gim, '<table align="center" bgcolor="cccccc" border="0" cellpadding="1" cellspacing="0" width="90%"><tbody><tr><td><table bgcolor="ffffff" border="0" cellpadding="10" cellspacing="0" width="100%"><tbody><tr><td><p>$2</p></td></tr></tbody></table></td></tr></tbody></table>'],
// Image shortcut IMG=http://www.url.com/image.png surrounded by whitespace.
[/(\s)IMG=(\S*?)([\s\]])/gi, '$1<img src="$2">$3'],
// Named URLs in wikipedia format [http://address linked text]
[/\[http:([^ \t\v\f\n\r\]]*?)\s+(\S.*?)\]/gi, '<a href="http:$1">$2</a>'],
// Myspace URLs [my:Firefox] or [myspace:Firefox] becomes http://www.myspace.com/Firefox
[/\[(my|myspace):(\S.*?)\]/gi, '<a href="http://www.myspace.com/$2">Myspace: $2</a>'],
// Myspace group URLs [gr:toolbar] or [group:toolbar] becomes http://groups.myspace.com/toolbar
[/\[(gr|group):(\S.*?)\]/gi, '<a href="http://groups.myspace.com/$2">Myspace group: $2</a>'],
// Auto-link naked URLs
[/(\s)http(s)*:(\S*?)(\s)/gi, '$1<a href="http$2:$3">http$2:$3</a>$4'],
// Links to wikipedia articles [[linked text]] (useful in fights)
[/\[\[([\s\S]+?)\]\]/gi, '<a href="http://en.wikipedia.org/wiki/$1">$1</a>']
];
// Runs through itself over and over until nothing changes, to handle nested quote tags and the like.
// Uses "for" instead of "while" to prevent infinite loops from poorly written regexps. ;-)
for( j=0; j<=100; j++) {
olds = s;
for( i=0; i < replacements.length; i++) {
s = s.replace(replacements[i][0], replacements[i][1]);
}
if(olds == s) {break};
}
return s
}
function trigger_submit_on_ctrl_enter(e) {
if ((e.keyCode==13) && (e.ctrlKey)) {
p = this.parentNode
i = 0
if (this.nodeName == 'TEXTAREA')
this.value = myspacefmt(this.value)
while (p.nodeName != 'FORM' && i++ < 100)
p = p.parentNode
if (p.nodeName == 'FORM')
p.submit()
}
}
allInps = document.evaluate("//textarea | //select | //unput", document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < allInps.snapshotLength; i++) {
t = allInps.snapshotItem(i);
t.addEventListener("keydown", trigger_submit_on_ctrl_enter, 0);
}