BS Notification

Benachrichtigung bei Erwähnung in der SB oder einer neuen PN und Userauswahl mit @ in der SB

  1. // ==UserScript==
  2. // @name BS Notification
  3. // @namespace https://bs.to/
  4. // @version 4.3.1
  5. // @description Benachrichtigung bei Erwähnung in der SB oder einer neuen PN und Userauswahl mit @ in der SB
  6. // @author Asu_nyan
  7. // @match https://bs.to/*
  8. // @match https://burningseries.co/*
  9. // @icon https://bs.to/favicon.ico
  10. // @grant none
  11. // @require https://greasyfork.org/scripts/375096-bs-library/code/BS_Library.js?version=651891
  12. // ==/UserScript==
  13. const BS = window.BS;
  14. let username = BS.Module.Get('.navigation strong').innerText;
  15. let alternatives = [`@${username}`];
  16. let userpattern = `(${ alternatives.join('|') })`;
  17. let regex = new RegExp(userpattern, "ig");
  18. let posts = BS.Module.Get('#sbPosts');
  19. posts.addEventListener("DOMNodeInserted", (a,b) => {
  20. if(a.target.localName == "dd" && regex.test(a.target.innerHTML))
  21. {
  22. occurrence();
  23. let datauser = a.target.previousSibling.dataset.user;
  24. let time = a.target.previousSibling.getElementsByTagName('time')[0].innerText;
  25. let title = (datauser != undefined) ? datauser : "Du wurdest erwähnt.";
  26. let options = {
  27. body: a.target.innerText + "\r\n" + time,
  28. icon: "https://bs.to/favicon.ico",
  29. };
  30. new Notification(title, options);
  31. }
  32. });
  33.  
  34. if (!Array.prototype.remI) {
  35. let ars = ["Array", "HTMLCollection"];
  36. for (let i = 0; i < ars.length; i++) {
  37. Object.defineProperty(eval(ars[i]).prototype, "remI", {
  38. enumerable: false,
  39. value: function (index) {
  40. for (let i = 0; i < this.length; i++) {
  41. if (i > index) {
  42. this[i - 1] = this[i];
  43. }
  44. }
  45. this.length--;
  46. }
  47. });
  48. Object.defineProperty(eval(ars[i]).prototype, "f", {
  49. enumerable: false,
  50. value: function findArray(f, equal = false, path = "", first = true) {
  51. let index = -1;
  52. for (let i = 0; i < this.length; i++) {
  53. if (equal) {
  54. if (f === eval("this[i]" + path)) {
  55. index = i;
  56. if (first) {
  57. return index;
  58. }
  59. }
  60. } else {
  61. if (f.toString().indexOf(eval("this[i]" + path)) > -1) {
  62. index = i;
  63. if (first) {
  64. return index;
  65. }
  66. }
  67. }
  68. }
  69. return index;
  70. }
  71. });
  72. }
  73. }
  74.  
  75. (function() {
  76. 'use strict';
  77. if (Notification.permission !== 'denied' || Notification.permission === 'default') {
  78. Notification.requestPermission((permission) => {
  79. if (permission === 'granted') {
  80. console.log(`Notification Permission: ${ permission }`);
  81. }
  82. });
  83. }
  84. setInterval(BS.PN.NotifyIfNew, 5000);
  85. occurrence();
  86. setTimeout(function(){
  87. let sB=BS.Module.Get('#sbMsg');
  88. let par=sB.parentElement;
  89. sB.oninput=function(a,b,c){
  90. let usercontainer=BS.Module.Get('#sbUser').children;
  91. let onlineNames=[];
  92. for(let i=par.children.length-1;i>-1;i--){
  93. if(par.children[i].localName==="li12"){
  94. par.children[i].remove();
  95. }
  96. }
  97. for(let t=0;t<usercontainer.length;t++){
  98. if(sB.value.length>2){
  99. if(sB.value.indexOf("@")>-1 && usercontainer[t].children[0].textContent.toLowerCase().indexOf(sB.value.split("@")[1].toLowerCase())===0){
  100. onlineNames.push(usercontainer[t].children[0].textContent);
  101. }
  102. }
  103. }
  104. var active=BS.Module.Get('#sbPosts').children;
  105. for(let t=0;t<active.length;t+=2){
  106. if(onlineNames.f(active[t].children[0].textContent)>-1){
  107. onlineNames.remI(onlineNames.f(active[t].children[0].textContent,true));
  108. onlineNames.push(active[t].children[0].textContent);
  109. }else{
  110. if(sB.value.length>2&&sB.value.indexOf("@")>-1 && active[t].children[0].textContent.toLowerCase().indexOf(sB.value.split("@")[1].toLowerCase())===0){
  111. onlineNames.push(active[t].children[0].textContent);
  112. }
  113. }
  114.  
  115. }
  116. sB.onl=onlineNames;
  117. sB.index=0;
  118. if(sB.value.length>2&&onlineNames.length>0){
  119. let field=document.createElement("li12");
  120. field.style.width="200px";
  121. let height=onlineNames.length*20+20;
  122. let top=sB.offsetTop-(height)-5;
  123. field.style.position="absolute";
  124. field.style.top=top+"px";
  125. field.style.height=height+"px";
  126. field.style.left=sB.offsetLeft+"px";
  127. field.style.background="white";
  128. field.style.border="rgb(100, 160, 255) 1.5px solid";
  129. field.style.borderRadius= "4px";
  130. sB.fie=field;
  131. for(let j=0;j<onlineNames.length;j++){
  132. let username=document.createElement("el");
  133. username.innerText=onlineNames[j];
  134. username.style.position="absolute";
  135. username.style.top=j*20+8+"px";
  136. username.style.left=20+"px";
  137. username.style.width="160px";
  138. username.style.color="black";
  139. field.append(username);
  140. }
  141. par.append(field);
  142. }
  143. };
  144. sB.onkeydown=function(a,b,c){
  145. if(a.keyCode===38||a.keyCode===40){
  146. if(sB.fie.children[sB.index]){
  147. sB.fie.children[sB.index].style.backgroundColor="white";
  148. }
  149. function index(plus){
  150. if(plus){
  151. sB.index++;
  152. if(sB.index>sB.onl.length-1){
  153. sB.index=0;
  154. }
  155. }else{
  156. sB.index--;
  157. if(sB.index==-1){
  158. sB.index=sB.onl.length-1;
  159. }
  160. }
  161. }
  162. if(sB.index===undefined){
  163. sB.index=0;
  164. }
  165. if(a.keyCode===38){
  166. index(false);
  167. }else{
  168. index(true);
  169. }
  170. sB.fie.children[sB.index].style.backgroundColor="rgb(100, 160, 255)";
  171. sB.value=sB.value.replace(sB.value.split("@")[1].split(" ")[0],sB.onl[sB.index]+" ");
  172. }else if(a.keyCode===9){
  173. //tab
  174. if(sB.onl.length===1){
  175. sB.value=sB.value.replace(sB.value.split("@")[1].split(" ")[0],sB.onl[0]+" ");
  176. }else{
  177. sB.value=sB.value.replace(sB.value.split("@")[1].split(" ")[0],sB.onl[sB.onl.length-1]+" ");
  178. }
  179. for(let i=par.children.length-1;i>-1;i--){
  180. if(par.children[i].localName==="li12"){
  181. par.children[i].remove();
  182. }
  183. }
  184. setTimeout(function(sB){
  185. sB.focus();
  186. sB.selectionStart=sB.value.length;
  187. sB.selectionEnd=sB.value.length;
  188. },1,sB);
  189. }
  190. if(a.keyCode==13){
  191. return Shoutbox.checkEnter(a);
  192. }
  193. };
  194. },1000);
  195. })();
  196.  
  197. function occurrence(){
  198. let posts = document.getElementById('sbPosts');
  199. let postsContent = posts.children;
  200. for(let i = 0; i < postsContent.length; i++){
  201. if(postsContent[i].localName == "dd"){
  202. postsContent[i].innerHTML = postsContent[i].innerHTML.replace(regex, "<i style='color:yellow'>@"+username+"</i>");
  203. }
  204. }
  205. }