Tieba Quotor

贴吧引用

目前為 2014-03-05 提交的版本,檢視 最新版本

// ==UserScript==
// @name	Tieba Quotor
// @namespace	http://gera2ld.blog.163.com/
// @author	Gerald <[email protected]>
// @icon	http://s.gravatar.com/avatar/a0ad718d86d21262ccd6ff271ece08a3?s=80
// @version	1.4.4
// @description	贴吧引用
// @homepage	http://userscripts.org/scripts/show/157071
// @include	http://tieba.baidu.com/*
// @exclude	http://tieba.baidu.com/tb/*
// @require	http://userscripts.org/scripts/source/186749.user.js
// ==/UserScript==
function t(){function t(t){t.preventDefault();var e=$(this).parent().hasClass("p_mtail"),a=t.target,n=$(a).parents(".l_post"),i=e?n:$(a).parents(".lzl_single_post"),r=JSON.parse(n.attr("data-field")),o=e?r.author.name:JSON.parse(i.attr("data-field")).user_name;for(n=[],a=i.find(e?"div.d_post_content":"span.lzl_content_main").contents(":not(blockquote)").each(function(t,e){n.push(e)});n.length&&("BR"==n[0].tagName||!/\S/.test(n[0]));)n.shift();for(i=n.length-1,a=[];i>=0&&n.length;i--)if("BR"==n[i].tagName){if(!/^\s*($|——|>>)/.test(a.join("")))break;n.splice(i),a.splice(0)}else a.unshift(n[i].innerText||n[i].textContent||n[i].data);a=[],n.forEach(function(t){a.push(t.outerHTML||t.data||"")}),a=a.join("").replace(/^\s+|\s+$/gi,"").replace(/\s?<a [^>]*>@(.*?)<\/a>\s?/gi," $1 ").replace(/<a [^>]*?href="(.*?)"[^>]*>(.*?)<\/a>/,function(t,e,a){return e==a?a:'<font color="#261cdc">'+a+"</font>"}),a="引用 @"+o+" ("+r.content.floor+"楼"+(e?"":"之楼中楼")+")<br>"+a+"<br>————————————————————————————————<br><br>",(t=utils.unminify)&&t(),unsafeWindow.test_editor.execCommand("inserthtml",a)}$("<a href=#>引用</a>").css({"float":"right","margin-left":"5px"}).appendTo(".p_mtail").click(t),n.push(function(e){$("<a href=#>引用</a>").css("margin-right","10px").insertBefore(e.find("span.lzl_time")).click(t)})}function e(){function t(t,e){return'<a href="/f?ct=335675392&sc='+t+"&z="+PageData.thread.id+"#"+t+'" title="精确定位链接">'+e+"</a>"}function e(){for(var n=0,i=0;n<a.length;n++){var r=$(a[n]).children().children();if(r.length){var o=r.parents(".l_post").children("a").attr("name");r[0]&&(r[0].outerHTML="<a href=#"+o+' title="楼层定位链接">'+r[0].innerHTML+"</a>"),r[1]&&(r[1].outerHTML=t(o,r[1].innerHTML))}else a[i++]=a[n]}a.splice(i),a.length&&setTimeout(e,500)}var a=$("ul.p_tail").get();e(),n.push(function(e){e.find("span.lzl_time").html(function(e,a){return t($(this).parents(".lzl_single_post").children("a").attr("name"),a)})}),utils.addStyle("fieldset .BDE_Image{height:auto !important; width:auto !important; max-height:200px; max-width:560px !important;}"),$("div.d_post_content").each(function(t,e){var a,n,i=-1,r=$(e).contents();for(a=0;a<r.length;a++)n=r[a],i>=0&&"#text"==n.nodeName&&/^\s*—{27,36}\s*$/.test(n.data)?(r.slice(i,i+3).wrapAll("<legend>").parent().add(r.slice(i+4,a).wrapAll("<p class=quote_content>").parent()).wrapAll("<blockquote class=d_quote>").wrapAll("<fieldset>"),$(n).add(r[i+3]).remove(),(n=r[a+1])&&"BR"==n.nodeName&&($(n).remove(),a++),i=-1):"#text"==n.nodeName&&/^\s*引用(\s|&nbsp;?)+$/.test(n.data)&&r[a+1]&&"A"==r[a+1].nodeName&&"@"==r[a+1].innerHTML[0]&&r[a+2]&&"#text"==r[a+2].nodeName&&/^\s+\(.*?楼\)$/.test(r[a+2].data)&&"BR"==r[a+3].nodeName&&(i=a,a+=3)})}function a(){function t(e){var a=this;a.update=function(){var i=e.find("p.j_pager");return"1"==i.attr("clicked")?a.delay():(n.forEach(function(t){t(e)}),i.click(function(e){"A"==e.target.tagName&&($(this).attr("clicked","1"),e=new t($(this).parents("ul.j_lzl_m_w")),e.delay())}),void 0)},a.delay=function(){setTimeout(a.update,200)}}var e=new t($("ul.j_lzl_m_w"));e.update()}var n=[];PageData&&PageData.user&&(PageData.thread&&e(),PageData.user.is_login&&(unsafeWindow.PosterContext&&unsafeWindow.PosterContext.isPostAllowed()&&t(),unsafeWindow.LzlEditor&&a()));