Commit 2906db0d authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Merge branch '1150-fix-spam-page-js' into 'development'

Resolve "Fix spam page js"

Closes #1150

See merge request !1909
parents 1c6f50fc 99fb68b2
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
} }
.matches { .matches {
background-color: #c9f4c9; background-color: #c9f4c9!important;
color: #3c3c3c !important;
} }
#block-requests { #block-requests {
margin-bottom: 16px; margin-bottom: 16px;
...@@ -104,47 +105,51 @@ ...@@ -104,47 +105,51 @@
var updating = true; var updating = true;
var buttonText = "Aktualisierung stoppen"; var buttonText = "Aktualisierung stoppen";
var interval = setInterval(updateQueries, 1000); var interval = setInterval(updateQueries, 1000);
$("#regexp").on("input", checkRegexp); document.getElementById("regexp").oninput = checkRegexp;
$("#check-against").on("input", checkRegexp); document.getElementById("check-against").oninput = checkRegexp;
$(document).ready(function(){ window.addEventListener('load', function(){
checkRegexp(); checkRegexp();
}); });
$("#head > button").click(function() { document.querySelector("#head > button").addEventListener('click', function() {
if(!updating) { if(!updating) {
$("#head > button").removeClass("btn-danger"); document.querySelector("#head > button").classList.remove("btn-danger");
$("#head > button").addClass("btn-success"); document.querySelector("#head > button").classList.add("btn-success");
buttonText = "Aktualisierung stoppen"; buttonText = "Aktualisierung stoppen";
interval = setInterval(updateQueries, 1000); interval = setInterval(updateQueries, 1000);
} }
var updateAt = lastUpdate + 60000; var updateAt = lastUpdate + 60000;
var updateIn = Math.round((updateAt - Date.now()) / 1000); var updateIn = Math.round((updateAt - Date.now()) / 1000);
$("#head > button").html(buttonText + " (" + updateIn + ")"); document.querySelector("#head > button").innerHTML = buttonText + " (" + updateIn + ")";
updating = !updating; updating = !updating;
}); })
function updateQueries() { function updateQueries() {
var updateAt = lastUpdate + 60000; var updateAt = lastUpdate + 60000;
var updateIn = Math.round((updateAt - Date.now()) / 1000); var updateIn = Math.round((updateAt - Date.now()) / 1000);
if(!updating){ if(!updating){
$("#head > button").removeClass("btn-success"); document.querySelector("#head > button").classList.remove("btn-success");
$("#head > button").addClass("btn-danger"); document.querySelector("#head > button").classList.add("btn-danger");
buttonText = "Aktualisierung starten"; buttonText = "Aktualisierung starten";
clearInterval(interval); clearInterval(interval);
} }
$("#head > button").html(buttonText + " (" + updateIn + ")"); document.querySelector("#head > button").innerHTML = buttonText + " (" + updateIn + ")";
if(updateAt > Date.now()){ if(updateAt > Date.now()){
return; return;
} }
fetch("{{ url('admin/spam/jsonQueries') }}") fetch("{{ url('admin/spam/jsonQueries') }}")
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
$("#queries").html(""); document.getElementById("queries").innerHTML = "";
$(data).each(function(index, el){ data.forEach((el, index) => {
$("#queries").append("<div class=\"query card\">" + el + "</div>"); newElement = document.createElement("div");
newElement.classList.add("query");
newElement.classList.add("card");
newElement.innerHTML = el;
document.getElementById("queries").appendChild(newElement);
}); });
lastUpdate = Date.now(); lastUpdate = Date.now();
checkRegexp(); checkRegexp();
...@@ -154,14 +159,16 @@ ...@@ -154,14 +159,16 @@
function checkRegexp() { function checkRegexp() {
var val = $("#regexp").val(); var val = document.getElementById("regexp").value;
var queries = []; var queries = [];
$("#queries > .query").each(function(index, el){ document.querySelectorAll("#queries > .query").forEach((el, index) => {
queries.push($(el).html()); queries.push(el.innerHTML);
}); });
queries.push($("#check-against").val());
queries.push(document.getElementById("check-against").value)
var url = "{{ url('admin/spam/queryregexp') }}"; var url = "{{ url('admin/spam/queryregexp') }}";
var options = { var options = {
...@@ -178,17 +185,18 @@ ...@@ -178,17 +185,18 @@
fetch(url, options) fetch(url, options)
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
$("#queries > .query").each(function(index, el){ document.querySelectorAll("#queries > .query").forEach((el, index) => {
if(data[index]["matches"]){ if(data[index]["matches"]){
$(el).addClass("matches"); el.classList.add("matches");
}else{ }else{
$(el).removeClass("matches"); el.classList.remove("matches");
} }
}); });
if(data[data.length-1]["matches"]){ if(data[data.length-1]["matches"]){
$("#check-against").addClass("matches"); document.getElementById("check-against").classList.add("matches");
}else{ }else{
$("#check-against").removeClass("matches"); document.getElementById("check-against").classList.remove("matches");
} }
}); });
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment