mirror of
https://github.com/msfjarvis/msfjarvis.dev.git
synced 2024-06-03 04:18:56 +05:30
ad5c047cd5
- See issue #1. - Credits goes to @chris-79 for the idea.
35 lines
1.6 KiB
HTML
35 lines
1.6 KiB
HTML
{{/* Get address and protocol */}}
|
|
{{- $address := .Get "address" | default (.Get 0) -}}
|
|
{{- $protocol := .Get "protocol" | default "mailto" -}}
|
|
{{- $class := .Get "class" -}}
|
|
{{- $displaytext := .Get "display" -}}
|
|
{{- $parts := split $address "@" -}}
|
|
{{- $user := (index $parts 0) -}}
|
|
{{- $domain := (index $parts 1) -}}
|
|
{{/* Compute md5 fingerprint */}}
|
|
{{- $fingerprint := md5 (print (.Get "address") $protocol (index (seq 999 | shuffle) 0)) -}}
|
|
<style type="text/css">
|
|
.cloaked-e-mail:before {
|
|
content:attr(data-domain) "\0040" attr(data-user);
|
|
unicode-bidi:bidi-override;
|
|
direction:rtl;
|
|
}
|
|
</style>
|
|
<span class="cloaked-e-mail" data-user="{{ range $index := seq (sub (len $user) 1) 0}}{{ substr $user $index 1}}{{ end }}" data-domain="{{ range $index := seq (sub (len $domain) 1) 0}}{{ substr $domain $index 1}}{{ end }}"></span>
|
|
<script id="{{ $fingerprint }}">
|
|
var scriptTag = document.getElementById("{{ $fingerprint }}");
|
|
var link = document.createElement("a");
|
|
var address = "{{ range $index := seq (sub (len $user) 1) 0}}{{ substr $user $index 1}}{{ end }}".split('').reverse().join('') + "@" + "{{ range $index := seq (sub (len $domain) 1) 0}}{{ substr $domain $index 1}}{{ end }}".split('').reverse().join('');
|
|
link.href = {{ $protocol }} + ":" + address;
|
|
{{ with $displaytext }}
|
|
link.innerText = {{ $displaytext }};
|
|
{{ else }}
|
|
link.innerText = address;
|
|
{{ end }}
|
|
{{ with $class }}
|
|
link.className = "{{ $class }}";
|
|
{{ end }}
|
|
scriptTag.parentElement.insertBefore(link, scriptTag.previousElementSibling);
|
|
scriptTag.parentElement.removeChild(scriptTag.previousElementSibling)
|
|
</script>
|