Skip to content

Instantly share code, notes, and snippets.

@HT-7
HT-7 / date_calculator.js
Last active June 29, 2022 23:10
JavaScript date calculator (backwards-compatible to ECMAscript 3)
View date_calculator.js
var calcDate_data = {}; // initializing data object
function calcDate(date1, date2){
// memorize input to detect invalid input
calcDate_data.input1 = date1;
calcDate_data.input2 = date2;
// initiate date object
var dt_date1 = new Date(date1);
@HT-7
HT-7 / downloadDOM.js
Last active November 5, 2022 22:35
downloadDOM – Save pages as lightweight HTML documents with one click! A file name with domain name and time stamp is automatically generated.
View downloadDOM.js
function download(filename, text) {
var tmp_node = document.createElement('a');
tmp_node.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
tmp_node.setAttribute('download', filename);
tmp_node.style.display = 'none';
document.body.appendChild(tmp_node);
tmp_node.click();
@HT-7
HT-7 / timerUI.js
Last active November 5, 2022 19:45
Web media timer
View timerUI.js
// TimerUI – for home cinemas
// == Dependencies ==
var mediaType; // for compatibility
var playerExists = false; // is set to true below if player exists
var checkMediaType_enabled = true; // for debugging purposes
var media_element = {}; // declaring as object
var tmp="",count=0; // initiating temporary variables used inside functions and loops
@HT-7
HT-7 / playback keyboard controls.js
Last active May 20, 2022 00:52
Playback keyboard controls (jumping, skipping, volume, and speed) for web media players which lack such controls natively.
View playback keyboard controls.js
// Playback keyboard controls script
// (currently only works on dedicated media pages)
// Configuration
var jump_distance_forward = 10; // Jump this many seconds forward using right arrow key.
var jump_distance_backward = 5; // Jump this many seconds backward using left arrow key.
var speed_step = 1/4; // Speed increased or decreased by this value using arrow keys up and down.
var volume_step = 1/10; // Volume increased or decreased by this value using +-.
var volume_step_fine = 1/100; // Volume increased or decreased by this value if below volume_step.
// Seek: 0 to 9 Reset the speed using "Insert".