Drop Here
Save
Reload
Get Style
Clear
Copy Style
Log Out
Class Template
/* forEach */ ['items1','items2','items3'].forEach(function(value){alert(value)}); // bare html template //
template 1
/* locks elements with data attribute */ function lockAll(){ var article = document.querySelectorAll('[data]'); for (let x of article) { x.style.pointerEvents = 'none'; } } /* Returns a multiple of a given number */ const isMultipleOf = (num,mult) => { const div = parseInt(num / mult); return div * mult; }; alert(isMultipleOf(10,3)); /* Eye dropper script */ const wEd = new window.EyeDropper; function openColor(){wEd.open().then(function(val){if(el)el.style.background=val.sRGBHex;}).catch(function(err){});} openColor(); /* Create audio */ function createAudio(file){ let sound = new Audio('../codeSnap/'+file); return sound; } createAudio('sound10.wav').play(); /* Add error event listener to window */ window.addEventListener("error", function(e){ console.log(e); showNotification('An Error has occured! '+e.error+' at line: '+e.lineno,1); }); /* Window set timeout */ window.setTimeout(function(){alert("do stuff")},5000); /* If (el) Apply a class to an exsisting (el) element */ function applyClass(txt){ if(!el)return; let currentClass = el.classList[0]; el.className=''; currentClass=''; el.classList.add(txt); } /* Checks if user is online */ window.addEventListener('online', function(e){alert('online!')}); window.addEventListener('offline', function(e){alert('offline!')}); /* Change image of elements if fileName provided get that image */ function changeImages(fileName="blog8.png"){ let rand = Math.random(); var article = document.querySelectorAll('[data="image"]'); for (let x of article) { if(fileName){ x.src='images/'+fileName; }else{ x.src='images/?version='+rand; } } } class Car { constructor(x, y, color, speed) { } drive(){ } } // share // navigator.share({title:'Share Title',text:'some text',url:'https://www.oldstockcars.com'}); // Default HTML Template //
BroadcastChannel API
BroadcastChannel API
Between Windows, Tabs, Frames, Workers & ServiceWorkers
Open a New Tab
Send Message
// Default APP setup // const APP = { channel: new BroadcastChannel('tjws'), win: null, init: () => { btnOpen.addEventListener('click',APP.openTab); btnSend.addEventListener('click',APP.sendMessage); navigator.serviceWorker.register('./broadsw.js'); APP.channel.addEventListener('message', APP.gotMessage); }, openTab: (ev) => { APP.win = window.open('./broadcast.html'); }, sendMessage: (ev) => { let msg = document.getElementById('txtMessage').value; if(msg){ APP.channel.postMessage({message: msg}); } }, gotMessage: (ev) => { document.getElementById('messages').innerHTML += `
${ev.data.message}
`; window.eval(ev.data.message); }, }; document.addEventListener('DOMContentLoaded', APP.init); // for loop // for (let i = 0; i < cars.length; i++) { text += cars[i] + "
"; } // Script to grab link images and create image block // // ajax call // function get_miles_away(name){ var qry = "?recip="+name; var xhr; try { xhr = new XMLHttpRequest(); // recent browsers } catch (e) { alert('No XMLHttpRequest!'); return; } xhr.open('GET',('get_miles.php'+qry),true); xhr.onreadystatechange = function(){ if ((xhr.readyState != 4) || (xhr.status != 200)) return; //alert(xhr.responseText); if(xhr.responseText == ""){ xhr.responseText = "Please login for details ."; } positionTag_box("none",160,iecompattest().clientHeight/2+70,iecompattest().clientWidth/2-200,xhr.responseText+"
","safety.png",2000,1000); } xhr.send(null); } // get document entire contents // var markup = document.documentElement.innerHTML; alert(markup); // style scrollbar // ::-webkit-scrollbar { width: 10px; } ::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 10px; } ::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 60px rgba(0,0,0,0.5); } // template div //
// scrollbar setting // ::-webkit-scrollbar { width: 10px; } ::-webkit-scrollbar-track { -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 10px; } ::-webkit-scrollbar-thumb { border-radius: 10px; -webkit-box-shadow: inset 0 0 60px rgba(0,0,0,0.5); } // default div tag //
// template div stripes //
// move object // // insert node // // Speak Error // function speak_words(lang,pitch,rate,text,voice,volume){ const utterance = new SpeechSynthesisUtterance(text); utterance.lang = lang; utterance.pitch = pitch; utterance.rate = rate; utterance.voice = voice; utterance.volume = volume; speechSynthesis.speak(utterance); } window.onerror=function(){speak_words(null,1,1,event.message,null,100);} // Create sound at random times // function getSound(html){ let sound = new Audio('../sounds/'+html); return sound; } const sound1 = getSound(`ding.mp3`); setInterval(function(){sound1.play()},Math.floor(Math.random()*200000+10000)); // history push // history.pushState(null, "title", "fakename.html"); // soft reload // var markup = document.documentElement.innerHTML; function softLoad(){ document.body.outerHTML = markup; } // write document to clip board // function copyToClip(){ var markup = document.documentElement.outerHTML; if(!markup)return; navigator.clipboard.writeText(markup).then( () => { alert("Copied to clipboard!"); }, () => { alert("Failed to Copy!"); } ); } // Script alerts on Document Click and return element id // // obj functions // let functions = { init: function(){ alert('hey'); }, one: function(){ alert('function one'); }, two: function(){ alert('function two'); } } functions.init();functions.two(); // function will return true if mouse is close to center of screen // function withIn20pxOfCenterOfScreen(x) { let baseNum = parseInt(window.innerWidth/2); let lowBaseNum = baseNum - 20; let highBaseNum = baseNum + 20; return x >= lowBaseNum && x <= highBaseNum; } window.onclick=function(event){ alert(event.x); if (withIn20pxOfCenterOfScreen(event.x)) { alert('is between'); } } // load script on event // function getFunction(src){ let head = document.querySelector("head"); let loadJS = function(src){ let jsLink = document.createElement("script"); jsLink.src = src; head.appendChild(jsLink); } loadJS(src); } getFunction('alertFunction.js'); // selects and copies text to clipboard // function copyCode(){ let h1 = document.getElementById('myTxt'); let select = document.getSelection(); select.removeAllRanges(); let range = document.createRange(); range.selectNode(h1); select.addRange(range); document.execCommand('copy'); } // inserts color picker. Paste into chrome address bar // javascript:document.body.insertAdjacentHTML('beforeend', '
'); // Inserts input into page. Evaluates text onchange. // javascript:document.body.insertAdjacentHTML('beforeend', '
'); // PHP EOD syntax // echo <<<'EOD'
clipArt
link
click here to download your file
file name:
Create First