🏠 Home 

Greasy Fork is available in English.

hwm_text_counter

Подсчет количества введенных символов в полях ввода: форума, персональной информации, личной почты, блокнота, описания клана, рассылки по клану (by Demin)

  1. // ==UserScript==
  2. // @name hwm_text_counter
  3. // @author Demin
  4. // @namespace Demin
  5. // @description Подсчет количества введенных символов в полях ввода: форума, персональной информации, личной почты, блокнота, описания клана, рассылки по клану (by Demin)
  6. // @homepage https://greasyfork.org/users/1602-demin
  7. // @icon http://i.imgur.com/LZJFLgt.png
  8. // @version 1.3
  9. // @encoding utf-8
  10. // @include http://*heroeswm.ru/*
  11. // @include http://178.248.235.15/*
  12. // @include http://*lordswm.com/*
  13. // @exclude */rightcol.php*
  14. // @exclude */ch_box.php*
  15. // @exclude */chat*
  16. // @exclude */ticker.html*
  17. // @exclude */frames*
  18. // @exclude */brd.php*
  19. // @grant GM_deleteValue
  20. // @grant GM_getValue
  21. // @grant GM_listValues
  22. // @grant GM_setValue
  23. // @grant GM_addStyle
  24. // @grant GM_log
  25. // @grant GM_openInTab
  26. // ==/UserScript==
  27. // (c) 2014-2015, demin ( http://www.heroeswm.ru/pl_info.php?id=15091 )
  28. // (c) 2010, bonArt
  29. (function() {
  30. var version = '1.3';
  31. if (typeof GM_getValue != 'function') {
  32. this.GM_getValue=function (key,def) {return localStorage[key] || def;};
  33. this.GM_setValue=function (key,value) {return localStorage[key]=value;};
  34. this.GM_deleteValue=function (key) {return delete localStorage[key];};
  35. }
  36. var url_cur = location.href;
  37. var url = 'http://'+location.hostname+'/';
  38. //====================Page detection====================
  39. var url_reply = "forum_messages.php";
  40. var url_newmsg = "new_topic.php";
  41. var url_sett = "pers_settings.php";
  42. var url_sms = "sms-create.php";
  43. var url_note = "sms.php?notebook";
  44. var url_clan = "clan_control.php";
  45. var url_clan_sms = "clan_broadcast.php";
  46. if ( (url_cur.indexOf(url_clan)==-1) && (url_cur.indexOf(url_note)==-1) && (url_cur.indexOf(url_reply)==-1) && (url_cur.indexOf(url_newmsg)==-1) && (url_cur.indexOf(url_sms)==-1) && (url_cur.indexOf(url_clan_sms)==-1) && (url_cur.indexOf(url_sett)==-1) ) return;
  47. var script_num = 6799;
  48. var script_name = "hwm_text_counter: Подсчет количества введенных символов в полях ввода: форума, персональной информации, личной почты, блокнота, описания клана, рассылки по клану (by Demin)";
  49. update_n(version,script_num,script_name);
  50. //====================Text blocks====================
  51. if ( url.match('lordswm') ) {
  52. var msg_head = "Subject: "; //head
  53. var msg_body_sms = "Message: "; //message body
  54. var msg_body = "";
  55. var used_smb = "Used "; //used
  56. var chars_of = " chars of "; //chars of
  57. } else {
  58. var msg_head = "\u0422\u0435\u043C\u0430\u003A "; //head
  59. var msg_body_sms = "\u0422\u0435\u043B\u043E \u0441\u043E\u043E\u0431\u0449\u0435\u043D\u0438\u044F\u003A "; //message body
  60. var msg_body = "";
  61. var used_smb = "\u0412\u0432\u0435\u0434\u0435\u043D\u043E "; //used
  62. var chars_of = " \u0441\u0438\u043C\u0432\u043E\u043B\u043E\u0432 \u0438\u0437 "; //chars of
  63. }
  64. //====================Nod generation====================
  65. if ( (url_cur.indexOf(url_sms)!=-1) || (url_cur.indexOf(url_clan_sms)!=-1) || (url_cur.indexOf(url_newmsg)!=-1) ) {
  66. var tr_th = document.createElement('tr');
  67. var td_th = document.createElement('td');
  68. var sp_th = document.createElement('span');
  69. tr_th.appendChild(td_th);
  70. td_th.appendChild(sp_th);
  71. }
  72. var tr_ta = document.createElement('tr');
  73. var td_ta = document.createElement('td');
  74. var sp_ta = document.createElement('span');
  75. tr_ta.appendChild(td_ta);
  76. td_ta.appendChild(sp_ta);
  77. //====================Pages parameters====================
  78. var t_col = 0;
  79. var msg_ta = document.querySelector("textarea");
  80. if ( !msg_ta ) return;
  81. var msg_th = document.querySelector("form");
  82. //subj.maxLength = maxLength;
  83. if ( url_cur.indexOf(url_reply)!=-1 ) {
  84. var max_chars_ta = 3000;
  85. t_col = 2;
  86. msg_ta.rows = 15;
  87. }
  88. if ( url_cur.indexOf(url_newmsg)!=-1 ) {
  89. msg_th = msg_th.querySelector("input[type='text']");
  90. var max_chars_th = 70;
  91. var max_chars_ta = 3000;
  92. msg_body = msg_body_sms;
  93. t_col = 2;
  94. msg_ta.rows = 10;
  95. }
  96. if ( url_cur.indexOf(url_sett)!=-1 ) {
  97. var max_chars_ta = 2000;
  98. t_col = 2;
  99. msg_ta.rows = 40;
  100. }
  101. if ( url_cur.indexOf(url_sms)!=-1 ) {
  102. msg_th = msg_th.querySelectorAll("input[type='text']")[1];
  103. var max_chars_th = 70;
  104. var max_chars_ta = 3900;
  105. msg_body = msg_body_sms;
  106. t_col = 2;
  107. msg_ta.rows = 20;
  108. msg_ta.style.width = 900;
  109. }
  110. if ( url_cur.indexOf(url_note)!=-1 ) {
  111. var max_chars_ta = 2900;
  112. td_ta.className = "wblight";
  113. td_ta.style.borderTopWidth = "0px";
  114. msg_ta.parentNode.className = "wblight";
  115. msg_ta.parentNode.style.borderBottomWidth = "0px";
  116. msg_ta.parentNode.parentNode.parentNode.parentNode.cellSpacing = 0;
  117. t_col = 1;
  118. msg_ta.rows = 30;
  119. }
  120. if ( url_cur.indexOf(url_clan)!=-1 ) {
  121. var max_chars_ta = 9800;
  122. td_ta.className = "wbwhite";
  123. td_ta.style.borderTopWidth = "0px";
  124. msg_ta.parentNode.style.borderBottomWidth = "0px";
  125. t_col = 1;
  126. msg_ta.rows = 30;
  127. }
  128. if ( url_cur.indexOf(url_clan_sms)!=-1 ) {
  129. msg_th = msg_th.querySelector("input[type='text']");
  130. msg_th.style.width = "100%";
  131. var max_chars_th = 70;
  132. var max_chars_ta = 3900;
  133. msg_body = msg_body_sms;
  134. t_col = 2;
  135. msg_ta.rows = 20;
  136. msg_ta.style.width = 900;
  137. }
  138. //====================Text generation====================
  139. if ( (url_cur.indexOf(url_sms)!=-1) || (url_cur.indexOf(url_clan_sms)!=-1) || (url_cur.indexOf(url_newmsg)!=-1) ) {
  140. sp_th.innerHTML = msg_head + used_smb + "0" + chars_of + max_chars_th;
  141. td_th.colSpan = t_col;
  142. sp_th.style.marginLeft = "25";
  143. sp_th.style.fontSize = "12px";
  144. }
  145. sp_ta.innerHTML = msg_body + used_smb + "0" + chars_of + max_chars_ta;
  146. td_ta.colSpan = t_col;
  147. sp_ta.style.marginLeft = "25";
  148. sp_ta.style.fontSize = "12px";
  149. //====================Inserting nod blocks into a document====================
  150. if ( (url_cur.indexOf(url_sms)!=-1) || (url_cur.indexOf(url_clan_sms)!=-1) || (url_cur.indexOf(url_newmsg)!=-1) ) {
  151. insertAfter(msg_ta, tr_ta, tr_th);
  152. countCharsChange_th();
  153. } else {
  154. insertAfter(msg_ta, tr_ta);
  155. }
  156. countCharsChange_ta();
  157. //====================Keypress listener====================
  158. if ( (url_cur.indexOf(url_sms)!=-1) || (url_cur.indexOf(url_clan_sms)!=-1) || (url_cur.indexOf(url_newmsg)!=-1) ) {
  159. addEvent( msg_th, "keydown", countChars_th );
  160. addEvent( msg_th, "click", countChars_th );
  161. addEvent( msg_th, "change", countChars_th );
  162. addEvent( msg_th, "mouseout", countChars_th );
  163. addEvent( msg_th, "mouseover", countChars_th );
  164. }
  165. addEvent( msg_ta, "keydown", countChars_ta );
  166. addEvent( msg_ta, "click", countChars_ta );
  167. //====================Functions====================
  168. function insertAfter(parent, node, node2) {
  169. if ( url_cur.indexOf(url_sett)==-1 ) {
  170. while ( parent.tagName != 'TR' ) { parent = parent.parentNode; }
  171. }
  172. parent.parentNode.insertBefore(node, parent.nextSibling);
  173. if ( node2 ) { parent.parentNode.insertBefore(node2, parent.nextSibling); }
  174. }
  175. function countChars_th() {
  176. setTimeout( function() { countCharsChange_th(); }, 100 ); // workaround for pasting from clipboard
  177. }
  178. function countChars_ta() {
  179. setTimeout( function() { countCharsChange_ta(); }, 100 );
  180. }
  181. function countCharsChange_th() {
  182. sp_th.innerHTML = msg_head + used_smb + msg_th.value.length + chars_of + max_chars_th;
  183. sp_th.style.backgroundColor = ( msg_th.value.length > max_chars_th ) ? "#fcc" : "";
  184. }
  185. function countCharsChange_ta() {
  186. sp_ta.innerHTML = msg_body + used_smb + msg_ta.value.length + chars_of + max_chars_ta;
  187. sp_ta.style.backgroundColor = ( msg_ta.value.length > max_chars_ta ) ? "#fcc" : "";
  188. }
  189. function $(id) { return document.querySelector("#"+id); }
  190. function addEvent(elem, evType, fn) {
  191. if (elem.addEventListener) {
  192. elem.addEventListener(evType, fn, false);
  193. }
  194. else if (elem.attachEvent) {
  195. elem.attachEvent("on" + evType, fn);
  196. }
  197. else {
  198. elem["on" + evType] = fn;
  199. }
  200. }
  201. function update_n(a,b,c,d,e){if(e){e++}else{e=1;d=(Number(GM_getValue(b+'_update_script_last2','0'))||0)}if(e>3){return}var f=new Date().getTime();var g=document.querySelector('#update_demin_script2');if(g){if((d+86400000<f)||(d>f)){g=g.innerHTML;if(/100000=1.1/.exec(g)){var h=new RegExp(b+'=(\\d+\\.\\d+)=(\\d+)').exec(g);var i=/url7=([^%]+)/.exec(g);if(a&&h&&i){if(Number(h[1])>Number(a))setTimeout(function(){if(confirm('\u0414\u043E\u0441\u0442\u0443\u043F\u043D\u043E \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u0438\u0435 \u0441\u043A\u0440\u0438\u043F\u0442\u0430: "'+c+'".\n\u0423\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u044C \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u0443\u044E \u0432\u0435\u0440\u0441\u0438\u044E \u0441\u0435\u0439\u0447\u0430\u0441?\n\nThere is an update available for the script: "'+c+'".\nWould you like install the script now?')){if(typeof GM_openInTab=='function'){GM_openInTab(i[1].replace(/\s/g,'')+h[2])}else{window.open(i[1].replace(/\s/g,'')+h[2],'_blank')}}},500)}GM_setValue(b+'_update_script_last2',''+f)}else{setTimeout(function(){update_n(a,b,c,d,e)},1000)}}}else{var j=document.querySelector('body');if(j){var k=GM_getValue(b+'_update_script_array2');if(e==1&&((d+86400000<f)||(d>f)||!k)){if(k){GM_deleteValue(b+'_update_script_array2')}setTimeout(function(){update_n(a,b,c,d,e)},1000);return}var l=document.createElement('div');l.id='update_demin_script2';l.setAttribute('style','position: absolute; width: 0px; height: 0px; top: 0px; left: 0px; display: none;');l.innerHTML='';j.appendChild(l);if((d+86400000<f)||(d>f)||!k){var m=new XMLHttpRequest();m.open('GET','photo_pl_photos.php?aid=1777'+'&rand='+(Math.random()*100),true);m.onreadystatechange=function(){update(m,a,b,c,d,e)};m.send(null)}else{document.querySelector('#update_demin_script2').innerHTML=k;setTimeout(function(){update_n(a,b,c,d,e)},10)}}}}function update(a,b,c,d,e,f){if(a.readyState==4&&a.status==200){a=a.responseText;var g=/(\d+=\d+\.\d+(=\d+)*)/g;var h='';var i=/(url7=[^%]+\%)/.exec(a);if(i){h+=i[1]}while((i=g.exec(a))!=null){if(h.indexOf(i[1])==-1){h+=' '+i[1]}};GM_setValue(c+'_update_script_array2',''+h);var j=document.querySelector('#update_demin_script2');if(j){j.innerHTML=h;setTimeout(function(){update_n(b,c,d,e,f)},10)}}}
  202. })();