Stories
Slash Boxes
Comments

SoylentNews is people

Log In

Log In

Create Account  |  Retrieve Password


takyon (881)

Journal of takyon (881)

The Fine Print: The following are owned by whoever posted them. We are not responsible for them in any way.
Thursday May 21, 15
12:48 AM
Code

// ==UserScript==
// @name Soylent Upgrade
// @match http://soylentnews.org/submit.pl
// @match https://soylentnews.org/submit.pl
// @match http://soylentnews.org/submit.pl?op=viewsub&subid=*
// @match https://soylentnews.org/submit.pl?op=viewsub&subid=*
// @match http://soylentnews.org/admin.pl
// @match https://soylentnews.org/admin.pl
// @match http://soylentnews.org/admin.pl?op=edit&sid=*
// @match https://soylentnews.org/admin.pl?op=edit&sid=*
// @match http://soylentnews.org/comments.pl*
// @match https://soylentnews.org/comments.pl*
// ==/UserScript==

var simplifyChars = true;

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;
        temp = temp.replace(/<\/p><p>/g,"<\/p>\n\n<p>");
        temp = temp.replace(/<br>\s?<br>/g,"<\/p>\n\n<p>");
        temp = temp.replace(/<\/blockquote><p>/g,"<\/blockquote>\n\n<p>");
        temp = temp.replace(/<\/p><blockquote>/g,"<\/p>\n\n<blockquote>");
        temp = temp.replace(/<blockquote><div><p>/g,"<blockquote><div>\n\n<p>");
        temp = temp.replace(/<\/p><\/div><\/blockquote>/g,"<\/p>\n\n<\/div><\/blockquote>");
        temp = temp.replace(/<\/blockquote><blockquote>/g,"<\/blockquote>\n\n<blockquote>");
        temp = temp.replace(/<p class="byline">\s/i,"<p class=\"byline\">");
        temp = temp.replace(/<p>\s/g,"<p>");
        temp = temp.replace(/\s<\/p>/g,"<\/p>");
        temp = temp.replace(/<\/li><li>/g,"<\/li>\n<li>");
        temp = temp.replace(/<\/li><\/ul>/g,"<\/li>\n<\/ul>");
        temp = temp.replace(/<\/p><ul>/g,"<\/p>\n\n<ul>");
        temp = temp.replace(/<p>\[...\]/g,"<p>[...] ");
        while (temp.indexOf("  ")!=-1)
        {
            temp = temp.replace(/  /g," ");
        }
        if (simplifyChars)
        {
            temp = temp.replace(/\u2018/g,"'");
            temp = temp.replace(/\u2019/g,"'");
            temp = temp.replace(/\u201C/g,"\"");
            temp = temp.replace(/\u201D/g,"\"");
            temp = temp.replace(/\u2026/g,"..."); // ellipsis
        }
        boxes[x].value = temp;
        boxes[x].rows = 32;
    }
    var toolbar = document.createElement("div");
    // Blockquote button
    var tempbutton = document.createElement("input");
    tempbutton.setAttribute("type","button");
    tempbutton.setAttribute("value","Blockquote");
    tempbutton.setAttribute("onmousedown","addBlockquote(document.getElementsByTagName('textarea')["+x+"]);");
    toolbar.appendChild(tempbutton);
    // Bold button
    var tempbutton = document.createElement("input");
    tempbutton.setAttribute("type","button");
    tempbutton.setAttribute("value","B");
    tempbutton.setAttribute("style","font-weight:bold;");
    tempbutton.setAttribute("onmousedown","addBold(document.getElementsByTagName('textarea')["+x+"]);");
    toolbar.appendChild(tempbutton);
    // Italic button
    var tempbutton = document.createElement("input");
    tempbutton.setAttribute("type","button");
    tempbutton.setAttribute("value","I");
    tempbutton.setAttribute("style","font-style:italic;");
    tempbutton.setAttribute("onmousedown","addItalic(document.getElementsByTagName('textarea')["+x+"]);");
    toolbar.appendChild(tempbutton);
    // Strike button
    var tempbutton = document.createElement("input");
    tempbutton.setAttribute("type","button");
    tempbutton.setAttribute("value","S");
    tempbutton.setAttribute("style","text-decoration:line-through;");
    tempbutton.setAttribute("onmousedown","addStrike(document.getElementsByTagName('textarea')["+x+"]);");
    toolbar.appendChild(tempbutton);
    boxes[x].parentNode.insertBefore(toolbar, boxes[x].nextSibling);
}

var temp = document.createElement("script");
temp.appendChild(document.createTextNode("function addBlockquote(area) { var sel = getSelection(); if (sel.length != 0) { area.value = area.value.replace(sel,'<blockquote>'+sel+'<\/blockquote>'); } } function addBold(area) { var sel = getSelection(); if (sel.length != 0) { area.value = area.value.replace(sel,'<b>'+sel+'<\/b>'); } } function addItalic(area) { var sel = getSelection(); if (sel.length != 0) { area.value = area.value.replace(sel,'<em>'+sel+'<\/em>'); } } function addStrike(area) { var sel = getSelection(); if (sel.length != 0) { area.value = area.value.replace(sel,'<strike>'+sel+'<\/strike>'); } }"));
document.getElementsByTagName('head')[0].appendChild(temp);

function getSelection() {
    return (!!document.getSelection) ? document.getSelection() :
           (!!window.getSelection)   ? window.getSelection() :
           document.selection.createRange().text;
}

Display Options Threshold/Breakthrough Reply to Article Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.