Skip to content

Instantly share code, notes, and snippets.

@hieulw
Created October 26, 2020 14:17
Show Gist options
  • Select an option

  • Save hieulw/d4a5f99bbc6183114d9a21bf4029bd7a to your computer and use it in GitHub Desktop.

Select an option

Save hieulw/d4a5f99bbc6183114d9a21bf4029bd7a to your computer and use it in GitHub Desktop.
function fetchQRCode(content, download = false) {
const endpoint = "https://qr-generator.qrcode.studio/qr/custom";
const data = {
data: content,
config: {
bgColor: "#FFFFFF",
body: "circle-zebra-vertical",
bodyColor: "#f37239",
brf1: ["fv"],
brf2: [],
brf3: [],
erf1: ["fv"],
erf2: [],
erf3: [],
eye: "frame12",
eye1Color: "#0277BD",
eye2Color: "#0277BD",
eye3Color: "#0277BD",
eyeBall: "ball14",
eyeBall1Color: "#0277BD",
eyeBall2Color: "#0277BD",
eyeBall3Color: "#0277BD",
gradientColor1: "#f58739",
gradientColor2: "#941010",
gradientOnEyes: true,
gradientType: "linear",
logo: "d368ebf637705261d3b81ac06a716e907c4000bb.png",
logoMode: "clean",
},
size: 500,
download: download == true ? true : "imageUrl",
file: download == true ? "png" : "svg"
}
if(download == false) {
fetch(endpoint, {
credentials: "omit",
headers: {
"content-type": "text/plain;charset=UTF-8",
"sec-fetch-mode": "cors",
},
referrer: "https://www.qrcode-monkey.com/",
referrerPolicy: "no-referrer-when-downgrade",
body: JSON.stringify(data),
method: "POST",
mode: "cors",
body: JSON.stringify(data)
}).then((res) => {
return res.json();
}).then((data) => {
window.open('https:'+data.imageUrl);
}).catch((err) => {
console.error(err);
})
} else {
let queries = [];
for(let key in data) {
let val = data[key];
if(typeof val == 'object') {
val = JSON.stringify(val);
}
queries.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
}
let popup = window.open(endpoint+'?'+queries.join('&'));
}
}
function addTickets(quantity = 100) {
const db = firebase.firestore();
let qrcode = [];
for(let i = 0; i < quantity; i++) {
db.collection('tickets').add({
checked:false,
timeCheck: firebase.firestore.Timestamp.now(),
}).then(ref => {
qrcode.push(ref.id)
}).catch(err => {
console.error(err);
});
}
return qrcode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment