ABPVN VNZ-toolkit

Hỗ trợ thêm tính năng trên VNZ

  1. // ==UserScript==
  2. // @name ABPVN VNZ-toolkit
  3. // @namespace ABPVN
  4. // @author Hoàng Rio
  5. // @description Hỗ trợ thêm tính năng trên VNZ
  6. // @homepage http://abpvn.com
  7. // @icon http://i.imgur.com/vAI2Rxd.png
  8. // @include http://www.vn-zoom.com/f*
  9. // @include http://www.vn-zoom.com/newreply.php*
  10. // @include http://www.vn-zoom.com/editpost.php*
  11. // @require https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.js
  12. // @version 1.3.8
  13. // @grant none
  14. // ==/UserScript==
  15. String.prototype.ismatch = function (regex){
  16. return this.match(regex)!==null;
  17. };
  18. $.getcookie=function(cookiename){
  19. var value = "; " + document.cookie;
  20. var parts = value.split("; " + cookiename + "=");
  21. if (parts.length == 2) return parts.pop().split(";").shift();
  22. };
  23. var img_count=0;
  24. function VNZ_img_view(){
  25. $(document).ready(function (){
  26. $('head').append('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.css" type="text/css" media="screen" />');
  27. $('.content img').each(function (){
  28. if(!$(this).attr('src').ismatch("http://www.vn-zoom.com")){
  29. this.onclick= function () {};
  30. $(this).css('cursor','zoom-in');
  31. $(this).wrap('<a class="abpvn" style="cursor: zoom-in;" title="'+$(this).attr("src")+'" rel="group" href="'+$(this).attr("src")+'"></a>');
  32. }
  33. });
  34. $("a.abpvn").fancybox({
  35. 'padding' : '0',
  36. 'type' : 'image',
  37. 'transitionIn' : 'elastic',
  38. 'transitionOut' : 'elastic',
  39. 'speedIn' : 300,
  40. 'speedOut' : 200,
  41. 'overlayShow' : true,
  42. 'titlePosition' : 'over',
  43. 'overlayOpacity': 0.8,
  44. 'hideOnOverlayClick': true,
  45. helpers : {
  46. overlay : {
  47. css : {
  48. 'z-index': '0',
  49. }
  50. }
  51. }
  52. });
  53. });
  54. }
  55. function VNZ_toolkit_options(){
  56. $(document).ready(function (){
  57. $('body').append("<div id='VNZ-toolkit-options' accesskey='v' style='width: auto; height: auto; top: 0; left: 0; position: fixed; opacity: 0.75;' title='Cài đặt ABPVN VNZ-toolkit'><img src='https://www.webanh.tk/full/h5EKCO.png' style='border-radius: 50%; box-shadow: 0px 0px 25px 5px black; cursor: pointer; width:30px; height:30px;'></img></div>");
  58. $('#VNZ-toolkit-options').append("<div id='VNZ-toolkit-options-area' style='display: none; color: white; background-color: green; margin-left: 32px; padding: 10px; box-shadow: 0px 0px 25px 5px black; border-radius: 10px; border: 1px white solid; font-size: 14px;'><center><div id='msg' style='color: red; height: 20px;'></div></center></div>");
  59. $('#VNZ-toolkit-options-area').append("<label><input id='VNZ-toolkit-img-view' checked='true' type='checkbox'/>Chế độ xem ảnh</label><br/>");
  60. $('#VNZ-toolkit-options-area').append("<label><input id='VNZ-toolkit-img-qUpload' checked='true' type='checkbox'/>Chế độ up ảnh nhanh</label><br/>");
  61. $('#VNZ-toolkit-options-area').append("<center><button id='VNZ-toolkit-options-save' style='align: center; width: 50px;'>Lưu</button><center>");
  62. $('#VNZ-toolkit-options img').mouseover(function(){
  63. if($.getcookie('ABPVN VNZ-toolkit')!==undefined){
  64. var ABPVN_VNZ_options=$.getcookie('ABPVN VNZ-toolkit').split(',');
  65. if(ABPVN_VNZ_options[0]!='true'){
  66. $('#VNZ-toolkit-img-view').prop('checked',false);
  67. }
  68. if(ABPVN_VNZ_options[1]!='true'){
  69. $('#VNZ-toolkit-img-qUpload').prop('checked',false);
  70. }
  71. }
  72. $('#msg').html('');
  73. $('#VNZ-toolkit-options-area').fadeIn('slow');
  74. });
  75. $('#VNZ-toolkit-options').mouseleave(function(){
  76. $('#VNZ-toolkit-options-area').fadeOut('slow');
  77. });
  78. $('#VNZ-toolkit-options-save').click(function(){
  79. var now = new Date();
  80. var time = now.getTime();
  81. var expireTime = time + 365*24*3600*1000;
  82. now.setTime(expireTime);
  83. var cookie_str='ABPVN VNZ-toolkit=';
  84. $("#VNZ-toolkit-options-area input[type=checkbox]").each(function (){
  85. cookie_str+=$(this).prop('checked')+',';
  86. });
  87. document.cookie=cookie_str+';expires='+now.toGMTString()+';path=/;';
  88. $('#msg').html('Đã lưu');
  89. $('#VNZ-toolkit-options-area').fadeOut('slow');
  90. });
  91. });
  92. }
  93. $.VNZ_tookit_upload=function(file, element){
  94. var fd=new FormData();
  95. fd.append('file_up',file);
  96. $.ajax({
  97. xhr: function() {
  98. var xhr = new window.XMLHttpRequest();
  99. xhr.upload.addEventListener("progress", function(e) {
  100. if (e.lengthComputable) {
  101. var percentValue =Math.round((e.loaded / e.total) * 100) + '%';
  102. $('#cke_top_'+element+' div.cke_toolbox span#VNZ_img_count').attr("title","Đang upload "+file.name+" : "+percentValue);
  103. }
  104. }, false);
  105.  
  106. xhr.addEventListener("progress", function(e) {
  107. if (e.lengthComputable) {
  108. var percentValue =Math.round((e.loaded / e.total) * 100) + '%';
  109. $('#cke_top_'+element+' div.cke_toolbox span#VNZ_img_count').attr("title","Đang upload "+file.name+" : "+percentValue);
  110. }
  111. }, false);
  112.  
  113. return xhr;
  114. },
  115. type: 'POST',
  116. crossDomain: true,
  117. url: 'https://www.webanh.tk/ajax?act=upload&from=vnz',
  118. data: fd,
  119. processData: false,
  120. contentType: false,
  121. success:function(data){
  122. //console.log('#cke_top_'+element+' div.cke_toolbox span#VNZ_img_count')
  123. $('#cke_contents_'+element+' textarea').val($('#cke_contents_'+element+' textarea').val()+'\n'+data.bbcode);
  124. //console.log(data.bbcode);
  125. img_count--;
  126. $('#cke_top_'+element+' div.cke_toolbox span#VNZ_img_count').html("Đang tải lên "+img_count+" ảnh");
  127. if(img_count===0){
  128. $(".VNZ_img_qUpload").attr('src','https://www.webanh.tk/css/images/upload.png');
  129. $('.VNZ_img_qUpload').attr('title','Upload ảnh nhanh lên webanh.tk');
  130. $('#cke_top_'+element+' div.cke_toolbox span#VNZ_img_count').hide();
  131. $('#cke_top_'+element+' div.cke_toolbox span#ABPVN_VNZ span.cke_toolgroup img.VNZ_img_qUpload').bind('click',function(){
  132. $('#VNZ_img_up_'+element+'').trigger("click");
  133. });
  134. }
  135. },
  136. error: function(xhr,status,error){
  137. /*if(status=='error'){
  138. $('#progress-'+index+'').attr('class','error');
  139. $('#progress-'+index+'').attr('style','width: 100%');
  140. $('#progress-'+index+'').attr('title',status);
  141. }*/
  142. alert("Lỗi kết nối");
  143. }
  144. });
  145. //console.log(error);
  146. };
  147. function VNZ_img_qUpload(){
  148. var VNZ_img_up=function (element){
  149. $('#cke_top_'+element+' div.cke_toolbox').append('<span id="ABPVN_VNZ" class="cke_toolbar"><span class="cke_toolgroup" style="width: 20px; height: 20px; border-radius: 50%; border: 2px green solid;"><img title="Upload ảnh nhanh lên webanh.tk" class="VNZ_img_qUpload cke_button" style="width: 20px; height: 20px; border-radius: 50%" src="https://www.webanh.tk/css/images/upload.png"></img><input type="file" id="VNZ_img_up_'+element+'" data-element="'+element+'" name="VNZ_img_up" accept="image/*" multiple="true" style="display: none"/></span></span><span class="cke_button" id="VNZ_img_count" style="display: none; color: white; background-color: black;"></span>');
  150. $('#cke_top_'+element+' div.cke_toolbox span#ABPVN_VNZ span.cke_toolgroup img.VNZ_img_qUpload').bind('click',{element: element},function(event){
  151. $('#VNZ_img_up_'+event.data.element+'').trigger("click");
  152. });
  153. $('#VNZ_img_up_'+element+'').bind('change',function (event){
  154. var element=$(this).attr('data-element');
  155. $('#cke_top_'+element+' div.cke_toolbox span#ABPVN_VNZ span.cke_toolgroup img.VNZ_img_qUpload').attr('src','https://www.webanh.tk/css/images/loading.gif');
  156. $('#cke_top_'+element+' div.cke_toolbox span#ABPVN_VNZ span.cke_toolgroup img.VNZ_img_qUpload').attr('title','Đang upload');
  157. var acceptext=['jpg','png','gif','bmp','svg','ico'];
  158. var files=$(this).prop('files');
  159. var filenames=$.map(files, function(val) { return val.name; });
  160. for(var i=0;i<files.length;i++){
  161. var fileext=filenames[i].substr( (filenames[i].lastIndexOf('.') +1) );
  162. fileext=fileext.toLowerCase();
  163. if($.inArray(fileext,acceptext)!=-1){
  164. $('#cke_top_'+element+' div.cke_toolbox span#VNZ_img_count').show();
  165. $('#cke_top_'+element+' div.cke_toolbox span#VNZ_img_count').html("Đang tải lên "+files.length+" ảnh");
  166. img_count=files.length;
  167. $.VNZ_tookit_upload(files[i], element);
  168. $('#cke_top_'+element+' div.cke_toolbox span#ABPVN_VNZ span.cke_toolgroup img.VNZ_img_qUpload').unbind('click');
  169. }
  170. }
  171. });
  172. };
  173. $(window).load(function(){
  174. VNZ_img_up('vB_Editor_QR_editor');
  175. VNZ_img_up('vB_Editor_001_editor');
  176. });
  177. $('a.editpost').click(function (){
  178. setTimeout(function(){
  179. VNZ_img_up('vB_Editor_QE_1_editor');
  180. VNZ_img_up('vB_Editor_QE_2_editor');
  181. VNZ_img_up('vB_Editor_QE_3_editor');
  182. },1500);
  183. });
  184. //console.log("VNZ_img_qUpload fired");
  185. }
  186. (function (){
  187. VNZ_toolkit_options();
  188. if($.getcookie('ABPVN VNZ-toolkit')!==undefined){
  189. var ABPVN_VNZ_options=$.getcookie('ABPVN VNZ-toolkit').split(',');
  190. if(ABPVN_VNZ_options[0]=='true'){
  191. VNZ_img_view();
  192. }
  193. if(ABPVN_VNZ_options[1]=='true'){
  194. VNZ_img_qUpload();
  195. }
  196. }
  197. else{
  198. VNZ_img_view();
  199. VNZ_img_qUpload();
  200. }
  201. })();