diff --git a/client/html/posts_header.tpl b/client/html/posts_header.tpl
index e0ba0eae..61f03c72 100644
--- a/client/html/posts_header.tpl
+++ b/client/html/posts_header.tpl
@@ -4,6 +4,8 @@
%><%
%><%
%><%
+ %><%
+ %><%
%><% if (ctx.enableSafety) { %><%
%>'/><%
%>'/><%
diff --git a/client/js/views/posts_header_view.js b/client/js/views/posts_header_view.js
index 6b697c4f..b0ddf5ce 100644
--- a/client/js/views/posts_header_view.js
+++ b/client/js/views/posts_header_view.js
@@ -145,6 +145,7 @@ class PostsHeaderView extends events.EventTarget {
'click', e => this._evtSafetyButtonClick(e));
}
this._formNode.addEventListener('submit', e => this._evtFormSubmit(e));
+ this._randomButtonNode.addEventListener('click', e => this._evtRandomButtonClick(e));
this._bulkEditors = [];
if (this._bulkEditTagsNode) {
@@ -191,6 +192,10 @@ class PostsHeaderView extends events.EventTarget {
return this._hostNode.querySelector('form [name=search-text]');
}
+ get _randomButtonNode() {
+ return this._hostNode.querySelector('#random-button');
+ }
+
get _bulkEditTagsNode() {
return this._hostNode.querySelector('.bulk-edit-tags');
}
@@ -242,6 +247,14 @@ class PostsHeaderView extends events.EventTarget {
e.preventDefault();
this._navigate();
}
+ _evtRandomButtonClick(e) {
+ if (!this._queryInputNode.value.includes('sort:random')) {
+ this._queryInputNode.value += ' sort:random';
+ } else {
+ location.reload();
+ }
+ this._navigate();
+ }
_navigate() {
this._autoCompleteControl.hide();