From 0b6dd17a05198c926f828180987cd0bf87bfa32c Mon Sep 17 00:00:00 2001 From: umorigu Date: Sat, 23 Sep 2017 03:27:29 +0900 Subject: [PATCH] Improve search2 : Support OR --- skin/search2.js | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/skin/search2.js b/skin/search2.js index 8a68b3b..e70957b 100644 --- a/skin/search2.js +++ b/skin/search2.js @@ -333,44 +333,51 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function( var url = loc.protocol + '//' + loc.host + loc.pathname + '?cmd=search2' + (base ? '&base=' + encodeURIComponent(base) : '') + - '&q=' + encodeURIComponent(q); + '&q=' + encodeSearthText(q); e.preventDefault(); setTimeout(function() { location.href = url; }, 1); return false; }); - } - f.querySelectorAll('input[type="radio"][name="type"]').forEach(function(radio){ - if (radio.value === 'AND') { - radio.addEventListener('click', onAndRadioClick); - } else if (radio.value === 'OR') { - radio.addEventListener('click', onOrRadioClick); - } - });; - function onAndRadioClick(e) { - var sp = removeSearchOperators(f.word.value).split(/\s+/); - var newText = sp.join(' '); - if (f.word.value !== newText) { - f.word.value = newText; + f.querySelectorAll('input[type="radio"][name="type"]').forEach(function(radio){ + if (radio.value === 'AND') { + radio.addEventListener('click', onAndRadioClick); + } else if (radio.value === 'OR') { + radio.addEventListener('click', onOrRadioClick); + } + });; + function onAndRadioClick(e) { + var sp = removeSearchOperators(f.word.value).split(/\s+/); + var newText = sp.join(' '); + if (f.word.value !== newText) { + f.word.value = newText; + } } - } - function onOrRadioClick(e) { - var sp = removeSearchOperators(f.word.value).split(/\s+/); - var newText = sp.join(' OR '); - if (f.word.value !== newText) { - f.word.value = newText; + function onOrRadioClick(e) { + var sp = removeSearchOperators(f.word.value).split(/\s+/); + var newText = sp.join(' OR '); + if (f.word.value !== newText) { + f.word.value = newText; + } } } }); + function encodeSearthText(q) { + var sp = q.split(/\s+/); + for (var i = 0; i < sp.length; i++) { + sp[i] = encodeURIComponent(sp[i]); + } + return sp.join('+'); + } } - function isEnabledFunctions() { + function isEnabledFetchFunctions() { if (window.fetch && document.querySelector) { return true; } return false; } - if (! isEnabledFunctions()) return; + if (! isEnabledFetchFunctions()) return; replaceSearchWithSearch2(); hookSearch2(); removeEncodeHint(); -- 2.11.0