var simplifyChars = true; // Change to false if you don't want stylized quotation marks, ellipses, etc. to be replaced var stripEmail = false; // Remove auto-filled email from submission
// End User Options
/* ! http://mths.be/fromcodepoint v0.1.0 by @mathias */ if (!String.fromCodePoint) { (function() { var defineProperty = (function() { try { var object = {}; var $defineProperty = Object.defineProperty; var result = $defineProperty(object, object, object) && $defineProperty; } catch(error) {} return result; }()); var stringFromCharCode = String.fromCharCode; var floor = Math.floor; var fromCodePoint = function() { var MAX_SIZE = 0x4000; var codeUnits = []; var highSurrogate; var lowSurrogate; var index = -1; var length = arguments.length; if (!length) { return ''; } var result = ''; while (++index < length) { var codePoint = Number(arguments[index]); if ( !isFinite(codePoint) || codePoint < 0 || codePoint > 0x10FFFF || floor(codePoint) != codePoint ) { throw RangeError('Invalid code point: ' + codePoint); } if (codePoint <= 0xFFFF) { codeUnits.push(codePoint); } else { codePoint -= 0x10000; highSurrogate = (codePoint >> 10) + 0xD800; lowSurrogate = (codePoint % 0x400) + 0xDC00; codeUnits.push(highSurrogate, lowSurrogate); } if (index + 1 == length || codeUnits.length > MAX_SIZE) { result += stringFromCharCode.apply(null, codeUnits); codeUnits.length = 0; } } return result; }; if (defineProperty) { defineProperty(String, 'fromCodePoint', { 'value': fromCodePoint, 'configurable': true, 'writable': true }); } else { String.fromCodePoint = fromCodePoint; } }()); }
// Add "Quote This" buttons to all initially visible comments
var spans = document.getElementsByTagName("span"); for (var x=0; x<spans.length; x++) { if (spans[x].id.indexOf("reply_link_")==0) { var button = document.createElement("span"); button.setAttribute("class","nbutton"); var p = document.createElement("p"); var b = document.createElement("b"); var a = document.createElement("a"); // Set the href of the "Quote This" button to the href of the "Reply to This" button, with the escaped contents of the post added to URL and any [domain.names] following links in the post cut out: a.setAttribute("href",spans[x].getElementsByTagName("a")[0].href.replace("#post_comment","&postercomment="+escape("<blockquote>"+document.getElementById("comment_body_"+spans[x].id.replace("reply_link_","")).innerHTML.replace(/<\/a>\s\[.*?\..*?\]/g,"<\/a>")+"<\/blockquote>\n\n")+"#post_comment")); // To Do: Shorten URLs longer than 2000 characters a.appendChild(document.createTextNode("Quote This")); b.appendChild(a); p.appendChild(b); button.appendChild(p); spans[x].parentNode.insertBefore(button, spans[x].nextSibling); spans[x].parentNode.insertBefore(document.createTextNode(" "), spans[x].nextSibling); // Divider } }
if (stripEmail && window.location.href.search(/http(s)?\:\/\/soylentnews\.org\/submit\.pl/)!=-1) // Empty email input area, but only on submission page { var boxes = document.getElementsByTagName("input"); for (var x=0; x<boxes.length; x++) { if (boxes[x].name == "email") { boxes[x].value = ""; } } }
// Add title case button next to title/subj field on Story Submissions, Submission Preview, and Story Preview if (window.location.href.search(/http(s)?\:\/\/soylentnews\.org\/(submit|admin)\.pl/)!=-1) { var boxes = document.getElementsByTagName("input"); for (var x=0; x<boxes.length; x++) { if (boxes[x].name == "title" || boxes[x].name == "subj") { boxes[x].id = "storyTitle"; var button = document.createElement("input"); button.setAttribute("type","button"); button.setAttribute("value","Title Case"); button.setAttribute("title","Convert title to title case."); button.setAttribute("onclick","document.getElementById('storyTitle').value=document.getElementById('storyTitle').value.replace(/\\b([a-z])/gi,function(m, p1){return p1.toUpperCase();}).replace(/\\b(at|of|is|and|to|in|by|as|its|be|the|on|a|an|but|or|for)\\b/gi,function(m, p1){return p1.toLowerCase();}).replace(/^([a-z])/gi,function(m, p1){return p1.toUpperCase();}).replace(/:\\s([a-z])/gi,function(m, p1){return ': '+p1.toUpperCase();}).replace(/\\bx(86|64)\\b/gi,'x$1');"); boxes[x].parentNode.insertBefore(button, boxes[x].nextSibling); if (window.location.href.search(/http(s)?\:\/\/soylentnews\.org\/admin\.pl/)!=-1 || boxes[x].name == "subj") { boxes[x].parentNode.insertBefore(document.createElement("br"), boxes[x].nextSibling); } else { boxes[x].parentNode.insertBefore(document.createTextNode(" "), boxes[x].nextSibling); } } } }
var boxes = document.getElementsByTagName("textarea"); for (var x=0; x<boxes.length; x++) { if (boxes[x].name == "introtext" || boxes[x].name == "bodytext" || boxes[x].name == "story") { var temp = boxes[x].value; // Retrieve textarea contents temp = temp.replace(/<\/p><p>/g,"<\/p>\n\n<p>"); // Add newlines between paragraphs temp = temp.replace(/<br>\s?<br>/g,"<\/p>\n\n<p>"); // Convert double break tags to paragraph tags temp = temp.replace(/<\/blockquote><p>/g,"<\/blockquote>\n\n<p>"); // Add newlines after blockquotes temp = temp.replace(/<\/p><blockquote>/g,"<\/p>\n\n<blockquote>"); // Add newlines before blockquotes temp = temp.replace(/<blockquote><div><p>/g,"<blockquote><div>\n\n<p>"); // Add newlines within start of blockquotes temp = temp.replace(/<\/p><\/div><\/blockquote>/g,"<\/p>\n\n<\/div><\/blockquote>"); // Add newlines within end of blockquotes temp = temp.replace(/<\/blockquote><blockquote>/g,"<\/blockquote>\n\n<blockquote>"); // Add newlines between two blockquotes temp = temp.replace(/<p class="byline">\s/i,"<p class=\"byline\">"); // Remove extra space from byline temp = temp.replace(/<p>\s/g,"<p>"); // Remove extra space from start of paragraph temp = temp.replace(/\s<\/p>/g,"<\/p>"); // Remove extra space from end of paragraph temp = temp.replace(/<\/li><li>/g,"<\/li>\n<li>"); // Add newlines between list items temp = temp.replace(/<\/li><\/ul>/g,"<\/li>\n(<\/ul>|<\/ol>)"); // Add newline after last list item temp = temp.replace(/<\/p><ul>/g,"<\/p>\n\n(<ul>|<ol>)"); // Add newlines before lists temp = temp.replace(/<p>\[...\]/g,"<p>[...] "); // Add space within beginning of foreshortened paragraph while (temp.indexOf(" ")!=-1) { temp = temp.replace(/ /g," "); // Replace double spaces with single spaces } if (simplifyChars) { temp = temp.replace(/\u2018/g,"'"); // 'LEFT SINGLE QUOTATION MARK' (U+2018) to (U+0027) temp = temp.replace(/\u2019/g,"'"); // 'RIGHT SINGLE QUOTATION MARK' (U+2019) to (U+0027) temp = temp.replace(/\u201C/g,"\""); // 'LEFT DOUBLE QUOTATION MARK' (U+201C) to (U+0022) temp = temp.replace(/\u201D/g,"\""); // 'RIGHT DOUBLE QUOTATION MARK' (U+201D) to (U+0022) temp = temp.replace(/\u2026/g,"..."); // 'HORIZONTAL ELLIPSIS' (U+2026) to (U+002E) x3 } boxes[x].value = temp; boxes[x].rows = 32; // Expand textarea height to 32 rows } var toolbar = document.createElement("div");
// Blockquote button var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","Blockquote"); tempbutton.setAttribute("title","Wrap \u003Cblockquote\u003E tags around the selected text."); tempbutton.setAttribute("onclick","addBlockquote(document.getElementsByTagName('textarea')["+x+"]);"); toolbar.appendChild(tempbutton);
// Paragraph and Line break buttons var tempspan = document.createElement("span"); tempspan.setAttribute("id","htmlFormatButtons"); if (document.getElementById("posttype") && document.getElementById("posttype").selectedIndex == 0) { tempspan.setAttribute("style","display:none;"); // Hide if initial post type option is "Plain Old Text" } if (document.getElementById("posttype")) { document.getElementById("posttype").addEventListener("change", function() {if (document.getElementById('posttype').selectedIndex == 0) {document.getElementById('htmlFormatButtons').style.display = 'none'} else {document.getElementById('htmlFormatButtons').style.display = 'inline'}}); // Change visibility of these buttons based on value of post type } var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","P"); tempbutton.setAttribute("title","Wrap \u003Cp\u003E tags around the selected text."); tempbutton.setAttribute("onclick","addPara(document.getElementsByTagName('textarea')["+x+"]);"); tempspan.appendChild(tempbutton); var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","BR"); tempbutton.setAttribute("title","Insert a line break."); tempbutton.setAttribute("onclick","addBreak(document.getElementsByTagName('textarea')["+x+"]);"); tempspan.appendChild(tempbutton); toolbar.appendChild(tempspan);
// HR button, if editing a story if (boxes[x].name == "introtext" || boxes[x].name == "bodytext" || boxes[x].name == "story") { var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","HR"); tempbutton.setAttribute("title","Insert a horizontal rule."); tempbutton.setAttribute("style","text-decoration:underline overline;"); tempbutton.setAttribute("onclick","addHRule(document.getElementsByTagName('textarea')["+x+"]);"); tempspan.appendChild(tempbutton); toolbar.appendChild(tempspan); }
// URL button var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","URL"); tempbutton.setAttribute("title","Create a hyperlink around the selected text."); tempbutton.setAttribute("style","text-decoration:underline;"); tempbutton.setAttribute("onclick","addHyperlink(document.getElementsByTagName('textarea')["+x+"]);"); toolbar.appendChild(tempbutton); toolbar.appendChild(document.createTextNode(" "));
// Code button var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","Code"); tempbutton.setAttribute("title","Wrap \u003Cecode\u003E tags around the selected text."); tempbutton.setAttribute("style","font-family:monospace;"); tempbutton.setAttribute("onclick","addEcode(document.getElementsByTagName('textarea')["+x+"]);"); toolbar.appendChild(tempbutton);
// Teletype button var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","TT"); tempbutton.setAttribute("title","Wrap \u003Ctt\u003E (teletype, i.e. monospace) tags around the selected text."); tempbutton.setAttribute("style","font-family:monospace;"); tempbutton.setAttribute("onclick","addTT(document.getElementsByTagName('textarea')["+x+"]);"); toolbar.appendChild(tempbutton);
// Small button, if editing a story if (boxes[x].name == "introtext" || boxes[x].name == "bodytext" || boxes[x].name == "story") { var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","\u0073\u1D0D\u1D00\u029F\u029F"); tempbutton.setAttribute("title","Wrap \u003Csmall\u003E tags around the selected text."); // tempbutton.setAttribute("style","font-size:75%;"); tempbutton.setAttribute("onclick","addSmall(document.getElementsByTagName('textarea')["+x+"]);"); toolbar.appendChild(tempbutton); }
// Ordered list button var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","1. List"); tempbutton.setAttribute("title","Insert an ordered list or convert newline-separated text into an ordered list."); tempbutton.setAttribute("onclick","addOrdlist(document.getElementsByTagName('textarea')["+x+"]);"); toolbar.appendChild(tempbutton);
// Unordered list button var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","\u2022 List"); tempbutton.setAttribute("title","Insert an unordered list or convert newline-separated text into an unordered list."); tempbutton.setAttribute("onclick","addUnordlist(document.getElementsByTagName('textarea')["+x+"]);"); toolbar.appendChild(tempbutton);
// Despace button var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value","Despace"); tempbutton.setAttribute("title","Delete newlines within the selection."); tempbutton.setAttribute("onclick","despace(document.getElementsByTagName('textarea')["+x+"]);"); toolbar.appendChild(tempbutton);
// Symbol button var tempbutton = document.createElement("input"); tempbutton.setAttribute("type","button"); tempbutton.setAttribute("value",":-)"); tempbutton.setAttribute("title","Insert a symbol."); tempbutton.setAttribute("onclick","if (document.getElementById('smilebar"+x+"').style.display == 'none') {document.getElementById('smilebar"+x+"').style.display = 'block'} else {document.getElementById('smilebar"+x+"').style.display = 'none'; if (p = document.getElementById('postercomment')) { var x = p.offsetTop; while (p = p.offsetParent) {x += p.offsetLeft;} window.scrollTo(0,x-75); } }"); toolbar.appendChild(tempbutton); boxes[x].parentNode.insertBefore(toolbar, boxes[x].nextSibling);
// Symbol list var smilebar = document.createElement("div"); smilebar.setAttribute("style","-moz-user-select:none; -webkit-user-select:none; display:none; font-size:16pt; max-height:240px; overflow:auto; padding:0.5em;"); smilebar.setAttribute("id","smilebar"+x); var smiles = ["\u0026amp;","\u0026lt;","\u0026gt;"];
var codes = [[161,169],[171,172],[174],[176,177],[180,183],[187,191],[215],[224,255],[402],[629],[632],[916],[920],[931],[934],[937],[945,946],[956],[960],[963],[8216,8221],[8226],[8230],[8251],[8364],[8478],[8482],[8528,8542],[8585],[8592,8652],[8712,8716],[8721],[8730],[8733,8734],[8736],[8743,8749],[8756,8757],[8773],[8776],[8800,8805],[8834,8837],[8984],[9760],[9762,9765],[9770],[9773,9775],[9784,9794],[9812,9831],[9833,9842],[9850],[9855,9861],[9874,9877],[9882,9885],[9888,9893],[9913],[9940],[9962],[9971],[9981],[9992,10087],[65533],[127744,127756],[127759],[127775,127776],[127797],[127801],[127804,127812],[127817],[127820,127822],[127828,127831],[127838,127839],[127843],[127849],[127855],[127860,127867],[127891],[127904,127911],[127918],[127939],[127942],[127977],[128025],[128074,128078],[128123,128131],[128137,128142],[128148,128150],[128152],[128158],[128161,128164],[128168,128170],[128172],[128176,128177],[128187],[128189,128190],[128193,128194],[128197],[128203,128204],[128206],[128214],[128225,128227],[128231,128233],[128241],[128244],[128246],[128250,128252],[128259],[128266,128270],[128273,128276],[128278,128280],[128286],[128293,128299],[128302,128303],[128509,128510],[128659],[128684,128685]];
for (var i=0; i<codes.length; i++) { if (codes[i].length > 1) { for (var j=codes[i][0]; j<=codes[i][1]; j++) { smiles[smiles.length] = String.fromCodePoint(j); } } else { smiles[smiles.length] = String.fromCodePoint(codes[i][0]); } } // Populate smiles array with code ranges converted to individual characters
smiles = smiles.concat(["xD",":-)",":^)","(^_^;)","\u0028\u00A0\u0361\u00B0\u00A0\u035C\u0296\u00A0\u0361\u00B0\u0029","\u0028\u00A0\u0361\u007E\u00A0\u035C\u0296\u00A0\u0361\u00B0\u0029\uFEFF","\u00AF\u005C\u005F\u0028\u30C4\u0029\u005F\u002F\u00AF","\u0028\u256F\u00B0\u25A1\u00B0\uFF09\u256F\uFE35\u00A0\u253B\u2501\u253B","\u0028\u30CE\u0CA0\u76CA\u0CA0\u0029\u30CE\u5F61\u253B\u2501\u253B","\u0028\u0060\uFF65\u03C9\uFF65\u00B4\u0029","\u0CA0_\u0CA0","\u0295\u2022\u1D25\u2022\u0294","\u0028\u3065\uFFE3\u00A0\u00B3\uFFE3\u0029\u3065","\u0669\u0028\u204E\u275B\u1D17\u275B\u204E\u0029\u06F6","\u30FD\u0F3C\u0E88\u0644\u035C\u0E88\u0F3D\uFF89"]); // Add in arbitrary emoticons
for (var i=0; i<smiles.length; i++) { var smile = document.createElement("span"); smile.setAttribute("style","cursor:pointer; padding:2px; white-space:nowrap;"); smile.setAttribute("onclick","addSmile(document.getElementsByTagName('textarea')["+x+"],'"+smiles[i].replace("\u005C","\u005C\u005C")+"');"); smile.appendChild(document.createTextNode(smiles[i])); smilebar.appendChild(smile); if (i+1<smiles.length) { smilebar.appendChild(document.createTextNode(" ")); } } toolbar.parentNode.insertBefore(smilebar, toolbar.nextSibling);
// Create macro configuration interface var macrobar = document.createElement("div"); macrobar.setAttribute("style","display:none; padding:0.5em;"); macrobar.setAttribute("id","macrobar"+x); var table = document.createElement("table"); var tr = document.createElement("tr"); var th = document.createElement("th"); th.appendChild(document.createTextNode("Name")); tr.appendChild(th); var th = document.createElement("th"); th.appendChild(document.createTextNode("Type")); tr.appendChild(th); var th = document.createElement("th"); th.appendChild(document.createTextNode("String | Expression")); tr.appendChild(th); var th = document.createElement("th"); th.setAttribute("title","Only used with expressions. Parenthesized substring matches (e.g. '$1') can be used."); th.setAttribute("style","cursor:help;"); th.appendChild(document.createTextNode("Expression Replace")); tr.appendChild(th); table.appendChild(tr); for (var i=1; i<=7; i++) { var tr = document.createElement("tr");
// Macro name var td = document.createElement("td"); var name = document.createElement("input"); name.setAttribute("type","text"); name.setAttribute("id","soymacros"+x+"name"+i); td.appendChild(name); tr.appendChild(td);
// Macro type var td = document.createElement("td"); var rad = document.createElement("input"); rad.setAttribute("type","radio"); rad.setAttribute("name","soymacros"+x+"type"+i); rad.setAttribute("id","soymacros"+x+"type"+i+"S"); td.appendChild(rad); td.appendChild(document.createTextNode(" String ")); var rad = document.createElement("input"); rad.setAttribute("type","radio"); rad.setAttribute("name","soymacros"+x+"type"+i); rad.setAttribute("id","soymacros"+x+"type"+i+"E"); td.appendChild(rad); td.appendChild(document.createTextNode(" Expression ")); tr.appendChild(td);
// Field A var td = document.createElement("td"); var f1 = document.createElement("input"); f1.setAttribute("type","text"); f1.setAttribute("id","soymacros"+x+"fieldA"+i); td.appendChild(f1); tr.appendChild(td);
// Field B var td = document.createElement("td"); var f1 = document.createElement("input"); f1.setAttribute("type","text"); f1.setAttribute("id","soymacros"+x+"fieldB"+i); td.appendChild(f1); tr.appendChild(td);
var p = document.createElement("p"); var save = document.createElement("input"); save.setAttribute("type","button"); save.setAttribute("value","Save"); save.setAttribute("title","Save any edits to the macro configuration."); save.setAttribute("onclick","macrobarSave("+x+");"); p.appendChild(save); p.appendChild(document.createTextNode(" ")); var guide = document.createElement("a"); guide.setAttribute("href","https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions"); guide.setAttribute("target","_blank"); guide.appendChild(document.createTextNode("Regexp Guide")); p.appendChild(guide); macrobar.appendChild(p);
Soylent Upgrade Greasemonkey/Tampermonkey extension v9
Post Comment