Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Custom HTML alert box progress, using Javascript/Jquery
- // ==UserScript==
- // @name Cookie Test
- // @namespace
- // @version 1.0
- // @description enter something useful
- // @author RF Geraci
- // @include *
- // @grant none
- // ==/UserScript==
- function addStyleString(str) {
- var node = document.createElement('style');
- node.innerHTML = str;
- document.head.appendChild(node);
- }
- function generateColour(){
- //var colours = ['red', 'green', 'blue', 'yellow', 'orange', 'pink'];
- //var random = Math.floor((Math.random() * colours.length));
- // return colours[random];
- return "#" + Math.random().toString(16).slice(2, 8);
- }
- function includeJQuery(){
- var script = document.createElement('script');
- script.src = 'http://code.jquery.com/jquery-1.11.0.min.js';
- script.id = 'Custom_Jquery';
- script.type = 'text/javascript';
- document.getElementsByTagName('body')[0].appendChild(script);
- }
- function Hide(e){
- $(e).FadeOut(2000);
- }
- function Msg(msg, title, btnText, DivColour){
- includeJQuery();
- DivColour = typeof DivColour !== 'undefined' ? DivColour : '#81c0e8'; //'deepskyblue';
- if (DivColour == '%random%') DivColour = generateColour();
- var div = document.createElement('div');
- var p = document.getElementsByTagName('body')[0];
- div.id = "custom_alert";
- p.insertBefore(div, p.childNodes[0]);
- var divStyle =
- 'display: block' + //DISPLAY NONE, THEN TRANSISTION IN!
- 'max-width: 50% !important;' +
- 'max-height: 75% !important;' +
- 'background:' + DivColour + ' !important;' +
- 'z-index: 1000 !important;' +
- 'position: fixed !important;' +
- 'top: 50% !important;' +
- 'left: 50% !important;' +
- 'border: 1px solid white !important;' +
- 'box-shadow: 0px 0px 15px rgba(0,0,0,0.3) !important;' +
- '-webkit-transform: translate(-50%, -50%) !important;' +
- 'transform: translate(-50%, -50%) !important;' +
- 'overflow-y: auto !important;' +
- 'word-wrap: break-word !important;' +
- '-webkit-transition; -webkit-transform 1s;';
- addStyleString('#custom_alert{' + divStyle + '}');
- //div.setAttribute('style', divStyle);
- var aTitle = document.createElement('h1');
- aTitle.id = 'aTitle';
- aTitle.innerHTML = title;
- addStyleString('#aTitle {color: white !important;' +
- 'padding: 5px !important;' +
- 'font: bold 15px arial, sans-serif !important;' +
- 'border-bottom: 1px solid white;}');
- div.appendChild(aTitle);
- var tarea = document.createElement('div');
- tarea.id = 'tarea';
- addStyleString('#tarea {padding: 5px !important;' +
- 'transition: position 1s !important}');
- div.appendChild(tarea);
- var aMsg = document.createElement('h1');
- aMsg.id = 'aMsg';
- aMsg.innerHTML = msg;
- addStyleString('#aMsg {color: white !important;' +
- 'padding: 10px !important;' +
- 'font: 15px arial, sans-serif !important;' +
- 'text-align: center !important;' +
- 'transition: position 1s !important;}');
- tarea.appendChild(aMsg);
- var aBtn = document.createElement('input');
- aBtn.id = 'aBtn';
- aBtn.type = 'button';
- aBtn.value = btnText;
- addStyleString('#aBtn{padding: 5px;' +
- 'background: #4091c4;' + //+ generateColour() + ';' +
- 'color: white;' +
- 'border: 1px solid #8cd3ff;' +
- 'border-radius: 1px;' +
- 'outline: none;' +
- 'margin: 5px auto;' +
- 'text-align: center;' +
- 'width: 50%;' +
- 'position: relative;' +
- 'font: bold 15px arial, sans-serif !important;' +
- 'left: 25%;' +
- '-webkit-transition: background 0.5s;');
- addStyleString('#aBtn:hover {background: #56ade2;}');
- addStyleString('#aBtn:active {background: #0c669e;}');
- addStyleString('#custom_alert {-webkit-animation: myAnim1 2.5s 1;}');
- addStyleString('@-webkit-keyframes myAnim1{from {-webkit-transform: translate(-1000%,-1000%); } to {-webkit-transform: translate(-50%, -50%);}');
- div.appendChild(aBtn);
- aBtn.onclick = function(){
- div.style.display = 'none';
- // div.parentNode.removeChild(div);
- };
- }
- //Useage
- Msg("I am about to log you out.", "Logout...", 'OK');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement