') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - ShanniLi/hexer · GitHub
Skip to content

Repository files navigation

CLI Usage

$ </bin/ls hexer

API Usage

Simple mode: buffer -> string

Got as buffer? We can render it:

varhex=require('hexer');console.log(hex(someBuffer));

Simply steram spy mode: in -> hex.Spy (->sink) -> out

Want to see what's going through a stream?

var hex = require('hexer');
stream
.pipe(hex.Spy(process.stdout)) // argument is where to dump to
.pipe(somewhere); // normal output flows through

Simple streaming mode: in -> hex.Transform -> out

Got a stream? We can render it:

varhex=require('hexer');process.stdin.pipe(hex.Transform()).pipe(process.stdout);

Chunked streaming mode: in -> hex.ChunkedTransform -> out

Got a stream? We can render each of its chunks:

varhex=require('hexer');process.stdin.pipe(hex.ChunkedTransform()).pipe(process.stdout);

Advanced chunked streaming mode

Finally you can control the sessionization yourself if that makes sense:

varhex=require('hexer');varhexer=hex.Transform();hexer.pipe(process.stdout);process.stdin.on('data',functiononData(chunk){if(decideToReset(chunk)){hexer.reset();}hexer.write(chunk);});

However that example is a bit contrived, a more realistic example would be:

varhex=require('hexer');varhexer=hex.Transform();hexer.pipe(process.stdout);process.stdin.on('data',functiononData(chunk){vari=findBoundary(chunk);while(i>0){hexer.write(chunk.slice(0,i));hexer.reset();chunk=chunk.slice(i);i=findBoundary(chunk);}if(chunk.length){hexer.write(chunk);}});

Options

  • prefix: a string that will be printed at the beginning of every line. (default empty string, "")

  • cols: the number of bytes to display on each line (default 16)

  • group: the number of bytes to display adjacently (default 2)

  • groupSeparator: a string that appears between byte groups (default one space " ")

  • headSep: a string that appears between the offset column and the byte column (default colon space, ": ")

  • divide: a string that appears between the byte value column and the character representation column (default two spaces, " ")

  • gutter: the minimum width of the gutter, the region on the left that contains the byte offset that each line starts with. (default 0)

  • offsetWidth: the minimum number of digits to display in the byte offset column.

  • decorateHexen(totalOffset, screenOffset, hexen): A function that has an opportunity to alter the numeric representation of a byte. Decoration is typically used to change the color of the byte based on its position in the stream or position in the line.

  • decorateHuman(totalOffset, screenOffset, human, byte): A function that has an opportunity to alter the appearance of a given human-readable representation of a byte. Decoration is typically used to change the color of the byte based on its position in the stream, position on the line, its representation, or its value.

  • renderHexen(byte): a function that accepts a byte value and returns a hexen readable, two character representation of that byte. By default, the hexen representation is lower-case zero-padded hex.

  • renderHuman(byte): a function that accepts a byte value and returns a human readable, single character representation of that byte. By default, the human representation is the character itself for all printable ASCII characters, and a period "." for control characters and EASCII bytes.

  • emptyHexen: a two character representation of a non-existant byte at a particular offset for the byte value representation. (default spaces, " ")

  • emptyHuman: the representation of a non-existant byte in the human readable characters column (default null string, "")

  • nullHuman: if an entire buffer or stream is empty, the default behavior is to represent it as an empty string or stream. With this option, the empty line will be expressly rendered, with offset zero, empty byte columns, and this string in the human readable characters section.

  • colored: if set true, enables ANSI coloring of output

License and Copyright

Copyright (c) 2015 Joshua T Corbin and contributors. All rights reserved. MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages