From ab4c58e17ee7b63ea4a130e0dfc9765a4db98b61 Mon Sep 17 00:00:00 2001 From: Shish Date: Sat, 30 Dec 2023 13:47:23 +0000 Subject: [PATCH] [view] reduce jquery --- ext/view/script.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/ext/view/script.js b/ext/view/script.js index 3c8799f3..4d8b0432 100644 --- a/ext/view/script.js +++ b/ext/view/script.js @@ -7,23 +7,21 @@ function joinUrlSegments(base, query) { } document.addEventListener('DOMContentLoaded', () => { + function updateAttr(selector, attr, value) { + document.querySelectorAll(selector).forEach(function(e) { + let current = e.getAttribute(attr); + let newval = joinUrlSegments(current, query); + e.setAttribute(attr, newval); + }); + } + if(document.location.hash.length > 3) { var query = document.location.hash.substring(1); - $('LINK#prevlink').attr('href', function(i, attr) { - return joinUrlSegments(attr,query); - }); - $('LINK#nextlink').attr('href', function(i, attr) { - return joinUrlSegments(attr,query); - }); - $('A#prevlink').attr('href', function(i, attr) { - return joinUrlSegments(attr,query); - }); - $('A#nextlink').attr('href', function(i, attr) { - return joinUrlSegments(attr,query); - }); - $('span#image_delete_form form').attr('action', function(i, attr) { - return joinUrlSegments(attr,query); - }); + updateAttr("LINK#prevlink", "href", query); + updateAttr("LINK#nextlink", "href", query); + updateAttr("A#prevlink", "href", query); + updateAttr("A#nextlink", "href", query); + updateAttr("span#image_delete_form form", "action", query); } });