Skip to content

Instantly share code, notes, and snippets.

function setLocalJSON(objName, objValue) {
if (typeof objName == 'string') {
if (objValue.constructor == {}.constructor) {
localStorage.setItem('objJSON-' + objName, JSON.stringify(objValue));
} else {
console.error('setLocalJSON accepts only json objects.');
return false;
};
};
};
function getLocalJSON(objName) {
if (typeof objName == 'string') {
if (localStorage.getItem('objJSON-' + objName) !== null) {
let objValue = localStorage.getItem('objJSON-' + objName);
return JSON.parse(objValue);
} else {
return {};
};
};
};
@luislobo14rap
luislobo14rap / salvarComo.js
Last active August 28, 2024 08:09
salvarComo.js
// salvarComo.js v1.0.1
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
var saveAs=saveAs||function(e){"use strict";if(typeof e==="undefined"||typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var t=e.document,n=function(){return e.URL||e.webkitURL||e},r=t.createElementNS("http://www.w3.org/1999/xhtml","a"),o="download"in r,a=function(e){var t=new MouseEvent("click");e.dispatchEvent(t)},i=/constructor/i.test(e.HTMLElement)||e.safari,f=/CriOS\/[\d]+/.test(navigator.userAgent),u=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},s="application/octet-stream",d=1e3*40,c=function(e){var t=function(){if(typeof e==="string"){n().revokeObjectURL(e)}else{e.remove()}};setTimeout(t,d)},l=function(e,t,n){t=[].concat(t);var r=t.length;while(r--){var o=e["on"+t[r]];if(typeof o==="function"){try{o.call(e,n||e)}catch(a){u(a)}}}},p=function(e){if(/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)){return n
@luislobo14rap
luislobo14rap / get-time-in-string.js
Last active November 20, 2022 22:17
get-time-in-string.js
// get-time-in-string.js v1.1
function getTimeInString(text, newDate = new Date()){
let _fullYear = newDate.getFullYear()
, _month = newDate.getMonth() + 1
, _date = newDate.getDate()
, _hours = newDate.getHours()
, _minutes = newDate.getMinutes()
, _seconds = newDate.getSeconds();
_month = ( _month > 9 ? _month : '0' + _month.toString() )
String.prototype.htmlEntities = function( reverse = 0 ){
let thisString = this;
let entities = [' ', '<', '>', '"', '\'', '¢', '£', '¥', '€', '©', '®'];
let htmlEntities = ['&nbsp;', '&lt;', '&gt;', '&quot;', '&apos;', '&cent;', '&pound;', '&yen;', '&euro;', '&copy;', '&reg;'];
if( reverse == 0 ){
thisString = thisString.replace(/&/g, 'ΠπϖⲠⲡhE');
for(let i = 0; i < 11; i++){
thisString = thisString.replace( new RegExp( entities[i] , 'g'), htmlEntities[i] ).replace(/ΠπϖⲠⲡhE/g, '&amp;');
@luislobo14rap
luislobo14rap / textarea-toSimpleText.html
Last active April 28, 2021 09:05
to-simple-text.js
<!-- to-simple-text.js v1.2.3 e RegExp -->
<!doctype html>
<html lang="pt-br">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
//jquery-mask-latin-characters
$('input[name="nome"]').mask(
'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
{translation:{'A':{pattern:/[ \.a-zA-ZÀÁÂÃÄÅàáâãäåÈÉÊËèéêëÌÍÎÏìíîïÒÓÔÕÖòóôõöÙÚÛÜùúûüÇçÑñ]/,optional:true}}}
);
//phone
let SPMaskBehavior=function(s){return 11===s.replace(/\D/g,'').length?'(00) 00000-0000':'(00) 0000-00009'},spOptions={onKeyPress:function(s,a,e,n){e.mask(SPMaskBehavior.apply({},arguments),n)}};$('.sp_celphones').mask(SPMaskBehavior,spOptions);
@luislobo14rap
luislobo14rap / browser-exit-confirmation.js
Last active January 17, 2020 12:21
browser-exit-confirmation.js
// browser-exit-confirmation.js v1
window.onbeforeunload = function(event){
event = event || window.event;
return 'Sure?';
};
regex negative set:
regex: [^;]
input: ABC;DEF
output: ABCDEF
('ABC;DEF').match(/[^;]+/g)