灰话不说,上代码
[jscript autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”15-29,31,32,36,83,98,144-198″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”true” title=”172067.user.js”]
[/jscript]
// ==UserScript== // @name 贴吧彩字闪字 // @namespace yuxingyc // @description 彩字闪字通过www.czxiu.com网站在线生成 // @include http://tieba.baidu.com/* // @downloadURL https://userscripts.org/scripts/source/172067.user.js // @updateURL https://userscripts.org/scripts/source/172067.meta.js // @grant GM_setValue // @grant GM_getValue // @grant GM_addStyle // @grant GM_xmlhttpRequest // @version 1.2.1 // ==/UserScript== function GM_get(a,b){//GM_getValue在addNodeInsertedListener(参考大花猫的脚本,这个元素监听真心不错,比window.onload好多了)下无效,感谢@网络孤独行客修复 return GM_getValue(a,b); } function GM_set(a,b){ return GM_setValue(a,b); } //初始化默认设置 text_default=GM_getValue("text1","G风格彩字[14]"); value_dafalut=GM_getValue("value1","default#14"); noText=GM_getValue("noText",0); /*监听元素*/ addNodeInsertedListener('.old_style_wrapper', function() { $=unsafeWindow.$; $(".old_style_wrapper").after("<input id='bdinput2013627' type='button' value='生成图片'> <input id='bdinput2013627_2' type='button' value='设为默认'> <font color='gray'>提示:彩字闪字通过www.czxiu.com在线生成,并非本地生成</font>"); $(".old_style_wrapper").after("<select id='bdselect2013627' value='color'>"); function add(text1,value1){ document.getElementById("bdselect2013627").options.add(new Option(text1, value1)); } add(text_default,value_dafalut); add("G风格彩字[14]","default#14"); add("单行彩色字[20]","2011rbcolor#20"); add("浪漫英文[20]","romaneng#20"); add("丑人举牌[10]","080330paizi#10"); add("丑人拎牌[12]","biantaipai#12"); add("致富标语[16]","poster_wall2#16"); add("书写快乐[12]","pinkpen#12"); add("可爱的心[20]","070908_mrdx#20"); add("可爱闪字[14]","lovelyshine#14"); add("漂亮闪烁[14]","starshine#14"); add("记事本[16]","080405jsb#16"); add("小便条[20]","0809note#20"); function textToPic(w,o,z){ GM_xmlhttpRequest({ method: "GET", url:"http://www.czxiu.com/d.php?s=default", headers: { 'If-Modified-Since':'0', }, onload:function(response){ var a=response.responseText.replace(/\n|\r/g,""); var czMakey=a.match(/czMakey = '(\w+)'/)[1]; setImg(czMakey); } }); function setImg(czMakey){ var url1 = 'http://www.czxiu.com/m.php?k=' + czMakey + '&w=' + encodeURIComponent(w.replace(/&nbsp;| /g,".")) + '&s='+style+'&p=0';//p=1透明背景 GM_xmlhttpRequest({ method: "GET", url:url1, headers: { 'If-Modified-Since':'0', }, onload:function(response){ var str=response.responseText; var rtype = str.substring(0,2); var rdata = str.substring(4); if (rtype != 'OK')alert(rdata); else { var url = rdata.substring(2); url ="http://www.czxiu.com/"+url.replace(/\+/, '%20').replace(/"|'|<|>/g,''); if(noText==1)w=""; $("#ueditor_replace").html('<img unselectable="on" src="'+url+'" class="BDE_Image" onload="EditorUI.resizeImage(this, 560)"><br>'+w); o.disabled=false; z.disabled=false; } } }); } } var style="default"; function color() { var z=document.getElementById("bdselect2013627"); var v=z[z.selectedIndex].value.split("#"); style=v[0]; var w=$("#ueditor_replace").html().replace(/<[^>]+>/g,""); if (w == '') { alert('总该说点什么吧?'); } else if (w.length > parseInt(v[1])) { alert('抱歉,此风格最多'+v[1]+'字'); }else { z.disabled=true; var o=document.getElementById("bdinput2013627"); o.disabled=true; setTimeout(function() { o.disabled=false; z.disabled=false; },5000); textToPic(w,o,z); } } document.getElementById("bdselect2013627").addEventListener('change',color,false); document.getElementById("bdinput2013627").addEventListener('click',color,false); document.getElementById("bdinput2013627_2").addEventListener('click',function() { var z=document.getElementById("bdselect2013627"); var a=z[z.selectedIndex].text; var b=z[z.selectedIndex].value; GM_set("text1",a); GM_set("value1",b); if(confirm(a+"已设为默认\n\n生成图片后删除文字?\n\n要删除文字:点击[确定]\n要保留文字:点击[取消]\n(刷新后生效)")) { GM_set("noText",1); }else GM_set("noText",0); },false); }); //函数 元素精确定位 function addNodeInsertedListener(elCssPath, handler, executeOnce, noStyle) { var animName = "anilanim", prefixList = ["-o-", "-ms-", "-khtml-", "-moz-", "-webkit-", ""], eventTypeList = ["animationstart", "webkitAnimationStart", "MSAnimationStart", "oAnimationStart"], forEach = function(array, func) { for (var i = 0, l = array.length; i < l; i++) { func(array[i]); } }; if (!noStyle) { var css = elCssPath + "{", css2 = ""; forEach(prefixList, function(prefix) { css += prefix + "animation-duration:.001s;" + prefix + "animation-name:" + animName + ";"; css2 += "@" + prefix + "keyframes " + animName + "{from{opacity:.9;}to{opacity:1;}}"; }); css += "}" + css2; GM_addStyle(css); } if (handler) { var bindedFunc = function(e) { var els = document.querySelectorAll(elCssPath), tar = e.target, match = false; if (els.length !== 0) { forEach(els, function(el) { if (tar === el) { if (executeOnce) { removeNodeInsertedListener(bindedFunc); } handler.call(tar, e); return; } }); } }; forEach(eventTypeList, function(eventType) { document.addEventListener(eventType, bindedFunc, false); }); return bindedFunc; } } //函数 元素精确定位取消绑定 function removeNodeInsertedListener(bindedFunc) { var eventTypeList = ["animationstart", "webkitAnimationStart", "MSAnimationStart", "oAnimationStart"], forEach = function(array, func) { for (var i = 0, l = array.length; i < l; i++) { func(array[i]); } }; forEach(eventTypeList, function(eventType) { document.removeEventListener(eventType, bindedFunc, false); }); }
脚本原作者@yuxingyc
修复by小绯
【在线安装】
GJ
firefox基~
支持,非常好~
看着这么长的一大串。。。哥就快醉了