MOVED TO: openInNewWindow.js - F5-REFRESHABLE! - (data, type = 'octet-stream')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sorted.js (array, strFlags) returns CLONE (not in-place sort!) -- flags 'uid': u=Unique original values, i=case Insensitive compare function, d=Descending (reverse) order | |
// minified = 179 chars s=(a,f="",c=a=>f.includes(a),d=[...(c("u")?[...new Set(a)]:a)])=>(d=c("i")?d.sort((a,b,c=(a+"").toUpperCase(),d=(b+"").toUpperCase())=>c<d?-1:c===d):d.sort(),c("d")?d.reverse():d) | |
let sorted = (array, strFlags = "", | |
// friendlier syntax like RegExp( _, strFlags ) rather than fetch( _, {options} ) | |
_tmp_HasFlag = flag => strFlags.includes(flag), | |
// work with CLONE of original array (or Set made from it) -- we do NOT want to do IN-PLACE sort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/////// download.js: SAVE data TO file (aka 'export/download')... | |
//// const download_MIN=(d,f=`file-${+new Date}.txt`,t="octet-stream")=>{const h=URL.createObjectURL(new Blob([d].slice(void 0===d),{type:t})),s=null!==f;return Object.assign(document.createElement("a"),{href:h,[s&&"download"]:f,target:"_blank"}).click(),s&&URL.revokeObjectURL(h)}; | |
const download = ( | |
data | |
, filename = `file-${+new Date}.txt` // null means download: filename OMITTED = DISPLAY data in browser | |
, type = "octet-stream" // default is ~ "application/octet-binary" | |
) => { | |
const href = URL.createObjectURL(new Blob( // https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob | |
[data].slice(data === undefined) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Math.sum.js and Math.avg and Math.max and Math.sum -- ALL will automatically flatten (all, args, passed, [[even, [, Arrays]]]) | |
console.log(Math.sum); | |
// undefined | |
console.log(Math.avg); | |
// undefined | |
console.log(Math.max); | |
// ƒ max() { [native code] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store.js ALL-IN-ONE function: () = dump Storage, (keyOrNS, value OTHER THAN undefined) = return value after setting it, (keyOrNS) = return value - UNDEFINED if missing, (null, keyOrNS) = removeItem(keyOrNS) then return keyOrNS | |
// let store=(k,d,s=localStorage,z=s.getItem(k))=>null==k?null==d?s:(s.removeItem(d),d):void 0===d?null==z?void 0:JSON.parse(z):(s.setItem(k,JSON.stringify(d,0,"\t")),d); | |
let store = ( | |
keyOrNS, | |
data, | |
storage = [localStorage, sessionStorage][0], | |
_z = storage.getItem(keyOrNS) | |
) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// htmlDecode.js htmlEncode.js - using modern browsers' built-in DOM manipulation (plus common escaping for htmlEncode) | |
// let htmlDecode=a=>Object.assign(document.createElement("textarea"),{innerHTML:null==a?"":a.replace(/<\s*br\s*\/?\s*>/gi,"\n")}).value; | |
let htmlDecode = html => Object.assign( | |
document.createElement("textarea"), { | |
innerHTML: html == null ? "" : html.replace(/<\s*br\s*\/?\s*>/gi, "\n") | |
} | |
).value; | |
// let htmlEncode=a=>Object.assign(document.createElement("div"),{innerText:null==a?"":a}).innerHTML.replace(/<br>/g,"\n").replace(/['"\t\f\r\n\u00A0-\u2666]/g,a=>({"'":"'",'"':"""})[a]||`&#${a.charCodeAt(0)};`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// selectedHtml.js -- returns [htmlString, htmlString.length] , args are ALL optional ( doc, selection = doc.getSelection(), range = selection.getRangeAt(0) ) | |
// const selectedHtml=(b=document,c=b.getSelection(),d=c&&c.getRangeAt(0),e=d&&a.createElement("div"),f=e?(e.appendChild(d.cloneContents()),e.innerHTML):"")=>[f,f.length]; | |
const selectedHtml = ( | |
_doc = document, | |
_sel = _doc.getSelection(), // "You can call Window.getSelection(), which works identically to Document.getSelection()." https://developer.mozilla.org/en-US/docs/Web/API/Document/getSelection | |
_range = _sel && _sel.getRangeAt(0), | |
_el = _range && doc.createElement("div"), | |
_result = !_el ? "" : ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HTML.js - display full webpage source (document.documentElement.outerHTML) into a new tab popup | |
// RUN = 304 char: javascript:void function(){let a=open("about:blank").document,b=a.body;b.appendChild(a.createElement("b")).innerText=a.title=`Source code of ${location.href}`;let c=b.appendChild(a.createElement("pre"));c.innerText=document.documentElement.outerHTML,c.style.whiteSpace="pre-wrap",c.style.color="blue"}(); | |
let doc = open('about:blank').document; | |
let body = doc.body; | |
let tagForTitle = "b"; | |
body.appendChild(doc.createElement(tagForTitle)).innerText = doc.title = `Source code of ${location.href}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("TOP"); | |
exports.importedInfo = [, 3, 6, 9, exports && exports.length, "someGlobal:", typeof someGlobal !== "undefined" && someGlobal]; | |
module.exports.xyz = 123; | |
alert('executing xt.js?' + location.href); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// require.js in just 793 chars -- even works from local CSCRIPT.EXE JScript.js (because not everybody runs Node) -- var exports = require('moduleName') | |
(function(a){var b={},c=[],d=function(a,d){var f={exports:{}},g=a.length?e.resolve(a,c[0]):"",h=e.fetch(g),i=null!=h&&eval("[(function(exports,require,module,__filename,__dirname){"+(h+"})][0]"));if(i){b[d]=f.exports,c.unshift(g);try{i(b[d],e,f,g,e.dir(g))}catch(a){}return c.shift(),f.exports}},e=function(a){var c=(a+"").replace(/\\/g,"/").replace(/\.js$/i,""),e=c.toLowerCase();if(a)return e in b?b[e]:d(c,e)};e.resolve=function(a,b){return(/^\.{1,2}/.test(a)?e.dir(b||location.href.replace(/\\/g,"/"))+"/":"")+a+".js"},e.fetch=function(a){try{var b=a.length&&new XMLHttpRequest,c=b&&(b.send(b.open("GET",a,!1)),b.status),d=b&&b.responseText;if(200===c||d.length&&!c)return d}catch(a){}},e.dir=function(a){var b=a.lastIndexOf("/");return 0>b?"":a.slice(0,b)},a.require=a.require||e})(this); | |
(function(globalContext){ | |
var moduleName = "require"; | |
var cache = {}; |