Last active
April 12, 2021 12:38
-
-
Save boehlke/31fe123bbf60ea8efcd494db7b841df8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Show PersonData QR Code | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description try to take over the world! | |
// @author You | |
// @match https://web.timify.com/* | |
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js | |
// @require https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
setInterval(function() { | |
const details = $(".ta-customers__preview__details") | |
const name = details.find('.ta-user-preview__name').text() | |
if(name) { | |
const fieldMap = { | |
"E-Mail": "email", | |
"Mobiltelefon": "phone", | |
"Geburtstag": "birthDate", | |
"Straße und Hausnr.": "address", | |
"PLZ": "postalCode", | |
"Stadt": "city", | |
} | |
const data = [] | |
details.find('.ta-icon-list').each(function(idx, elem) { | |
const fieldData = $(elem).text().split(':') | |
const fieldName = fieldMap[fieldData[0].trim()] | |
if(fieldName) { | |
data.push({ | |
field: fieldName, | |
value: fieldData[1].trim() | |
}) | |
} | |
}) | |
const nameParts = name.split(" ") | |
data.push({ | |
"field": "firstName", | |
"value": nameParts.slice(0, nameParts.length -1).join(" ") | |
}) | |
data.push({ | |
"field": "lastName", | |
"value": nameParts.slice(-1)[0], | |
}) | |
const fields = [ | |
"firstName", | |
"lastName", | |
"email", | |
"phone", | |
"birthDate", | |
"address", | |
"postalCode", | |
"city", | |
] | |
let qrCode = details.parent().find('.qr-code') | |
if(qrCode.length == 0) { | |
const qrCodeElement = document.createElement('div') | |
qrCodeElement.className = 'qr-code' | |
details.parent().append(qrCodeElement) | |
qrCode = $(qrCodeElement) | |
//new QRCode(qrCode[0], "#$$#" + data.map(function(field, idx) { | |
// return field.field + "=" + encodeURIComponent(field.value) | |
//}).join('###')) | |
const qrCodeContent = "#$$#" + fields.map(function(fieldName, idx) { | |
const value = data.filter((f) => {return f.field == fieldName }) | |
return value.length > 0 ? encodeURIComponent(value[0].value) : '' | |
}).join('##') | |
console.log(qrCodeContent) | |
new QRCode(qrCode[0], qrCodeContent) | |
} | |
} | |
}, 2000) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment