Skip to content

Instantly share code, notes, and snippets.

View luckylooke's full-sized avatar

Ctibor Laky luckylooke

View GitHub Profile
// taken from https://stackoverflow.com/questions/11849562/how-to-save-the-output-of-a-console-logobject-to-a-file
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
@luckylooke
luckylooke / fake_date.js
Last active July 22, 2022 13:53
fake Date in devTools for testing
// Context https://stackoverflow.com/a/72640597/861615
// Save the original `Date` function
const OriginalDate = Date;
const fakeDateArgs = [2022, 5, 3]; // beware month is 0 based
let fakeDate;
// Replace it with our own
Date = function Date(...args) {
// Called via `new`?
if (!new.target) {
// Mouse vs touch detection, supporting devices which are capable of both
// by default set using touch for all touch enabled devices
let userUsesTouch =
'ontouchstart' in document.documentElement ||
navigator.maxTouchPoints > 0 ||
navigator.msMaxTouchPoints > 0;
if (userUsesTouch) {
catchMouse();
@luckylooke
luckylooke / recaptcha_fallback.js
Created August 21, 2019 13:24
Google recaptcha wrapper for grecaptcha.execute() with version 2 fallback.
function execute(action, callback) {
// create real promise, because execute method does not return the real one
// (missing documentation what actually returns)
const promise = new Promise((resolve, reject) => {
grecaptcha.ready(() =>
grecaptcha.execute(key, { action }).then(token => {
resolve(token);
},
reject)
);