MUJS 2.0

A Library for UserScripts.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/10546/57895/MUJS%2020.js

  1. var sel = function(id){
  2. var sel = document.querySelector(id);
  3. return sel;
  4. }
  5.  
  6. var selAll = function(id){
  7. var selAll = document.querySelectorAll(id);
  8. return selAll;
  9. }
  10.  
  11. var del = function(elem){
  12. sel(elem).parentNode.removeChild(sel(elem));
  13. }
  14.  
  15. var write = function(left,top,text){
  16. var a = document.getElementsByTagName('body')[0];
  17. var b = document.createElement('div');
  18. b.innerHTML = text;
  19. b.style.position = 'absolute';
  20. b.style.left = left+'px';
  21. b.style.top = top+'px';
  22. a.appendChild(b);
  23. }
  24.  
  25. var bgColor = function(color){
  26. document.body.style.background = color;
  27. }
  28.  
  29. var display = function(element,attr){
  30. var x = document.querySelector(element);
  31. if(attr==0||attr=='none'||attr=='hide'||attr=='false'){x.style.display = 'none';}
  32. if(attr==1||attr=='block'||attr=='show'||attr=='true'){x.style.display = 'block';}
  33. }
  34.  
  35. var move = function(id,pos,left,top){
  36. sel(id).style.position=pos;
  37. sel(id).style.left=left+'px';
  38. sel(id).style.top=top+'px';
  39. }
  40.  
  41. var injectCss = function(css){
  42. var head = document.getElementsByTagName('head')[0];
  43. var style = document.createElement('style');
  44. style.type = "text/css";
  45. style.innerHTML = css;
  46. head.insertBefore(style,head.childNodes[1]);
  47. }
  48.  
  49. var bakeCookie = function(name,content,toDate){
  50. var hdate = new Date();
  51. hdate.setDate(hdate.getDate() + toDate).toLocaleString();
  52. str=name+'='+content;
  53. document.cookie= str+';expires='+hdate;
  54. //syntax for naming cookies
  55. //bakeCookie("cookiename","content",10000);
  56. }
  57.  
  58. var analyzeCookie = function(name){
  59. c = document.cookie.toString();
  60. var cookie_array = document.cookie.toString().split(';');
  61. pos = c.search(name);
  62. r = cookie_array[pos];
  63. f=r.toString().split('=')[1];
  64. return f;
  65. //analyzeCookie("cookieName") //returns the content of the cookie
  66. }
  67.  
  68. var eatCookie = function(name){
  69. c = document.cookie.toString();
  70. var cookie_array = document.cookie.toString().split(';');
  71. pos = c.search(name);
  72. r = cookie_array[pos];
  73. var hexp_date = new Date();
  74. hexp_date.setDate(hexp_date.getDate() - 10000).toLocaleString();
  75. document.cookie = r+';expires='+hexp_date;
  76. //eatCookie("cookieName") //without content or date
  77. }
  78.  
  79. var pushTo = function(elem,id,host,loc){
  80. var host = document.querySelector(host);
  81. var x = document.createElement(elem);
  82. x.id = id;
  83. if(loc==1||loc==null||loc=='after'){host.appendChild(x);}
  84. if(loc==0||loc=='before'){host.parentNode.insertBefore(x,host);}
  85. }
  86.  
  87. var typeTo = function(element,html){
  88. var x = document.querySelector(element);
  89. x.innerHTML = html;
  90. }
  91.  
  92.  
  93. var getData = function(site,target,type){
  94. if(target=='crossDomain'){
  95. var link='http://query.yahooapis.com/v1/public/yql?q=select * from html where url="'+site+'"&format='+type+'';}
  96. else if(target=='localDomain'||target==null){var link=site;}
  97. else{alert("Target parameter has to be either localDomain or crossDomain");}
  98. xml = new XMLHttpRequest();
  99. xml.open('get',link,false);xml.send();
  100. queryData = xml.responseText;
  101. return queryData;
  102. }
  103.  
  104. var showQueryData = function(qData){
  105. pushTo('textarea','queryDataContainer','body')
  106. typeTo('#queryDataContainer',qData);
  107. sel('#queryDataContainer').rows=15;
  108. sel('#queryDataContainer').cols=150;
  109. }
  110.  
  111. var mouse = function(event,id){
  112. x=document.querySelector(id);
  113. y=x.href; //getting link
  114. o=x.onclick; //check whether there is an onclick function
  115. t=x.target; //check target
  116.  
  117. if(t==""){t="_self"} //assign target if none
  118.  
  119. if(o==null && y!=null){ //This is for links without onclick functions with href
  120. x.onclick=function(){
  121. window.open(y,t);
  122. }
  123. //This is the if statement to fire the event
  124. if(event=='click' && id!=null){ //Firing the click event
  125. x.onclick();
  126. }
  127. }else if(o!=null && y!=null){ //This is for links with onclick functions & href
  128. if(event=='click' && id!=null){ //Firing the click event
  129. x.onclick();
  130. }
  131. window.open(y,t);
  132. }else if(o!=null && y==null){ //This is for links with onclick function without href
  133. x.onclick();
  134. }
  135.  
  136. if(event=='mouseover'){
  137. x.onmouseover();
  138. }
  139. //mouse('click','#id');
  140. //mouse('mouseover','#id');
  141. }
  142.