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