Advertisement
Guest User

Untitled

a guest
Sep 5th, 2020
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.52 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Eka's Chat Convenience Suite
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.33
  5. // @description try to take over the world!
  6. // @author Sacchi :>
  7. // @match https://rp.aryion.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. function blocklist(){
  14. //Creates a browser-stored cache of blocked users to allow easy migration between many profiles.
  15. if (window.location.href.indexOf("page=settings") === -1) return;
  16.  
  17. //content.js
  18. let ignores = localStorage.getItem('ignores');
  19. if (ignores === null) ignores = "";
  20. startup({ignores:ignores});
  21.  
  22. function startup(data){
  23. let savebutton = document.createElement("button"); savebutton.innerHTML = "Save Blocklist"; savebutton.classList.add("btn");savebutton.classList.add("btn-default"); savebutton.addEventListener("click", saveBlocks);
  24. let loadbutton = document.createElement("button"); loadbutton.innerHTML = "Load Blocklist"; loadbutton.classList.add("btn");loadbutton.classList.add("btn-default"); loadbutton.addEventListener("click", loadBlocks);
  25. let roster = document.createElement("div"); roster.setAttribute("style", "margin-top:1em"); roster.setAttribute("id", "blocklist");
  26. let inputarea = document.createElement("form"); let textfield = document.createElement("input"); textfield.setAttribute("type", "text"); textfield.setAttribute("id", "blockentry");textfield.setAttribute("style", "color:black;");
  27. let fieldbutton = document.createElement("button"); fieldbutton.innerHTML = "Input Blocklist from Text"; fieldbutton.classList.add("btn");fieldbutton.classList.add("btn-default"); fieldbutton.addEventListener("click", loadFromText);
  28. textfield.updateText = function(data){
  29. this.value = data.toString();
  30. }
  31. textfield.updateText(data.ignores);
  32. inputarea.appendChild(textfield);
  33.  
  34. let nav = document.getElementById("char-settings").getElementsByClassName("form-group")[2];
  35. nav.appendChild(savebutton);
  36. nav.appendChild(loadbutton);
  37. nav.appendChild(roster);
  38. nav.appendChild(inputarea);
  39. nav.appendChild(fieldbutton);
  40. updateBlocklist(data.ignores);
  41. }
  42.  
  43. function loadBlocks(){
  44. let ignores = localStorage.getItem('ignores');
  45. let container = document.getElementById("persistIgnore");
  46. let tagbox = document.getElementsByClassName("bootstrap-tagsinput")[1];
  47. let span = "";
  48. updateIgnoreBox(ignores);
  49.  
  50. alert("Successfully loaded blocklist. Please press Save for it to take effect.")
  51. }
  52.  
  53. function saveBlocks(){
  54. let users = new Set();
  55. let list = document.getElementById("persistIgnore").getElementsByTagName("option");
  56. for (let user = 0; user<list.length; user++){
  57. let name = list[user].textContent;
  58. users.add(name);
  59. }
  60. users = Array.from(users);
  61. updateBlocklist(users);
  62. console.log(users);
  63. localStorage.setItem('ignores', users);
  64. }
  65.  
  66. function updateIgnoreBox(ignores){
  67. if (typeof ignores === 'string'){
  68. ignores = ignores.split(",");
  69. }
  70. let container = document.getElementById("persistIgnore");
  71. let tagbox = document.getElementsByClassName("bootstrap-tagsinput")[1];
  72. let block = document.getElementById("blockentry");
  73. let finished = "";
  74. let span="";
  75. for (let i=0;i<ignores.length;i++){
  76. finished += `<option selected="selected">${ignores[i]}</option>`;
  77. finished += `<option selected="selected" value="${ignores[i]}">${ignores[i]}</option>`;
  78. span += `<span class="tag label label-info">${ignores[i]}<span data-role="remove"></span></span>`;
  79. }
  80.  
  81. tagbox.innerHTML = span + `<input size="1" type="text" placeholder="">`;
  82. container.innerHTML = finished;
  83. }
  84.  
  85. function loadFromText(){
  86. let block = document.getElementById("blockentry");
  87. if (block.value.length < 1) return;
  88.  
  89. let ignores = block.value.split(",");
  90. if (ignores.length < 1) return;
  91.  
  92. let container = document.getElementById("persistIgnore");
  93.  
  94. for (let ignore in ignores){
  95. ignores[ignore] = ignores[ignore].trim();
  96. }
  97.  
  98. updateIgnoreBox(ignores);
  99.  
  100. let users = Array.from(new Set(ignores));
  101. localStorage.setItem('ignores', users);
  102. alert("Successfully loaded from text. Please press Save.")
  103. }
  104.  
  105. function updateBlocklist(data){
  106. let blocklist = document.getElementById("blocklist");
  107. let str = "";
  108. if (typeof data === 'string'){
  109. data = data.split(",");
  110. }
  111. for (let i=0;i<data.length;i++){
  112. str += `${i+1}: ${data[i]} || `;
  113. }
  114. blocklist.innerHTML = `Your blocklist currently contains: <b>${str}</b>`;
  115. }
  116. };
  117.  
  118. function pingStopper(){
  119. //Makes it so you no longer recieve a 'ping' when a blocked user messages or mentions you.
  120. if (window.location.href.indexOf("jchat.srv") === -1) return;
  121. if (typeof handleChatMessage == "undefined") return;
  122.  
  123. handleChatMessage = function (msg){
  124. var $msg = renderChatMessage(msg);
  125.  
  126. // Open hoverboxes automatically if settings say to do so.
  127. if (me.settings.autoHoverWhispers && msg.type === "WHISPER_CHAT") {
  128. if (msg.fromMe) {
  129. HoverBoxSystem({leash: msg.to.name, type: "whisper", title: msg.to.name}).create();
  130. } else {
  131. HoverBoxSystem({leash: msg.from.name, type: "whisper", title: msg.from.name}).create();
  132. }
  133. }
  134. else if (me.settings.autoHoverGroups && msg.type === "GROUP_CHAT") {
  135. HoverBoxSystem({leash: msg.toLeash, type: "groupchat", title: msg.to.name}).create();
  136. }
  137.  
  138. HoverBoxSystem.routeToPane($msg);
  139.  
  140. // Play sound if necessary
  141. if (!ses.ignored[msg.from.id]) {
  142. if (msg.fromMe === false && msg.type === "WHISPER_CHAT") {
  143. if (me.settings.enableSound && sounds.whisper) sounds.whisper.play();
  144. }
  145. else if ($msg.hasClass("highlight")) {
  146. if (me.settings.enableSound && sounds.highlighted) sounds.highlighted.play();
  147. }
  148. else if ($msg.hasClass("nameding")) {
  149. if (me.settings.enableSound && sounds.nameding) sounds.nameding.play();
  150. }
  151. else if (msg.fromMe === false) {
  152. if (me.settings.enableSound && sounds.received) sounds.received.play();
  153. }
  154. }
  155.  
  156. // Add the title alert if window is not focused.
  157. if (window.isFocused === false
  158. && ($msg.hasClass("highlight") || $msg.hasClass("nameding"))
  159. && document.title.substr(0, TITLE_ALERT.length) !== TITLE_ALERT) {
  160. document.title = TITLE_ALERT + document.title;
  161. }
  162. }
  163. }
  164.  
  165. function profileEditFix(){
  166. //Removes the horizontal scroll bars that appear in the profile edit screen which can make editing profiles much more difficult.
  167. if (window.location.href.indexOf("page=profile") === -1) return;
  168.  
  169. const sty = document.createElement("style");
  170.  
  171. sty.textContent = `pre{overflow:hidden;}`;
  172. document.head.append(sty);
  173. }
  174.  
  175. function extraEyecons(){
  176. //Allows a user to have a total of 8 eyecons on a character. Takes effect permanently on that character once a profile is saved.
  177. if (window.location.href.indexOf("page=profile") === -1) return;
  178.  
  179. let vals = Array.from(document.getElementById("char-main").getElementsByTagName("input"));
  180. let cid = vals[0].value;
  181. let csrf = vals[1].value;
  182.  
  183. const eyeconContainer = document.getElementById("char-favcolors");
  184. const eyeconList = Array.from(eyeconContainer.getElementsByTagName("ol"))[0];
  185. const eyecons = eyeconList.getElementsByTagName("li");
  186.  
  187. function createNewEyecon(num){
  188. /**let template = `
  189. <input type="hidden" name="fc.id" value="${num}">
  190.  
  191. <div class="form-group ">
  192. <label for="fc${num}-color">Color:</label>
  193. <div class="input-group input-group-sm">
  194. <span class="input-group-addon color-sample" id="fc${num}-cs" style="color: #ffffff;">Lorem ipsum dolor sit amet</span>
  195. <input id="fc${num}-color" type="text" name="fc.textColor" value="#ffffff" data-target="#fc${num}-cs" class="colorpicker form-control input-sm" style="width: 80px;" autocomplete="off" data-original-title="" title="">
  196. </div>
  197. </div>
  198.  
  199. <div class="form-group">
  200. <label for="fc${num}-eyecon-file">Eyecon:</label>
  201. <input type="hidden" name="fc.eyecon" value="">
  202. <div class="btn btn-default btn-file btn-sm">
  203. <span>Browse</span>
  204. <input class="form-control input-sm" type="file" name="neweyecon" autocomplete="off" data-toggle="autocropper" data-modal="show" data-target="#modal-auto-cropper" data-linked-image="#fc${num}-eyecon-img" data-max-thumb-width="50" data-max-thumb-height="25" data-form-action="profileEdit.srv?action=saveFavcolorEyecon" data-form-data="{&quot;cid&quot;:${cid}, &quot;csrf&quot;:&quot;${csrf}&quot;, &quot;fc.id&quot;:&quot;${num}&quot;}">
  205. </div>
  206. <span>
  207. <img id="fc${num}-eyecon-img" src="">
  208. <a class="clear-eyecon" href="#" title="Clear Eyecon">×</a>
  209. </span>
  210.  
  211. </div>
  212. `;**/
  213.  
  214. let template = `
  215. <input type="hidden" name="fc.id" value="${num}">
  216.  
  217. <div class="form-group ">
  218. <label for="fc${num}-color">Color:</label>
  219. <div class="input-group input-group-sm">
  220. <span class="input-group-addon color-sample" id="fc4-cs" style="color: #ffffff;">Lorem ipsum dolor sit amet</span>
  221. <input id="fc$4-color" type="text" name="fc.textColor" value="#ffffff" data-target="#fc${num}-cs" class="colorpicker form-control input-sm" style="width: 80px;" autocomplete="off" data-original-title="" title="">
  222. </div>
  223. </div>
  224.  
  225. <div class="form-group">
  226. <label for="fc1-eyecon-file">Eyecon:</label>
  227. <input type="hidden" name="fc.eyecon" value="4">
  228. <div class="btn btn-default btn-file btn-sm">
  229. <span>Browse</span>
  230. <input class="form-control input-sm" type="file" name="neweyecon" autocomplete="off" data-toggle="autocropper" data-modal="show" data-target="#modal-auto-cropper" data-linked-image="#fc${num}-eyecon-img" data-max-thumb-width="50" data-max-thumb-height="25" data-form-action="profileEdit.srv?action=saveFavcolorEyecon" data-form-data="{&quot;cid&quot;:${cid}, &quot;csrf&quot;:&quot;${csrf}&quot;, &quot;fc.id&quot;:&quot;4&quot;}">
  231. </div>
  232. <span style="display: none;">
  233. <img id="fc${num}-eyecon-img">
  234. <a class="clear-eyecon" href="#" title="Clear Eyecon">×</a>
  235. </span>
  236.  
  237. </div>
  238. `;
  239.  
  240. let element = document.createElement("li");
  241. element.innerHTML = template.trim();
  242. let d = document.createElement("li");
  243. d.id="fc"+num;
  244. d.setAttribute("style","margin-bottom: 12px;");
  245. element.childNodes.forEach((x)=>d.appendChild(x));
  246. eyeconList.appendChild(d);
  247. }
  248.  
  249. if (document.getElementById("fc5") === null){
  250. createNewEyecon(5);
  251. }
  252. if (document.getElementById("fc6") === null){
  253. createNewEyecon(6);
  254. }
  255. if (document.getElementById("fc7") === null){
  256. createNewEyecon(7);
  257. }
  258. if (document.getElementById("fc8") === null){
  259. createNewEyecon(8);
  260. }
  261.  
  262.  
  263.  
  264.  
  265. }
  266.  
  267. function tempAllListFixer(){
  268. //Fixes text cutoff on the temporary all list plus small improvements to layout.
  269. if (window.location.href.indexOf("userlist.srv") === -1) return;
  270.  
  271. let style = document.createElement("style");
  272. style.textContent = `.ul-tile p.summary{overflow-y:scroll;} .ul-tile p.summary::-webkit-scrollbar{width:12px;} .ul-tile p.summary::-webkit-scrollbar-track{background-color:white;border-radius:4px;} .ul-tile p.summary::-webkit-scrollbar-thumb{background-color:#6f40bf;border-radius:3px;}`;
  273. document.head.appendChild(style);
  274.  
  275. }
  276.  
  277. function privateLogFilterModule(){
  278. //DATE: 09/05/2020
  279. //This module is designed to only take effect on the private logs menu. This module allows you to click a name to only show messages between you and that user.
  280. if (window.location.href.indexOf("privlog.srv") === -1) return;
  281.  
  282. //Initial setup to prevent clickthrough to child elements.
  283. let s = document.createElement("style");
  284. s.innerText = ".log-name *{pointer-events:none}#download-log-link{display:block;margin-left:auto;margin-right:auto;text-align:center;font-weight:bold;font-size:150%;}";
  285. document.head.appendChild(s);
  286.  
  287. //Initial setup to create log downloader button.
  288. let leftBar = document.querySelector("#left");
  289. let downloadButton = document.createElement("a");
  290. downloadButton.id = "download-log-link";
  291. downloadButton.innerText = `Download currently displayed log.`;
  292. downloadButton.download = "log";
  293. downloadButton.style.border = "4px solid #ac34a5";
  294. downloadButton.style.borderRadius = "10px";
  295. downloadButton.style.cursor = "pointer";
  296.  
  297. leftBar.prepend(downloadButton);
  298.  
  299. let filterByName = function(searchingName){
  300. let msgs = document.querySelector("#main").querySelectorAll(".chatmsg");
  301. for (let i=0;i<msgs.length;i++){
  302. if (msgs[i].children[1].innerText != searchingName && msgs[i].children[2].innerText != searchingName){
  303. msgs[i].style.display = "None";
  304. }else{
  305. msgs[i].style.display = "Block";
  306. }
  307. }
  308. }
  309.  
  310. //Event listener added to body instead of individual nodes. Since nodes are created after AJAX requests, no easy way to add onclicks without modifying native code.
  311. document.body.addEventListener("click", function(event){
  312. if(event.srcElement.classList.contains("log-name")) {
  313. let name = event.srcElement.getElementsByTagName("span")[1].innerText;
  314. filterByName(name);
  315. };
  316. let text = document.querySelector("#main").innerText;
  317. let file = window.URL.createObjectURL(new Blob([text],{type: 'text/plain'}));
  318. downloadButton.href = file;
  319. });
  320. }
  321.  
  322. function pingHighlighter(){
  323. //Date: 09/05/2020
  324. //This module is fairly simple. All it does is changes the background color of any alias-ping
  325. //messages on chat to make them easier to spot.
  326.  
  327. if (window.location.href.indexOf("jchat.srv") === -1) return;
  328.  
  329. let s = document.createElement("style");
  330. s.innerText = ".nameding{background-color:#222222}";
  331. document.head.appendChild(s);
  332. }
  333.  
  334. //If for any reason you would prefer to not have a module, you can remove it by commenting it out down below here.
  335. //All modules are completely independent so nothing should break.
  336. blocklist();
  337. pingStopper();
  338. profileEditFix();
  339. extraEyecons();
  340. tempAllListFixer();
  341. privateLogFilterModule();
  342. pingHighlighter();
  343.  
  344. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement