BS Notification

Benachrichtigung bei Erwähnung und Userauswahl mit @ in der SB

当前为 2018-05-31 提交的版本,查看 最新版本

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