Right-click dissuasion
This commit is contained in:
parent
2e3cd96309
commit
8130ce4845
|
@ -75,15 +75,11 @@ func (t *Template) Execute(w http.ResponseWriter, r *http.Request, vars map[stri
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reload the template from disk?
|
// Reload the template from disk?
|
||||||
if stat, err := os.Stat(t.filepath); err == nil {
|
if t.IsModifiedLocally() {
|
||||||
if stat.ModTime().After(t.modified) {
|
if err := t.Reload(); err != nil {
|
||||||
log.Info("Template(%s).Execute: file updated on disk, reloading", t.filename)
|
|
||||||
err = t.Reload()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Reloading error: %s", err)
|
log.Error("Reloading error: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Install the function map.
|
// Install the function map.
|
||||||
tmpl := t.tmpl
|
tmpl := t.tmpl
|
||||||
|
@ -98,6 +94,23 @@ func (t *Template) Execute(w http.ResponseWriter, r *http.Request, vars map[stri
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsModifiedLocally checks if any of the template partials of your Template have
|
||||||
|
// had their files locally on disk modified, so to know to reload them.
|
||||||
|
func (t *Template) IsModifiedLocally() bool {
|
||||||
|
// Check all the template files from base.html, to partials, to our filepath.
|
||||||
|
var files = templates(t.filepath)
|
||||||
|
for _, filename := range files {
|
||||||
|
if stat, err := os.Stat(filename); err == nil {
|
||||||
|
if stat.ModTime().After(t.modified) {
|
||||||
|
log.Info("Template(%s).Execute: file %s updated on disk, reloading", t.filename, filename)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Reload the template from disk.
|
// Reload the template from disk.
|
||||||
func (t *Template) Reload() error {
|
func (t *Template) Reload() error {
|
||||||
stat, err := os.Stat(t.filepath)
|
stat, err := os.Stat(t.filepath)
|
||||||
|
|
|
@ -85,7 +85,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
// Common event handlers for bulma modals.
|
// Common event handlers for bulma modals.
|
||||||
(document.querySelectorAll(".modal-background, .modal-close, .photo-modal") || []).forEach(node => {
|
(document.querySelectorAll(".modal-background, .modal-close, .photo-modal") || []).forEach(node => {
|
||||||
const target = node.closest(".modal");
|
const target = node.closest(".modal");
|
||||||
if (target.classList.contains("vue-managed")) return;
|
if (target.classList.contains("vue-managed") || target.classList.contains("nonshy-important-modal")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
node.addEventListener("click", () => {
|
node.addEventListener("click", () => {
|
||||||
target.classList.remove("is-active");
|
target.classList.remove("is-active");
|
||||||
});
|
});
|
||||||
|
|
17
web/static/js/right-click.js
Normal file
17
web/static/js/right-click.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// Right-click button handler, to dissuade downloading.
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
const $modal = document.querySelector("#rightclick-modal"),
|
||||||
|
$button = $modal.querySelector("button"),
|
||||||
|
cls = 'is-active';
|
||||||
|
|
||||||
|
console.log("register right clicks");
|
||||||
|
console.log($modal, $button);
|
||||||
|
|
||||||
|
document.addEventListener('contextmenu', (e) => {
|
||||||
|
$modal.classList.add(cls);
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
$button.addEventListener('click', () => {
|
||||||
|
$modal.classList.remove(cls);
|
||||||
|
});
|
||||||
|
});
|
|
@ -368,6 +368,42 @@
|
||||||
<!-- Likes modal -->
|
<!-- Likes modal -->
|
||||||
{{template "like-modal"}}
|
{{template "like-modal"}}
|
||||||
|
|
||||||
|
<!-- Right-click modal -->
|
||||||
|
<div class="modal nonshy-important-modal" id="rightclick-modal">
|
||||||
|
<div class="modal-background"></div>
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header has-background-warning">
|
||||||
|
<p class="card-header-title has-text-dark-dark">
|
||||||
|
<i class="fa fa-info-circle mr-2"></i> Please respect peoples' privacy
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="card-content content">
|
||||||
|
<p>
|
||||||
|
Please respect our members' privacy and refrain from downloading any pictures from {{PrettyTitle}}.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
It is <a href="/tos#downloading">against the rules</a> to download a copy of other peoples' photos
|
||||||
|
from this site. I know that I can't stop you from doing so anyway if you're so determined, but
|
||||||
|
please consider that many of us don't wish for our pictures to end up reposted somewhere
|
||||||
|
else on the Internet or seen by people outside of the {{PrettyTitle}} community.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Thank you for your understanding!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer has-text-centered">
|
||||||
|
<div class="card-footer-item">
|
||||||
|
<button type="button" class="button is-success">
|
||||||
|
Acknowledge
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script type="text/javascript" src="/static/js/right-click.js?build={{.BuildHash}}"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user