1 2 function formatHoursTo12(date) { 3 return date.getHours() % 12 || 12; 4 } 5 6 function startTime(period) { 7 let today = new Date(); 8 let year = today.getFullYear(); //Returns the year (4 digits for 4-digit years) of the specified date according to local time. 9 let day = today.getDate(); //Returns the day of the month (1â31) for the specified date according to local time. 10 let dayWeek = today.getDay(); //Returns the day of the week (0â6) for the specified date according to local time 11 let month = today.getMonth(); //Returns the month (0â11) in the specified date according to local time. 12 let hour = today.getHours(); //Returns the hour (0â23) in the specified date according to local time. 13 let min = today.getMinutes(); //Returns the minutes (0â59) in the specified date according to local time. 14 let sec = today.getSeconds(); //Returns the seconds (0â59) in the specified date according to local time. 15 if (typeof period === 'undefined'){ 16 var article = document.querySelector("#time-stamp"); 17 var period = article.dataset.period; 18//console.log(typeof period); 19//console.log(period); 20 } 21 if (['am','pm'].includes(period) ) { 22 period = "am"; 23 period = ((hour > 12) ? "pm" : period); 24 hour = formatHoursTo12(today); 25 } 26 else 27 if (['AM','PM'].includes(period) ) { 28 period = "AM"; 29 period = ((hour > 12) ? "PM" : period); 30 hour = formatHoursTo12(today); 31 } 32 hour = checkTime(hour); 33 min = checkTime(min); 34 sec = checkTime(sec); 35//console.log(period); 36 37 let elm = document.getElementById("showDate"); 38 if (elm){ 39 let time = hour+":"+min+":"+sec+" "+period; 40 elm.querySelector("#time-stamp").innerHTML = time; 41 setInterval(startTime, 500); 42 } 43 //let t = setTimeout(startTime,500); } 44 } 45 function checkTime(i) { 46 i = (i <= 9 ? '0' + i : i); 47 return i; 48 } 49 50 function readFile(input) { 51 let file = input.files[0]; 52 let reader = new FileReader(); 53 reader.readAsText(file); 54 reader.onload = function() { 55//console.log(reader.result); 56 }; 57 reader.onerror = function() { 58//console.log(reader.error); 59 }; 60 } 61 62/** 63 * https://molily.de/js/ 64 * Cross browser addEvent function by John Resig 65 * https://johnresig.com/blog/flexible-javascript-events/ 66 * some samples 67 * addEvent( document.getElementById('foo'), 'click', doSomething ); 68 * addEvent( obj, 'mouseover', function(){ alert('hello!'); } ); 69 * 70 */ 71/** 72 * Cross Browser helper to addEventListener. 73 * http://webintersect.com/articles/72/add-event-listener-to-dynamic-elements 74 * 75 * @param {HTMLElement} obj The Element to attach event to. 76 * @param {string} evt The event that will trigger the binded function. 77 * @param {function(event)} fnc The function to bind to the element. 78 * @return {boolean} true if it was successfuly binded. 79 */ 80 81 var addEvent = function (obj, evt, fnc) { 82 // W3C model 83 if (obj.addEventListener) { 84 obj.addEventListener(evt, fnc, false); 85 return true; 86 } 87 // Microsoft model 88 else if (obj.attachEvent) { 89 return obj.attachEvent('on' + evt, fnc); 90 } 91 // Browser don't support W3C or MSFT model, go on with traditional 92 else { 93 evt = 'on' + evt; 94 if (typeof obj[evt] === 'function') { 95 // Object already has a function on traditional 96 // Let's wrap it with our own function inside another function 97 fnc = (function (f1, f2) { 98 return function () { 99 f1.apply(this, arguments); 100 f2.apply(this, arguments); 101 }; 102 }) (obj[evt], fnc); 103 } 104 obj[evt] = fnc; 105 return true; 106 } 107 return false; 108 }; 109/*****************************************************************************/ 110/** 111 * sample 112 * removeEvent( object, eventType, function ); 113 * 114 */ 115 function removeEvent(obj, ev, fn) { 116 if (obj.detachEvent) { 117 obj.detachEvent('on' + ev, obj[ev + fn]); 118 obj[ev + fn] = null; 119 } else 120 obj.removeEventListener(ev, fn, false); 121 } 122/*****************************************************************************/ 123 if (!Array.from) { 124 Array.from = (function () { 125 var toStr = Object.prototype.toString; 126 var isCallable = function (fn) { 127 return typeof fn === 'function' || toStr.call(fn) === '[object Function]'; 128 }; 129 var toInteger = function (value) { 130 var number = Number(value); 131 if (isNaN(number)) { return 0; } 132 if (number === 0 || !isFinite(number)) { return number; } 133 return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number)); 134 }; 135 var maxSafeInteger = Math.pow(2, 53) - 1; 136 var toLength = function (value) { 137 var len = toInteger(value); 138 return Math.min(Math.max(len, 0), maxSafeInteger); 139 }; 140 // The length property of the from method is 1. 141 return function from(arrayLike/*, mapFn, thisArg */) { 142 // 1. Let C be the this value. 143 var C = this; 144 // 2. Let items be ToObject(arrayLike). 145 var items = Object(arrayLike); 146 // 3. ReturnIfAbrupt(items). 147 if (arrayLike == null) { 148 throw new TypeError("Array.from requires an array-like object - not null or undefined"); 149 } 150 // 4. If mapfn is undefined, then let mapping be false. 151 var mapFn = arguments.length > 1 ? arguments[1] : void undefined; 152 var T; 153 if (typeof mapFn !== 'undefined') { 154 // 5. else 155 // 5. a If IsCallable(mapfn) is false, throw a TypeError exception. 156 if (!isCallable(mapFn)) { 157 throw new TypeError('Array.from: when provided, the second argument must be a function'); 158 } 159 // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined. 160 if (arguments.length > 2) { 161 T = arguments[2]; 162 } 163 } 164 // 10. Let lenValue be Get(items, "length"). 165 // 11. Let len be ToLength(lenValue). 166 var len = toLength(items.length); 167 // 13. If IsConstructor(C) is true, then 168 // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len. 169 // 14. a. Else, Let A be ArrayCreate(len). 170 var A = isCallable(C) ? Object(new C(len)) : new Array(len); 171 // 16. Let k be 0. 172 var k = 0; 173 // 17. Repeat, while k < len⦠(also steps a - h) 174 var kValue; 175 while (k < len) { 176 kValue = items[k]; 177 if (mapFn) { 178 A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k); 179 } else { 180 A[k] = kValue; 181 } 182 k += 1; 183 } 184 // 18. Let putStatus be Put(A, "length", len, true). 185 A.length = len; 186 // 20. Return A. 187 return A; 188 }; 189 }()); 190 } 191/*****************************************************************************/ 192 var getBrowser = (function () { 193 var navigatorObj = navigator.appName, 194 userAgentObj = navigator.userAgent, 195 matchVersion; 196 var match = userAgentObj.match(/(opera|opr|chrome|safari|firefox|msie|trident)\/?\s*(\.?\d+(\.\d+)*)/i); 197 if (match && (matchVersion = userAgentObj.match(/version\/([\.\d]+)/i)) !== null) { 198 match[2] = matchVersion[1]; 199 } 200 //mobile 201 if (navigator.userAgent.match(/iPhone|Android|webOS|iPad/i)) { 202 var mobile; 203 return match ? [ 204 match[1], 205 match[2], 206 mobile 207 ] : [ 208 navigatorObj, 209 navigator.appVersion, 210 mobile 211 ]; 212 } 213 // web browser 214 return match ? [ 215 match[1], 216 match[2]
217 ] : [ 218 navigatorObj, 219 navigator.appVersion, 220 '-?' 221 ]; 222 }) (); 223 224 // forEach method, could be shipped as part of an Object Literal/Module 225 var forEach = function (array, callback, scope) { 226 for (var i = 0; i < array.length; i++) { 227 callback.call(scope, i, array[i]); // passes back stuff we need 228 } 229 }; 230 function each(elm, fn) { 231 for (var i = 0, l = elm.length; i < l; i++) { 232 fn.call(elm, elm[i], i); 233 } 234 } 235 function doSomething(elm) { 236 if ((typeof elm !== 'undefined') || elm) console.log(elm); 237 } 238/** 239 * https://www.axel-hahn.de/blog/2015/01/21/javascript-schnipsel-html-strippen/ 240 */ 241 function strip_tags(s) { 242 return s.replace(/<[^>]*>/g, ''); 243 } 244/** 245 * discuss at: https://phpjs.org/functions/dirname/ 246 * http: kevin.vanzonneveld.net 247 * original by: Ozh 248 * improved by: XoraX (http:www.xorax.info) 249 * example 1: dirname('/etc/passwd'); 250 * returns 1: '/etc' 251 */ 252 var dirname = function (path) { 253 var tmp = path.replace(/\\/g, '/').replace(/\/[^\/]*\/?$/, ''); 254 return tmp; 255 }; 256/** 257 * https://durhamhale.com/blog/javascript-version-of-phps-str-replace-function 258 */ 259 var str_replace = function (search, replace, string) { 260 return string.split(search).join(replace); 261 }; 262/** 263 * trim, rtrim, ltrim 264 * https://coursesweb.net/javascript/trim-rtrim-ltrim-javascript_cs 265 */ 266 var trim = function (str, chr) { 267 var rgxtrim = (!chr) ? new RegExp('^\\s+|\\s+$', 'g') : new RegExp('^' + chr + '+|' + chr + '+$', 'g'); 268 return str.replace(rgxtrim, ''); 269 }; 270 var rtrim = function (str, chr) { 271 var rgxtrim = (!chr) ? new RegExp('\\s+$') : new RegExp(chr + '+$'); 272 return str.replace(rgxtrim, ''); 273 }; 274 var ltrim = function (str, chr) { 275 var rgxtrim = (!chr) ? new RegExp('^\\s+') : new RegExp('^' + chr + '+'); 276 return str.replace(rgxtrim, ''); 277 }; 278 279 var showMessage = (function (txt, sel) { 280 var result = window.document.getElementById('messages'); 281 if (!result) {return false;} 282 var elm = document.createElement('P'); 283 elm.setAttribute('class', sel + ' rounded'); 284 elm.appendChild(document.createTextNode(txt)); 285 result.appendChild(elm); 286 }); 287 288/** 289 * https://www.javascriptkit.com/dhtmltutors/treewalker.shtml 290 */ 291/********************************************************************************************************/ 292 var LoadOnFly = (function ( nodeName, file ) { 293 'use strict'; 294 if ((typeof file === 'undefined') ) {return false;} 295 if (!document.doctype ) {return false;} 296 var jsRegex = /.js$/gi; 297 var cssRegex = /.css$/gi; 298 var scripts = {}; 299 var url = file; 300 var urlExt = trim(file.replace(/^.*\./, '')); 301 var NodeList = null; 302 var len = 0; 303 var node = null; 304 var str = 'undefined'; 305 var done = false; 306//console.info( urlExt + ' = 1.) ' + url); 307 if ((typeof url !== 'undefined') && (urlExt === 'js')) { 308//console.info(urlExt + ' = 1.) ' + url); 309 scripts[url] = false; 310 switch (nodeName) { 311 case 'body': 312 NodeList = document.body.querySelectorAll('SCRIPT'); 313//console.log(NodeList); 314 break; 315 default: 316 NodeList = document.head.querySelectorAll('SCRIPT'); 317 break; 318 } 319 if (NodeList) { len = NodeList.length - 1;} 320//console.info(NodeList); 321//console.info(' JS ' + url); 322 try { 323 var js = document.createElement('SCRIPT'); 324// js.setAttribute('type', 'text/javascript'); // optional, if not a html5 node 325 js.setAttribute('src', url); // src setzen 326 js.setAttribute('charset', 'UTF-8'); 327// js.setAttribute("async", true); // HTML5 Asyncron attribute 328 done = false; 329 if (nodeName == 'body') { 330 node = window.document.body.querySelectorAll('SCRIPT') [len]; 331 node.parentNode.appendChild( js ); 332//console.info( js ); 333 // script.parentNode.insertBefore(js,script); 334 } else { 335 node = window.document.head.querySelectorAll('SCRIPT') [len]; 336 node.parentNode.appendChild( js ); 337 } 338 } catch (e) { 339 str = '<script src=\'' + url + '\' charset="UTF-8"><' + '/script>'; 340 document.write(str); 341 } 342//console.info( node ); 343 } 344 // load css only within head 345 if ((typeof url !== 'undefined') && (urlExt === 'css')) { 346//console.info(urlExt + ' = 2.) ' + url); 347 scripts[url] = false;
348 try { 349 var NodeList = window.document.head.querySelectorAll('HEAD LINK[rel=stylesheet]'); 350 var css = document.createElement('LINK'); 351 len = 0; 352 css.setAttribute('rel', 'stylesheet'); 353// css.setAttribute('type', 'text/css'); 354 css.setAttribute('href', url); 355 css.setAttribute('media', 'all'); 356 if (NodeList) { 357 len = NodeList.length - 1; 358 }; 359 // insert after last link element if exist otherwise before first script 360 if (len > - 1) { 361 node = NodeList[len]; 362//console.info( node ); 363 // console.info(node); 364 // return false; 365 node.parentNode.insertBefore(css, node.nextSibling); 366 // console.info('CSS ' + url); 367 } else { 368 node = window.document.head.querySelectorAll('SCRIPT') [0]; 369 node.parentNode.insertBefore(css, node); 370 } 371 } catch (e) { 372 str = '<link rel="stylesheet" href=\'' + url + '\' media="all" />'; 373 document.write(str); 374 } 375 } 376 }); 377 378/* 379window.addEventListener('load', 380 function() { 381 LoadOnFly; 382 let clock = document.querySelector("#showDate"); 383 clock.addEventListener("load",startTime,false); 384console.log(clock); 385 }, false); 386*/ 387 function init() { 388// quit if this function has already been called 389 if (arguments.callee.done) return; 390// flag this function so we don't do the same thing twice 391 arguments.callee.done = true; 392// kill the timer 393// if (_timer){ clearInterval(_timer);} 394// do stuff 395// LoadOnFly; 396 let clock = document.querySelector("#showDate"); 397 if (clock){ 398//console.log(clock); 399 var article = document.querySelector("#time-stamp"); 400//console.log(article.dataset.period ); 401 startTime(article.dataset.period ); 402 } 403 }; 404 405 window.addEventListener('DOMContentLoaded', LoadOnFly, false); 406 if (document.addEventListener) { 407 document.addEventListener("DOMContentLoaded", init, false); 408 } 409
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.