BS Notification

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

当前为 2018-08-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name BS Notification
  3. // @namespace https://bs.to/
  4. // @version 3.5
  5. // @description Benachrichtigung bei Erwähnung in der SB oder einer neuen PN und Userauswahl mit @ in der SB
  6. // @author Asu
  7. // @match https://bs.to
  8. // @match https://bs.to/home
  9. // @icon https://bs.to/favicon.ico
  10. // @require https://greasyfork.org/scripts/368877-bs-script-library/code/BS_Script_Library.js?version=601546
  11. // @grant none
  12. // ==/UserScript==
  13. // Andere Sounds:
  14. // Ding: https://www.myinstants.com/media/sounds/ding_2.mp3
  15. // Forum Notification: https://board.bs.to/applications/core/interface/sounds/notification.mp3
  16. // Surprise Motherfucker: https://dl.dropboxusercontent.com/content_link/0sJVLvb4JIFKg5IavxBUmVAkHFUyZ91AfsNs6PXnNSrlaQmpVQpLlWrrfzUC7pQD/file?dl=0&duc_id=dropbox_duc_id
  17. var sound = new Audio("https://board.bs.to/applications/core/interface/sounds/notification.mp3");
  18. var customuserarray=[];
  19. var username=document.getElementById("navigation").children[0].childNodes[1].innerText;
  20. var userpattern = "@" + username;
  21. var regex = new RegExp(userpattern, "ig");
  22.  
  23. function x (){
  24. let posts = document.getElementById('sbPosts');
  25. let postsContent = posts.children;
  26. for(let i = 0; i < postsContent.length; i++){
  27. if(postsContent[i].localName == "dd"){
  28. postsContent[i].innerHTML = postsContent[i].innerHTML.replace(regex, "<i style='color:yellow'>@"+username+"</i>");
  29. }
  30. }
  31. }
  32.  
  33. function checkMessages() {
  34. let xhr = new XMLHttpRequest();
  35. xhr.open('GET', 'https://bs.to/messages', true);
  36. xhr.onload = () => {
  37. let div = document.createElement('div');
  38. div.innerHTML = xhr.responseText;
  39. let unread = div.querySelectorAll('.unread');
  40. let messages = (window.localStorage.messages) ? JSON.parse(window.localStorage.messages) : [];
  41. if(unread.length > 0) {
  42. for(let i = 0; i < unread.length; i++) {
  43. let msg = new Message({
  44. id: unread[i].children[1].children[0].getAttribute('href').split('/')[unread[i].children[1].children[0].getAttribute('href').split('/').length-1].split(':')[1],
  45. subject: unread[i].children[1].children[0].innerText,
  46. url: "https://bs.to/" + unread[i].children[1].children[0].getAttribute('href'),
  47. from: unread[i].children[2].children[0].innerText,
  48. to: unread[i].children[3].children[0].innerText,
  49. timestamp: unread[i].querySelector('time').innerText,
  50. title: `Neue Nachricht von ${unread[i].children[2].children[0].innerText}`
  51. });
  52. if (!(messages.some(e => e.id === msg.id))) {
  53. msg.notify();
  54. messages.push(msg);
  55. }
  56. }
  57. window.localStorage.messages = JSON.stringify(messages);
  58. }
  59. };
  60. xhr.send();
  61. }
  62.  
  63.  
  64. try{
  65. username=document.getElementById("navigation").children[0].childNodes[1].innerText;
  66. }catch(err){
  67. console.err(err);
  68. }
  69. if (!Array.prototype.remI) {
  70. var ars = ["Array", "HTMLCollection"];
  71. for (var i = 0; i < ars.length; i++) {
  72. Object.defineProperty(eval(ars[i]).prototype, "remI", {
  73. enumerable: false,
  74. value: function (index) {
  75. for (var i = 0; i < this.length; i++) {
  76. if (i > index) {
  77. this[i - 1] = this[i];
  78. }
  79. }
  80. this.length--;
  81. }
  82. });
  83. Object.defineProperty(eval(ars[i]).prototype, "f", {
  84. enumerable: false,
  85. value: function findArray(f, equal = false, path = "", first = true) {
  86. var index = -1;
  87. for (var i = 0; i < this.length; i++) {
  88. if (equal) {
  89. if (f === eval("this[i]" + path)) {
  90. index = i;
  91. if (first) {
  92. return index;
  93. }
  94. }
  95. } else {
  96. if (f.toString().indexOf(eval("this[i]" + path)) > -1) {
  97. index = i;
  98. if (first) {
  99. return index;
  100. }
  101. }
  102. }
  103. }
  104. return index;
  105. }
  106. });
  107. }
  108. }
  109.  
  110.  
  111. (function() {
  112. 'use strict';
  113. let posts = document.getElementById('sbPosts');
  114. posts.addEventListener("DOMNodeInserted", (a,b) => {
  115. if(a.target.localName == "dd" && regex.test(a.target.innerHTML))
  116. {
  117. x();
  118. let datauser = a.target.previousSibling.dataset.user;
  119. let title = (datauser != undefined) ? datauser : "Neue Benachrichtigung";
  120. let options = {
  121. body: a.target.innerText,
  122. icon: "https://bs.to/favicon.ico",
  123. };
  124. sound.play();
  125. let n = new Notification(title, options);
  126. }
  127. });
  128. // Your code here...
  129. setInterval(checkMessages, 1000*3);
  130. x();
  131.  
  132. //übernommener code:
  133.  
  134. setTimeout(function(){
  135. try{
  136. username=document.getElementById("navigation").children[0].childNodes[1].innerText;
  137. }catch(err){}
  138. var sB=$(sbMsg)[0];
  139. var par=sB.parentElement;
  140. sB.oninput=function(a,b,c){
  141. var usercontainer=$(sbUserCont)[0].children;
  142. var onlineNames=[];
  143. for(var i=par.children.length-1;i>-1;i--){
  144. if(par.children[i].localName==="li12"){
  145. par.children[i].remove();
  146. }
  147. }
  148. for(var t=0;t<usercontainer.length;t++){
  149. if(sB.value.length>2){
  150. if(sB.value.indexOf("@")>-1 && usercontainer[t].children[0].textContent.toLowerCase().indexOf(sB.value.split("@")[1].toLowerCase())===0){
  151. onlineNames.push(usercontainer[t].children[0].textContent);
  152. }
  153. }
  154. }
  155. var active=$(sbPosts)[0].children;
  156. for(var t=0;t<active.length;t+=2){
  157. if(onlineNames.f(active[t].children[0].textContent)>-1){
  158. onlineNames.remI(onlineNames.f(active[t].children[0].textContent,true));
  159. onlineNames.push(active[t].children[0].textContent);
  160. }else{
  161. if(sB.value.length>2&&sB.value.indexOf("@")>-1 && active[t].children[0].textContent.toLowerCase().indexOf(sB.value.split("@")[1].toLowerCase())===0){
  162. onlineNames.push(active[t].children[0].textContent);
  163. }
  164. }
  165.  
  166. }
  167. sB.onl=onlineNames;
  168. sB.index=0;
  169. if(sB.value.length>2&&onlineNames.length>0){
  170. var field=document.createElement("li12");
  171. field.style.width="200px";
  172. var height=onlineNames.length*20+20;
  173. var top=sB.offsetTop-(height)-5;
  174. field.style.position="absolute";
  175. field.style.top=top+"px";
  176. field.style.height=height+"px";
  177. field.style.left=sB.offsetLeft+"px";
  178. field.style.background="white";
  179. field.style.border="rgb(100, 160, 255) 1.5px solid";
  180. field.style.borderRadius= "4px";
  181. sB.fie=field;
  182. for(var j=0;j<onlineNames.length;j++){
  183. var username=document.createElement("el");
  184. username.innerText=onlineNames[j];
  185. username.style.position="absolute";
  186. username.style.top=j*20+8+"px";
  187. username.style.left=20+"px";
  188. username.style.width="160px";
  189. username.style.color="black";
  190. field.append(username);
  191. }
  192. par.append(field);
  193. }
  194. };
  195. sB.onkeydown=function(a,b,c){
  196. if(a.keyCode===38||a.keyCode===40){
  197. if(sB.fie.children[sB.index]){
  198. sB.fie.children[sB.index].style.backgroundColor="white";
  199. }
  200. function index(plus){
  201. if(plus){
  202. sB.index++;
  203. if(sB.index>sB.onl.length-1){
  204. sB.index=0;
  205. }
  206. }else{
  207. sB.index--;
  208. if(sB.index==-1){
  209. sB.index=sB.onl.length-1;
  210. }
  211. }
  212. }
  213. if(sB.index===undefined){
  214. sB.index=0;
  215. }
  216. if(a.keyCode===38){
  217. index(false);
  218. }else{
  219. index(true);
  220. }
  221. sB.fie.children[sB.index].style.backgroundColor="rgb(100, 160, 255)";
  222. sB.value=sB.value.replace(sB.value.split("@")[1].split(" ")[0],sB.onl[sB.index]+" ");
  223. }else if(a.keyCode===9){
  224. //tab
  225. if(sB.onl.length===1){
  226. sB.value=sB.value.replace(sB.value.split("@")[1].split(" ")[0],sB.onl[0]+" ");
  227. }else{
  228. sB.value=sB.value.replace(sB.value.split("@")[1].split(" ")[0],sB.onl[sB.onl.length-1]+" ");
  229. }
  230. for(var i=par.children.length-1;i>-1;i--){
  231. if(par.children[i].localName==="li12"){
  232. par.children[i].remove();
  233. }
  234. }
  235. setTimeout(function(sB){
  236. sB.focus();
  237. sB.selectionStart=sB.value.length;
  238. sB.selectionEnd=sB.value.length;
  239. },1,sB);
  240. }
  241. if(a.keyCode==13){
  242. return Shoutbox.checkEnter(a);
  243. }
  244. };
  245. },1000);
  246.  
  247. })();