Shoutbox

Shoutbox - Wyze

  1. // ==UserScript==
  2. // @name Shoutbox
  3. // @namespace https://realitygaming.fr
  4. // @version 1.1
  5. // @description Shoutbox - Wyze
  6. // @author Eh Eh
  7. // @match https://realitygaming.fr/chatbox/*
  8. // @grant none
  9. // ==/UserScript==
  10. var scc = {
  11. color: "#C2EAFF",
  12. notif: true,
  13. bot: false,
  14. lastRP: Date.now(),
  15. lastH: 0
  16. };
  17. var rP = {
  18. rep1: {title:"",msg:""},
  19. rep2: {title:"",msg:""},
  20. rep3: {title:"",msg:""},
  21. rep4: {title:"",msg:""},
  22. rep5: {title:"",msg:""}
  23. };
  24. var customChat = {
  25. msgID: [],
  26. __msgID: [],
  27. username: $('.accountUsername').text(),
  28. template_Button: '<div id="customChat_op" style="font-style:none;float:right;cursor:pointer;" class="fa fa-bars"></div>',
  29. template_Html: '<div id="customChat_op" data-role="blk" style="width:100%;height:100%;position:fixed;z-index:2147483645;background-color:rgba(0,0,0,0.2);opacity:0;display:none;"></div><div style="right: -800px;position: fixed;" class="customChat"><div class="customChat_header" style="background-color:#2F78A0"><div class="customChat_close" style="background-image:url()"></div><div class="customChat_header_text" style="margin-top: 40px;">CustomChat</div><div class="customChat_header_message">by Wayz</div></div><div class="customChat_middle_wrapper"><div class="customChat_middle"><div><input class="customChat_btn" id="hello" type="button"/><label for="hello"> Hello ! </label></div><br/><div><input class="customChat_btn" id="rep_pred" type="button"/><label for="rep_pred"> Message prédéfini </label></div><br/><div><input class="customChat_cb" id="notif" type="checkbox" checked=""/><label for="notif"><span class="ui"></span> Activer les notifications </label></div><br/><br/><div><input class="customChat_cb" id="bot" type="checkbox"/><label for="bot"><span class="ui"></span> Activer le pseudo BOT </label></div></div></div></div><div class="customChat_reponse" style="right:-800px;"><div class="customChat_rep_wrapper"><ul class="customChat_pred"><li class="customChat_a"><a id="customChat_rP" data-msg="" data-num="1" href="javascript:void(0);">Message 1</a></li><li class="customChat_a"><a id="customChat_rP" data-msg="" data-num="2" href="javascript:void(0);">Message 2</a></li><li class="customChat_a"><a id="customChat_rP" data-msg="" data-num="3" href="javascript:void(0);">Message 3</a></li><li class="customChat_a"><a id="customChat_rP" data-msg="" data-num="4" href="javascript:void(0);">Message 4</a></li><li class="customChat_a"><a id="customChat_rP" data-msg="" data-num="5" href="javascript:void(0);">Message 5</a></li><li class="customChat_a"><a id="customChat_del-rP" href="javascript:void(0);">Supprimer un message</a></li><li class="customChat_a"><a id="customChat_timer-rP" href="javascript:void(0);">Dernier message envoyé il y a NaN</a></li></ul></div></div>',
  30. template_Css: "<style id=\"css_cc\">.customChat{position:fixed;width:300px;height:100%;right:-420px;top:0;color:#000;z-index:2147483647;font-family:myriad-pro,sans-serif;text-align:left;line-height:1.2;user-select:none!important;-khtml-user-select:none!important;-o-user-select:none!important;-moz-user-select:-moz-none!important;-webkit-user-select:none!important;-webkit-transition:all .35s linear;-moz-transition:all .35s linear;-o-transition:all .35s linear;transition:all .35s linear}.customChat .customChat_header{position:absolute;height:230px;width:240px;padding:0 30px;top:0;left:0;overflow:hidden;border-left:1px solid rgba(0,0,0,.2);box-sizing:content-box}.customChat .customChat_header .customChat_header_text{width:100%;height:35px;padding-top:15px;text-align:center;color:#fff;font-family:\"Source Sans Pro\",sans-serif;font-size:25px;font-weight:lighter}.customChat .customChat_header .customChat_header_message{text-align:center;color:#fff;font-family:\"Source Sans Pro\",sans-serif;font-size:13px;font-weight:lighter}.customChat .customChat_middle_wrapper{height:auto;top:230px;bottom:0;width:100%;position:absolute;z-index:-2;border-left:1px solid rgba(0,0,0,.2);background-color:rgb(245,245,245)}.customChat>.customChat_middle_wrapper>.customChat_middle{background-color:#fff;position:absolute;top:0;left:0;width:100%;padding:10%;border-bottom:1px solid #dfdfdf;box-sizing:border-box;overflow:auto;max-height:100%}.customChat_pred{list-style:none;padding:4px;margin:0;background:#FEFEFE}.customChat_a a{display:block;margin:1px 0;padding:8px 20px;color:#34495E;background:#FFF;text-decoration:none;-webkit-transition:all .3s;-moz-transition:all .3s;transition:all .3s}.customChat_a a:focus,.customChat_a a:hover{background:#2F78A0;color:#FFF;padding-left:25px}.customChat_reponse{position:fixed;width:600px;height:100%;right:0px;top:0;color:#000;z-index:2147483646;font-family:myriad-pro,sans-serif;text-align:left;line-height:1.2;user-select:none!important;-khtml-user-select:none!important;-o-user-select:none!important;-moz-user-select:-moz-none!important;-webkit-user-select:none!important;-webkit-transition:all .35s linear;-moz-transition:all .35s linear;-o-transition:all .35s linear;transition:all .35s linear;margin-top:229px;}.customChat_rep_wrapper{background-color:#fff;position:absolute;top:0;left:0;width:100%;border:1px solid #dfdfdf;box-sizing:border-box;overflow:auto;max-height:50%;max-width:100%}.customChat_cb[type=checkbox]:checked,.customChat_cb[type=checkbox]:not(:checked){position:absolute;left:-9999px}.customChat_cb[type=checkbox]:checked+label,.customChat_cb[type=checkbox]:not(:checked)+label{position:relative;padding-left:75px;cursor:pointer}.customChat_cb[type=checkbox]:checked+label:after,.customChat_cb[type=checkbox]:checked+label:before,.customChat_cb[type=checkbox]:not(:checked)+label:after,.customChat_cb[type=checkbox]:not(:checked)+label:before{content:'';position:absolute}.customChat_cb[type=checkbox]:checked+label:before,.customChat_cb[type=checkbox]:not(:checked)+label:before{left:0;top:-3px;width:65px;height:30px;background:#DDD;border-radius:15px;-webkit-transition:background-color .2s;-moz-transition:background-color .2s;-ms-transition:background-color .2s;transition:background-color .2s}.customChat_cb[type=checkbox]:checked+label:after,.customChat_cb[type=checkbox]:not(:checked)+label:after{width:20px;height:20px;-webkit-transition:all .2s;-moz-transition:all .2s;-ms-transition:all .2s;transition:all .2s;border-radius:50%;background:#7F8C9A;top:2px;left:5px}.customChat_cb[type=checkbox]:checked+label:before{background:#34495E}.customChat_cb[type=checkbox]:checked+label:after{background:#6AD2EF;top:2px;left:40px}.customChat_cb[type=checkbox]:checked+label .ui,.customChat_cb[type=checkbox]:checked+label .ui:after,.customChat_cb[type=checkbox]:not(:checked)+label .ui:before{position:absolute;left:6px;width:65px;border-radius:15px;font-size:14px;font-weight:700;line-height:22px;-webkit-transition:all .2s;-moz-transition:all .2s;-ms-transition:all .2s;transition:all .2s}.customChat_cb[type=checkbox]:not(:checked)+label .ui:before{content:'Non';left:32px}.customChat_cb[type=checkbox]:checked+label .ui:after{content:'Oui';color:#6AD2EF}.customChat_btn[type=button]{background-color:#6AD2EF;border-radius:15px;border:5px solid #34495E;width:65px;height:30px;cursor:pointer;margin-right:5px;-webkit-transition:all .3s;-moz-transition:all .3s;-ms-transition:all .3s;transition:all .3s}label{color:#34495E}.customChat_btn[type=button]:hover{background-color:#4DAEC9}</style>", // base checkbox by @geoffrey_crofte
  31. template_Js: '<script id="js_cc">$("#rep_pred").click(function(){var s=$(".customChat_reponse");s.hasClass("visible")?($(this).css("backgroundColor","#6AD2EF"),s.animate({right:"-1000px"},200).removeClass("visible")):(s.animate({right:"0px"},200).addClass("visible"),$(this).css("backgroundColor","#4993BC"))}),$("div#customChat_op").click(function(){var s=$(".customChat"),a=$(".customChat_reponse"), z=$("#modal_js");s.hasClass("visible")?(s.animate({right:"-1000px"},200).removeClass("visible"),a.animate({right:"-1000px"},200).removeClass("visible"),z.css("display", "none"),$("#rep_pred").css("backgroundColor","#6AD2EF"),$(\'div#customChat_op[data-role="blk"]\').animate({opacity:"0"},200,"swing",function(){$(\'div#customChat_op[data-role="blk"]\').css("display","none")})):(s.animate({right:"0px"},200).addClass("visible"),$(\'div#customChat_op[data-role="blk"]\').animate({opacity:"1"},200,"swing",function(){$(\'div#customChat_op[data-role="blk"]\').css("display","block")}))});</script>',
  32. template_M: '<div id="modal_js" style="display:none;width:600px;background-color:#fefefe;border:1px solid rgba(0, 0, 0, 0.2);border-radius:5px;-webkit-box-shadow: 0px 0px 15px rgba(0,0,0,0.3);-moz-box-shadow: 0px 0px 15px rgba(0,0,0,0.3);box-shadow: 0px 0px 15px rgba(0,0,0,0.3);z-index:9854136598742"><div id="modal_js_head" style="border-bottom:1px solid rgba(0, 0, 0, 0.2);padding:10px 15px 10px 15px;"></div><div id="modal_js_body" style="padding:15px;"></div><div id="modal_js_footer" style="border-top:1px solid rgba(0, 0, 0, 0.2);padding:10px 15px 25px 15px;text-align:right;"><input type="button" id="modal_js_cancel" class="button primary" value="Annuler" /><input type="button" id="modal_js_save" class="button" value="Sauvegarder" /></div></div>',
  33. init: function(){
  34. setInterval(function(){customChat.checkNewMsg();}, 250);
  35. if(location.pathname.indexOf('chatbox') != -1) {
  36. $('#taigachat_controls').append(this.template_Button);
  37. $('#customChat_op.fa.fa-bars').attr('style', 'font-style:none;float:right;cursor:pointer;font-size:24px;padding-right:10px;');
  38. }
  39. else {
  40. $('#taigachat_full').find('.nodeTitle').append(this.template_Button);
  41. }
  42. $('body').prepend(this.template_Html);
  43. $('body').prepend(this.template_Css);
  44. $('body').prepend(this.template_Js);
  45. $('body').prepend(this.template_M);
  46. var $notif = $('#notif[type=checkbox]');
  47. $notif.on('change', function(){
  48. scc.notif = $(this).is(':checked');
  49. customChat.save();
  50. });
  51. var $bot = $('#bot[type=checkbox]');
  52. $bot.on('change', function(){
  53. scc.bot = $(this).is(':checked');
  54. customChat.save();
  55. });
  56. var $hello = $('#hello[type=button]');
  57. $hello.on('click', function() {
  58. customChat.hello();
  59. customChat.save();
  60. });
  61. var $rep = $('a#customChat_rP');
  62. $rep.on('click', function(){
  63. if($(this).data('msg').length > 4) {
  64. scc.lastRP = Date.now();
  65. var $input = $('#taigachat_message');
  66. $input.val(($input.val().trim().length>1?$input.val().trim()+" ":"") + customChat.decode_b64($(this).data('msg')));
  67. customChat.save();
  68. }
  69. else {
  70. customChat.add_rP($(this));
  71. }
  72. });
  73. var $rep_del = $('a#customChat_del-rP');
  74. $rep_del.on('click', function(){
  75. customChat.del_rP();
  76. });
  77. (function($){
  78. $.fn.extend({
  79. center: function () {
  80. return this.each(function() {
  81. var top = ($(window).height() - $(this).outerHeight()) / 2;
  82. var left = ($(window).width() - $(this).outerWidth()) / 2;
  83. $(this).css({position:'absolute', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
  84. });
  85. }
  86. });
  87. })(jQuery);
  88. this.load();
  89. },
  90. encode_b64: function(str) {
  91. return window.btoa(encodeURIComponent(escape(str)));
  92. },
  93. decode_b64: function(str) {
  94. return unescape(decodeURIComponent(window.atob(str)));
  95. },
  96. save: function(){
  97. var settings_scc = JSON.stringify(scc);
  98. var settings_rP = JSON.stringify(rP);
  99. localStorage.setItem('settings_scc', settings_scc);
  100. localStorage.setItem('settings_rP', settings_rP);
  101. },
  102. load: function(){
  103. var a = localStorage.getItem("settings_scc");
  104. if(a){
  105. var b = Object.keys(scc);
  106. var c = JSON.parse(a);
  107. for(var i in b){
  108. if(c[b[i]] == undefined){
  109. this.save();
  110. }
  111. else {
  112. scc[b[i]] = c[b[i]];
  113. }
  114. }
  115. }
  116. else {
  117. this.save();
  118. }
  119. var z = localStorage.getItem("settings_rP");
  120. if(z){
  121. var b = Object.keys(rP);
  122. var c = JSON.parse(z);
  123. for(var i in b){
  124. if(c[b[i]] == undefined){
  125. this.save();
  126. }
  127. else {
  128. rP[b[i]] = c[b[i]];
  129. }
  130. }
  131. }
  132. else {
  133. this.save();
  134. }
  135. for(var i in rP){
  136. if(rP[i].title.length > 1 && rP[i].msg.length > 1){
  137. var num = i.substr(3);
  138. $('#customChat_rP[data-num="' + num + '"]').text(customChat.decode_b64(rP[i].title));
  139. $('#customChat_rP[data-num="' + num + '"]').data('msg', rP[i].msg);
  140. }
  141. }
  142. $('#notif[type=checkbox]').prop('checked', scc.notif);
  143. $('#bot[type=checkbox]').prop('checked', scc.bot);
  144. setInterval(function(){customChat.lastRP();}, 2000);
  145. },
  146. notify: function(msg) {
  147. if(scc.notif){
  148. if(!("Notification"in window)){console.error("Ce navigateur ne supporte pas les notifications !")}else if(Notification.permission==="granted"){var notification=new Notification(msg, {icon: 'http://realitygaming.fr/attachments/rg-png.14121/'})}else if(Notification.permission!=="denied"){Notification.requestPermission(function(e){if(!("permission"in Notification)){Notification.permission=e}if(e==="granted"){var t=new Notification(msg, {icon: 'http://realitygaming.fr/attachments/rg-png.14121/'})}})}
  149. }
  150. else {
  151. console.log('notif disable')
  152. }
  153. },
  154. checkNewMsg: function(){
  155. var msg = $('#taigachat_box').children('ol').children('li');
  156. for(var i in msg) {
  157. var id = msg.eq(i).data('messageid');
  158. var msg_text = $('#taigachat_box').children('ol').children('li[data-messageid="' + id + '"]').children('span').eq(1).children('div').text().trim();
  159. var msg_sender = $('#taigachat_box').children('ol').children('li[data-messageid="' + id + '"]').children('span').eq(1).children('a').text().trim();
  160. if(this.msgID.indexOf(id) == -1 && msg_text.indexOf(this.username) != -1) {
  161. this.msgID.unshift(id);
  162. this.newMsg(id);
  163. }
  164. else if(this.__msgID.indexOf(id) == -1 && msg_sender == this.username && scc.bot){
  165. $('#taigachat_box').children('ol').children('li[data-messageid="' + id + '"]').children('span').eq(1).children('a').children('span').attr('class', 'style10');
  166. this.__msgID.unshift(id);
  167. }
  168. }
  169. },
  170. newMsg: function(id) {
  171. $('#taigachat_box').children('ol').children('li[data-messageid="' + id + '"]').css('backgroundColor', scc.color);
  172. var msg = $('#taigachat_box').children('ol').children('li[data-messageid="' + id + '"]').children('span').eq(1).children('div').text().trim();
  173. var sender = $('#taigachat_box').children('ol').children('li[data-messageid="' + id + '"]').children('span').eq(1).children('a').text().trim();
  174. this.notify(sender + " - " + msg);
  175. },
  176. hello: function() {
  177. if((Date.now() - scc.lastH) >= 3600000){
  178. scc.lastH = Date.now();
  179. var user1 = $('#taigachat_box').children('ol').children('li').eq(5).children('span').eq(1).children('a').text();
  180. var user2 = $('#taigachat_box').children('ol').children('li').eq(17).children('span').eq(1).children('a').text();
  181. var user3 = $('#taigachat_box').children('ol').children('li').eq(23).children('span').eq(1).children('a').text();
  182. var userinchat = $('#taigachat_count').text();
  183. $("#taigachat_message").val("Salut à @" + user1 + " , @" + user2 + " , @" + user3 + " et aux " + userinchat + " membres actuellement sur le chat :)");
  184. this.save();
  185. }
  186. else{
  187. alert('Vous avez utilisé cette fonction il y a moins d\'un heure !');
  188. }
  189. },
  190. lastRP: function(){
  191. var ms = Date.now() - scc.lastRP,
  192. // http://stackoverflow.com/a/19700358
  193. seconds = parseInt((ms/1000)%60),
  194. minutes = parseInt((ms/(1000*60))%60),
  195. hours = parseInt((ms/(1000*60*60))%24);
  196.  
  197. hours = (hours < 10) ? "0" + hours : hours;
  198. minutes = (minutes < 10) ? "0" + minutes : minutes;
  199. seconds = (seconds < 10) ? "0" + seconds : seconds;
  200.  
  201. var time = hours + ":" + minutes + ":" + seconds;
  202. $('#customChat_timer-rP').text('Dernier message envoyé il y a ' + time);
  203. },
  204. modal: function(title, body){
  205. $('#modal_js').css('display', 'block');
  206. $('#modal_js').center();
  207. $('#modal_js_head').html('<h2 style="font-family: \'Open Sans Condensed\',\'Arial\',sans-serif; font-size: 12pt; color: rgb(52, 73, 94);">' + title + '</h2>');
  208. $('#modal_js_body').html(body);
  209. },
  210. add_rP: function($rep){
  211. this.modal('Ajouter une réponse', '<input id="modal_js_rep_title" class="textCtrl" style="width:100%;height:20px;" placeholder="Entrez le titre du message" /><br/><br/><input id="modal_js_rep_body" class="textCtrl" style="width:100%;height:20px;" placeholder="Entrez le contenu du message" />');
  212. var is_add = true;
  213. $('#modal_js_save').on('click', function(){
  214. if(is_add){
  215. var rep_msg = $('#modal_js_rep_body').val().trim();
  216. var rep_title = $('#modal_js_rep_title').val().trim();
  217. if(rep_title.length > 2) {
  218. if(rep_msg.length > 4) {
  219. var cR = $rep.data('num');
  220. rP['rep' + cR].title = customChat.encode_b64(rep_title);
  221. rP['rep' + cR].msg = customChat.encode_b64(rep_msg);
  222. $('#modal_js').css('display', 'none');
  223. $rep.text(rep_title);
  224. $rep.data('msg', customChat.encode_b64(rep_msg));
  225. customChat.save();
  226. is_add = false;
  227. }
  228. else {
  229. alert('Votre message n\'est pas assez long !');
  230. }
  231. }
  232. else {
  233. alert('Votre titre n\'est pas assez long !');
  234. }
  235. }
  236. });
  237. $('#modal_js_cancel').on('click', function(){
  238. if(is_add){
  239. $('#modal_js').css('display', 'none');
  240. is_add = false;
  241. }
  242. });
  243. },
  244. del_rP: function(){
  245. this.modal('Entrer le chiffre de la réponse à supprimer', '<input id="modal_js_rep_num" class="textCtrl" style="width:100%;height:20px;" placeholder="Chiffre de la réponse à supprimer" /><br/>');
  246. var is_del = true;
  247. $('#modal_js_save').on('click', function(){
  248. if(is_del){
  249. var rep_num = $('#modal_js_rep_num').val().trim();
  250. if(rep_num > 0 && rep_num < 6){
  251. $('#customChat_rP[data-num="' + rep_num + '"]').text("Message " + rep_num);
  252. $('#customChat_rP[data-num="' + rep_num + '"]').data('msg', "");
  253. rP['rep' + rep_num].title = "";
  254. rP['rep' + rep_num].msg = "";
  255. $('#modal_js').css('display', 'none');
  256. customChat.save();
  257. is_del = false;
  258. }
  259. }
  260. });
  261. $('#modal_js_cancel').on('click', function(){
  262. if(is_del){
  263. $('#modal_js').css('display', 'none');
  264. is_del = false;
  265. }
  266. });
  267. }
  268. };
  269.  
  270. customChat.init();