Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.56 KB | None | 0 0
  1. // ==UserScript==
  2. // @name TORN : Chat Blocker & Highlighter
  3. // @namespace chatblocker
  4. // @version 4.3
  5. // @description Chat Blocker. Add spammer/scammer/troller to block them appear in all chat(company/faction/global/trade). And Highlighter
  6. // @author Mafia[610357]
  7. // @match https://www.torn.com/*
  8. // @require http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js
  9. // @grant GM_addStyle
  10. // @grant GM_getResourceText
  11. // ==/UserScript==
  12. jQuery.expr[':'].highlight = function(a, i, m) {
  13. return jQuery(a).text().toUpperCase()
  14. .indexOf(m[3].toUpperCase()) >= 0;
  15. };
  16.  
  17. GM_addStyle(`.licolor input { width: 15px; height: 18px; margin: 7px; background-color: transparent; cursor: pointer;}`);
  18.  
  19. (function () {
  20. 'use strict';
  21. var chatblocklist = JSON.parse(localStorage.chatblocklist || '[]');
  22. var chatcolor = JSON.parse(localStorage.chatcolor || '{"selfcolor":"#0080c0","highlight":"#ffffbf"}');
  23. var uid = $("script[src*='js/chat/chat']").attr("uid");
  24. var name = $("script[src*='js/chat/chat']").attr("name");
  25.  
  26. if(!chatcolor.uid || chatcolor.name != name){
  27. chatcolor.uid = uid;
  28. chatcolor.name = name;
  29. }
  30.  
  31. var highlight = function() {
  32. $("div[class^='chat-box_'] div[class^='message'] a[href$='"+chatcolor.uid+"']").css("color", chatcolor.selfcolor);
  33. var arr = (!chatcolor.txthighlight ? chatcolor.name : (chatcolor.name + "," + chatcolor.txthighlight).replace(/,\s*$/, "")).split(",");
  34. $.each(arr, function() {
  35. var item = $.trim(this);
  36. $("div[class^='chat-box_'] div[class^='message'] span:highlight("+item+")").parent().css({"background-color": chatcolor.highlight, "border-top": "1px dashed #000", "border-bottom": "1px dashed #000", "padding": "0px 5px"});
  37. });
  38. $("div[class^='chat-box_'] div[class^='message'] span:highlight("+chatcolor.name+")").parent().css({"background-color": chatcolor.highlight, "border-top": "1px dashed #000", "border-bottom": "1px dashed #000", "padding": "0px 5px"});
  39.  
  40. if(chatcolor.users) {
  41. $.each(chatcolor.users, function(id){
  42. $("div[class^='chat-box_'] div[class^='message'] a[href$='="+id+"']").css("color", this);
  43. });
  44. }
  45. }
  46.  
  47. var observerTarget = $("#chatRoot")[0];
  48. var observerConfig = { attributes: false, childList: true, characterData: false, subtree: true };
  49. var observer = new MutationObserver(function(mutations) {
  50.  
  51. highlight();
  52.  
  53. if($("a:contains('Blocked')").closest("li").is("[class*='active']")) {
  54. chatblocklist = [];
  55. $.each($("ul[class^='people-list_'] li a[class^='user-name-id_']"), function(){
  56. var id = parseInt($(this).attr("href").match(/\d+/));
  57. chatblocklist.push(id);
  58. });
  59.  
  60. localStorage.chatblocklist = JSON.stringify(chatblocklist);
  61. }
  62.  
  63. if($("a:contains('Friends')").closest("li").is("[class*='active']") || $("a:contains('Faction')").closest("li").is("[class*='active']") || $("a:contains('Company')").closest("li").is("[class*='active']")) {
  64.  
  65. if($(".viewport .overview ul.ui-autocomplete li").length && !$(".viewport .overview ul.ui-autocomplete li input").length) {
  66. observer.disconnect();
  67. GM_addStyle('.viewport .overview ul.ui-autocomplete li a { display: contents !important; } .viewport .overview ul.ui-autocomplete li input { cursor: crosshair; }');
  68. $.each($(".viewport .overview ul.ui-autocomplete li"), function(){
  69. $(this).append('<input type="color" style=" width: 14px; height: 18px; background-color: transparent; float: right; vertical-align: middle;">');
  70. });
  71.  
  72. if(chatcolor.users) {
  73. $.each(chatcolor.users, function(id){
  74. // console.log($(".viewport .overview ul.ui-autocomplete li a:contains(["+id+"])").length);
  75. $(".viewport .overview ul.ui-autocomplete li a:contains(["+id+"])").parent().css("color", this).find("input").val(this);
  76. });
  77. }
  78.  
  79. $(".viewport .overview ul.ui-autocomplete li input").change(function(){
  80. if(!chatcolor.users) chatcolor.users = {};
  81. var id = parseInt($(this).closest("li").find("a").text().match(/([0-9]*?)\]/)[0]);
  82. console.log($(this).closest("li").find("a").text(),id);
  83. chatcolor.users[id] = $(this).val();
  84. $("ul[class^='people-list_'] li a[href$='"+id+"']").css("color", $(this).val());
  85. $("ul[class^='people-list_'] li a[href$='"+id+"']").parent().find(".licolor input").val($(this).val());
  86. localStorage.chatcolor = JSON.stringify(chatcolor);
  87. highlight();
  88. return 0;
  89. });
  90. observer.observe(observerTarget, observerConfig);
  91. }
  92.  
  93. if($("ul[class^='people-list_'] li").length) {
  94. if(!$("span.licolor").length) {
  95. GM_addStyle('span.' + $("span[class^='ellipsis']").attr("class") + ' {max-width: 160px !important;}');
  96. observer.disconnect();
  97.  
  98.  
  99. $.each($("ul[class^='people-list_'] li"), function(){
  100. $(this).append('<span class="'+$("ul[class^='people-list_'] li span[class^='i-wrap']").attr("class")+' licolor"><input type="color"/></span>');
  101. });
  102.  
  103.  
  104. if(chatcolor.users) {
  105. $.each(chatcolor.users, function(id){
  106. $("ul[class^='people-list_'] li a[href$='"+id+"']").css("color", this).parent().find(".licolor input").val(this);
  107. });
  108. }
  109.  
  110. $(".licolor input").change(function(){
  111. if(!chatcolor.users) chatcolor.users = {};
  112. chatcolor.users[parseInt($(this).closest("li").find("a").attr("href").match(/\d+/)[0])] = $(this).val();
  113. $(this).closest("li").find("a").css("color", $(this).val());
  114. localStorage.chatcolor = JSON.stringify(chatcolor);
  115. highlight();
  116. });
  117. }
  118. observer.observe(observerTarget, observerConfig);
  119. }
  120. }
  121.  
  122. if($("div[class^='chat-settings-opts_']").length) {
  123. if(!$("div:contains(Name Color)").length) {
  124. $("div[class^='chat-opt-label']:contains(Company)").parent().prepend(`
  125. <div>
  126. <div class="${$("div[class^='chat-opt-label']:contains(Company)").attr("class")}">Name Color</div>
  127. <div class="${$("div[class^='chat-opt-value_'").attr("class")}">
  128. <div class="${$("div[class^='dropdown-root_']").attr("class")}">
  129. <input type="color" id="selfcolor" value="${chatcolor.selfcolor}" />
  130. <i class="top-page-icon refresh-icon" title="Reset colors" id="iresetc"></i>
  131. </div>
  132. </div>
  133. <div class="clear"></div>
  134. </div>
  135.  
  136. <div>
  137. <div class="${$("div[class^='chat-opt-label']:contains(Company)").attr("class")}">Highlight</div>
  138. <div class="${$("div[class^='chat-opt-value_'").attr("class")}">
  139. <div class="${$("div[class^='dropdown-root_']").attr("class")}">
  140. <input type="color" id="highlight" value="${chatcolor.highlight}" title="your name permanently highlighted" />
  141. <input id="txthighlight" type="text" title="add some words to highlight (in comma seperated) like xanax, vico, etc.." placeholder="xanax, vico, edvd" style="width: 88px;height: 24px;padding: 0px 7px;" value="${chatcolor.txthighlight || ""}">
  142. </div>
  143. </div>
  144. <div class="clear"></div>
  145. </div>`);
  146.  
  147. $("#selfcolor,#highlight").change(function(){
  148. chatcolor[$(this).attr("id")] = $(this).val();
  149. localStorage.chatcolor = JSON.stringify(chatcolor);
  150. highlight();
  151. });
  152.  
  153. $("#txthighlight").change(function(){
  154. chatcolor.txthighlight = $(this).val();
  155. localStorage.chatcolor = JSON.stringify(chatcolor);
  156. $("div[class^='message']").removeAttr("style");
  157. highlight();
  158. });
  159.  
  160. $("#iresetc").css("cursor", "pointer").click(function(){
  161. if(confirm("Are you sure to reset all color settings ? (all names colors and highlight settings)")) {
  162. localStorage.removeItem("chatcolor");
  163. location.reload();
  164. }
  165. });
  166. }
  167. }
  168.  
  169. $.each($("div[class^='message_'] a"), function() {
  170. if(chatblocklist.indexOf(parseInt($(this).attr("href").match(/\d+/))) != -1 && $(this).parent().is(":visible")) {
  171. $(this).parent().hide();
  172. }
  173.  
  174. if(chatblocklist.indexOf(parseInt($(this).attr("href").match(/\d+/))) == -1 && $(this).parent().is(":hidden")) {
  175. $(this).parent().show();
  176. }
  177.  
  178. });
  179.  
  180.  
  181. });
  182. observer.observe(observerTarget, observerConfig);
  183. highlight();
  184. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement