Advertisement
TheVideoVolcano

Progress on Custom Alert Box (HTML injection) v1.1

Jun 25th, 2015
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Custom HTML alert box progress, using Javascript/Jquery
  2.  
  3. // ==UserScript==
  4. // @name        Cookie Test
  5. // @namespace
  6. // @version      1.0
  7. // @description  enter something useful
  8. // @author       RF Geraci
  9. // @include       *
  10. // @grant        none
  11. // ==/UserScript==
  12.  
  13.  
  14. function addStyleString(str) {
  15.     var node = document.createElement('style');
  16.     node.innerHTML = str;
  17.     document.head.appendChild(node);
  18. }
  19.  
  20.  
  21.  
  22. function generateColour(){
  23.  
  24.  
  25.     //var colours = ['red', 'green', 'blue', 'yellow', 'orange', 'pink'];
  26.     //var random = Math.floor((Math.random() * colours.length));
  27.  
  28.     // return colours[random];
  29.  
  30.     return "#" + Math.random().toString(16).slice(2, 8);
  31. }
  32.  
  33. function includeJQuery(){
  34.     var script = document.createElement('script');
  35.     script.src = 'http://code.jquery.com/jquery-1.11.0.min.js';
  36.     script.id = 'Custom_Jquery';
  37.     script.type = 'text/javascript';
  38.     document.getElementsByTagName('body')[0].appendChild(script);
  39.    
  40. }
  41.  
  42. function Hide(e){
  43.     $(e).FadeOut(2000);
  44. }
  45.  
  46.  
  47. function Msg(msg, title, btnText, DivColour){
  48.  
  49.  
  50.     includeJQuery();
  51.  
  52.     DivColour = typeof DivColour !== 'undefined' ? DivColour : '#81c0e8'; //'deepskyblue';
  53.     if (DivColour == '%random%') DivColour = generateColour();
  54.  
  55.     var div = document.createElement('div');
  56.     var p = document.getElementsByTagName('body')[0];
  57.  
  58.  
  59.     div.id = "custom_alert";
  60.     p.insertBefore(div, p.childNodes[0]);
  61.  
  62.     var divStyle =
  63.         'display: block' + //DISPLAY NONE, THEN TRANSISTION IN!
  64.         'max-width: 50% !important;' +
  65.         'max-height: 75% !important;' +
  66.         'background:' + DivColour + ' !important;' +
  67.         'z-index: 1000 !important;' +
  68.         'position: fixed !important;' +
  69.         'top: 50% !important;' +
  70.         'left: 50% !important;' +
  71.         'border: 1px solid white !important;' +
  72.         'box-shadow: 0px 0px 15px rgba(0,0,0,0.3) !important;' +
  73.         '-webkit-transform: translate(-50%, -50%) !important;' +
  74.         'transform: translate(-50%, -50%) !important;' +
  75.         'overflow-y: auto !important;' +
  76.         'word-wrap: break-word !important;' +
  77.         '-webkit-transition; -webkit-transform 1s;';
  78.        
  79.    
  80.     addStyleString('#custom_alert{' + divStyle + '}');
  81.     //div.setAttribute('style', divStyle);
  82.  
  83.  
  84.     var aTitle = document.createElement('h1');
  85.     aTitle.id = 'aTitle';
  86.     aTitle.innerHTML = title;
  87.    
  88.     addStyleString('#aTitle {color: white !important;' +
  89.                             'padding: 5px !important;' +
  90.                             'font: bold 15px arial, sans-serif !important;' +
  91.                             'border-bottom: 1px solid white;}');
  92.        
  93.    
  94.  
  95.     div.appendChild(aTitle);
  96.  
  97.     var tarea = document.createElement('div');
  98.     tarea.id = 'tarea';
  99.  
  100.     addStyleString('#tarea {padding: 5px !important;' +
  101.                    'transition: position 1s !important}');
  102.                    
  103.                    
  104.     div.appendChild(tarea);
  105.  
  106.  
  107.     var aMsg = document.createElement('h1');
  108.     aMsg.id = 'aMsg';
  109.     aMsg.innerHTML = msg;
  110.     addStyleString('#aMsg {color: white !important;' +
  111.                    'padding: 10px !important;' +
  112.                    'font: 15px arial, sans-serif !important;' +
  113.                    'text-align: center !important;' +
  114.                    'transition: position 1s !important;}');
  115.    
  116.    
  117.     tarea.appendChild(aMsg);
  118.  
  119.     var aBtn = document.createElement('input');
  120.    
  121.     aBtn.id = 'aBtn';
  122.     aBtn.type = 'button';
  123.     aBtn.value = btnText;
  124.     addStyleString('#aBtn{padding: 5px;' +
  125.                                   'background: #4091c4;' + //+ generateColour() + ';' +
  126.                                   'color: white;' +
  127.                                   'border: 1px solid #8cd3ff;' +
  128.                                   'border-radius: 1px;' +  
  129.                                   'outline: none;' +
  130.                                   'margin: 5px auto;' +
  131.                                   'text-align: center;' +
  132.                                   'width: 50%;' +
  133.                                   'position: relative;' +
  134.                                   'font: bold 15px arial, sans-serif !important;' +
  135.                                   'left: 25%;' +
  136.                                   '-webkit-transition: background 0.5s;');
  137.                  
  138.    
  139.     addStyleString('#aBtn:hover {background: #56ade2;}');
  140.     addStyleString('#aBtn:active {background: #0c669e;}');
  141.     addStyleString('#custom_alert {-webkit-animation: myAnim1 2.5s 1;}');
  142.     addStyleString('@-webkit-keyframes myAnim1{from {-webkit-transform: translate(-1000%,-1000%); } to {-webkit-transform: translate(-50%, -50%);}');      
  143.    
  144.     div.appendChild(aBtn);
  145.  
  146.    
  147.     aBtn.onclick = function(){
  148.        
  149.         div.style.display = 'none';
  150.         //  div.parentNode.removeChild(div);
  151.      
  152.     };
  153.  
  154. }
  155.  
  156. //Useage
  157. Msg("I am about to log you out.", "Logout...", 'OK');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement