There are 27 previous versions of this script.
scr_meta=<><![CDATA[
// ==UserScript==
// @name Userscripts.org Quick Quote
// @namespace http://userscripts.org/users/23652
// @description Adds a quote button under usernames, even has selection quoting and nested quotes
// @include http://userscripts.org/topics/*
// @include https://userscripts.org/topics/*
// @copyright JoeSimmons
// @version 1.1.2
// @license Creative Commons Attribution-Noncommercial 3.0 United States License
// @require http://userscripts.org/scripts/source/51532.user.js
// ==/UserScript==
]]></>.toString();
// Create by avg, modified by JoeSimmons
function create(a,b) {
if(!a || a=="" || !b) return;
var ret=document.createElement(a);
for(var prop in b) if(prop.indexOf("on")==0) ret.addEventListener(prop.substring(2),b[prop],false);
else if(prop=="kids" && (prop=b[prop])) for each(var p in prop) ret.appendChild(p);
else if(/^(style|accesskey|id|name|src|href)$/.test(prop)) ret.setAttribute(prop, b[prop]);
else ret[prop]=b[prop];
return ret;
}
function selectHTML() {
var sel = window.getSelection(), html = "";
for (var i=0,l=sel.rangeCount; i<l; i++) {
var d = document.createElement("span"),
r = sel.getRangeAt(i),
parent_element = r.commonAncestorContainer,
prev_html = parent_element.innerHTML;
r.surroundContents(d);
html += d.innerHTML;
parent_element.innerHTML = prev_html;
}
return html;
}
function getPoster(e) {
var html = e.innerHTML.replace(/\n/g,"");
return {href:html.match(/^.+(https?\:\/\/userscripts\.org\/users\/[^"]+)/)[1], name:html.match(new RegExp($g(nestedposter["href"]+"\">([^<]+)<\/a>")))[1]};
}
function getPostID(e) {
var p = e.currentTarget || e.focusNode || e;
while((p=p.parentNode)!=null) if(p.id && (p.id.indexOf("post-body-")==0||p.id.indexOf("row-")==0)) return p.id.match(/^(post-body|row)-(\d+)$/)[2];
}
function quote(e) {
try {
var box, post, id=getPostID(e), url=window.location.href.replace(/#.*$/,""),
body = $g("#post-body-"+id),
select=window.getSelection(),
inpost=false;
// Check if selection is inside a post
if(select.focusNode && select.toString().length>0) {
var tag=select.focusNode.parentNode, p=select.focusNode;
while((p=p.parentNode)&&!inpost) if(p.id&&p.id.indexOf("post-body-")==0) inpost=true;
}
if(inpost) {
post = selectHTML().replace(/^(<p>\s*<\/p>)/g,"").replace(/^(\s*<br>\s*)*\s*/,"").replace(/^\s*/,"");
tag = tag.tagName.toLowerCase();
if(select.focusNode.textContent.indexOf(" wrote:")!=-1 && tag=="blockquote") {
var nestedposter = getPoster(select.focusNode);
post = "<blockquote><strong><a href=\""+nestedposter["href"]+"\">"+nestedposter["name"]+"</a></strong> wrote:<br>"+post+"</blockquote>";
}
else if(!/(t[dr]|table|a|li|[ou]l|big)/.test(tag)) post = "<"+tag+">"+post+"</"+tag+">";
}
else if(select.toString().length==0) post = body.innerHTML;
else return;
poster = $g(".//span/a[starts-with(@href, '/users/')]", {type:9, node:$g("#row-"+id)});
if($g("#edit_post_body") && $g("#edit").offsetWidth>0) box=$g("#edit_post_body");
else {
box=$g("#post_body");
if($g("#reply").style.display=="none") {
box.value="";
$g("#reply").style.display = "";
}
}
var post = "<blockquote><strong><a href=\""+poster.href+"\">"+poster.textContent+"</a></strong> <a href=\""+url+"#row-"+id+"\">wrote</a>:<br>" + post.replace(/^[\s\w\D]*<!--[\s\w\D]*-->/, "").replace(/(<br>*)*\s*/,"").replace(/\n/g,"<br>").replace(/ {2,}/g," ").replace(/<br> <br>/g,"<br>").replace(/<br>\s*$/,"").replace(/<br>\s/g,"<br>").replace(/\<\/?p\>/g,"").replace(/<\/a> <a/,"</a> <a") + "</blockquote>\n";
if(box && box.value=="") box.value = post;
else if(box) {
box.value = box.value.replace(/\n+$/,"");
box.value += "\n"+post;
}
box.focus();
box.scrollTop = box.scrollHeight;
} catch(err) {alert("Quote function error:\n\n"+err);}
}
var posts = $g(".//td[@class='author vcard']", {node:$g("#container")});
for(var i=0,post; (post=posts.snapshotItem(i)); i++) post.appendChild(create("a", {href:"javascript:void(0);",style:"display:block;",textContent:"Quote",onclick:quote}));
// Auto-Update by sizzlemctwizzle
aaus_38017={
i:"47155", // Script id on Userscripts.org
d:1, // Days to wait between update checks
n:/\/\/\s*@name\s+(.*)\s*\n/i.exec(scr_meta)[1],v:/\/\/\s*@version\s+(.*)\s*\n/i.exec(scr_meta)[1].replace(/\./g, ""),t:new Date().getTime()|0,ca:function(r){GM_xmlhttpRequest({method:"GET",url:"https://userscripts.org/scripts/source/"+this.i+".meta.js",onload:function(x){aaus_38017.co(x,r)}})},co:function(x,r){this.xv=/\/\/\s*@version\s+(.*)\s*\n/i.exec(x.responseText);this.xn=/\/\/\s*@name\s+(.*)\s*\n/i.exec(x.responseText);if(this.xv&&this.xn[1]==this.n){this.xv=this.xv[1].replace(/\./g, "");this.xn=this.xn[1];}else{if(x.responseText.match("Uh-oh! The page could not be found!")||this.xn[1]!=this.n)GM_setValue("updated", "off");return false;}if(this.xv>this.v&&confirm("A new version of the "+this.xn+" user script is available. Do you want to update?")){GM_setValue("updated",this.t);GM_openInTab("http://userscripts.org/scripts/source/"+this.i+".user.js")}else if(this.xv&&this.xv>this.v){if(confirm("Do you want to turn off auto updating for this script?")){GM_setValue("updated","off");GM_registerMenuCommand("Auto Update "+this.n,function(){GM_setValue("updated",new Date().getTime()|0);aaus_38017.ca("return")});alert("Automatic updates can be re-enabled for this script from the User Script Commands submenu.")}else{GM_setValue("updated",this.t)}}else{if(r)alert("No updates available for "+this.n);GM_setValue("updated",this.t)}},ch:function(){if(GM_getValue("updated",0)==0)GM_setValue("updated",this.t);if(GM_getValue("updated",0)!="off"&&+this.t>+GM_getValue("updated",0)+86400000*this.d){this.ca()}else if(GM_getValue("updated",0)=="off"){GM_registerMenuCommand("Enable "+this.n+" updates",function(){GM_setValue("updated",new Date().getTime()|0);aaus_38017.ca(true)})}else{GM_registerMenuCommand("Check "+this.n+" for updates",function(){GM_setValue("updated",new Date().getTime()|0);aaus_38017.ca(true)})}}};if(self.location==top.location&&GM_xmlhttpRequest)aaus_38017.ch();
