• R/O
  • HTTP
  • SSH
  • HTTPS

pukiwiki: Commit


Commit MetaInfo

Revision87408f4e6978e7d03bed8921218923fd81a08f81 (tree)
Time2020-03-12 00:01:49
Authorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/2507 StandardJs - JavaScript formatter - Remove semicolons

Install and execute standard:


npm install --save-dev standard
npx standard
npx standard --fix

Standard JS - JavaScript style guide, linter, and formatter
https://standardjs.com/

Change Summary

Incremental Difference

--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -13,6 +13,7 @@
1313 "vars-on-top": 0,
1414 "prefer-template": 0,
1515 "prefer-arrow-callback": 0,
16+ "semi": 0,
1617 "space-before-function-paren": 0,
1718 "no-plusplus": 0,
1819 "prefer-destructuring": 0,
--- a/package.json
+++ b/package.json
@@ -16,7 +16,7 @@
1616 "eslint-config-airbnb": "*",
1717 "eslint-plugin-import": "*",
1818 "eslint-plugin-jsx-a11y": "*",
19- "eslint-plugin-react": "*"
19+ "eslint-plugin-react": "*",
20+ "standard": "^14.3.1"
2021 }
2122 }
22-
--- a/skin/main.js
+++ b/skin/main.js
@@ -1,615 +1,617 @@
11 // PukiWiki - Yet another WikiWikiWeb clone.
22 // main.js
3-// Copyright 2017-2019 PukiWiki Development Team
3+// Copyright 2017-2020 PukiWiki Development Team
44 // License: GPL v2 or (at your option) any later version
55 //
66 // PukiWiki JavaScript client script
7-window.addEventListener && window.addEventListener('DOMContentLoaded', function() { // eslint-disable-line no-unused-expressions
8- 'use strict';
7+/* eslint-env browser */
8+// eslint-disable-next-line no-unused-expressions
9+window.addEventListener && window.addEventListener('DOMContentLoaded', function () {
10+ 'use strict'
911 /**
1012 * @param {NodeList} nodeList
1113 * @param {function(Node, number): void} func
1214 */
13- function forEach(nodeList, func) {
15+ function forEach (nodeList, func) {
1416 if (nodeList.forEach) {
15- nodeList.forEach(func);
17+ nodeList.forEach(func)
1618 } else {
1719 for (var i = 0, n = nodeList.length; i < n; i++) {
18- func(nodeList[i], i);
20+ func(nodeList[i], i)
1921 }
2022 }
2123 }
2224 // Name for comment
23- function setYourName() {
24- var NAME_KEY_ID = 'pukiwiki_comment_plugin_name';
25- var actionPathname = null;
26- function getPathname(formAction) {
27- if (actionPathname) return actionPathname;
25+ function setYourName () {
26+ var NAME_KEY_ID = 'pukiwiki_comment_plugin_name'
27+ var actionPathname = null
28+ function getPathname (formAction) {
29+ if (actionPathname) return actionPathname
2830 try {
29- var u = new URL(formAction, document.location);
30- var u2 = new URL('./', u);
31- actionPathname = u2.pathname;
32- return u2.pathname;
31+ var u = new URL(formAction, document.location)
32+ var u2 = new URL('./', u)
33+ actionPathname = u2.pathname
34+ return u2.pathname
3335 } catch (e) {
3436 // Note: Internet Explorer doesn't support URL class
35- var m = formAction.match(/^https?:\/\/([^/]+)(\/([^?&]+\/)?)/);
37+ var m = formAction.match(/^https?:\/\/([^/]+)(\/([^?&]+\/)?)/)
3638 if (m) {
37- actionPathname = m[2]; // pathname
39+ actionPathname = m[2] // pathname
3840 } else {
39- actionPathname = '/';
41+ actionPathname = '/'
4042 }
41- return actionPathname;
43+ return actionPathname
4244 }
4345 }
44- function getNameKey(form) {
45- var pathname = getPathname(form.action);
46- var key = 'path.' + pathname + '.' + NAME_KEY_ID;
47- return key;
46+ function getNameKey (form) {
47+ var pathname = getPathname(form.action)
48+ var key = 'path.' + pathname + '.' + NAME_KEY_ID
49+ return key
4850 }
49- function getForm(element) {
51+ function getForm (element) {
5052 if (element.form && element.form.tagName === 'FORM') {
51- return element.form;
53+ return element.form
5254 }
53- var e = element.parentElement;
55+ var e = element.parentElement
5456 for (var i = 0; i < 5; i++) {
5557 if (e.tagName === 'FORM') {
56- return e;
58+ return e
5759 }
58- e = e.parentElement;
60+ e = e.parentElement
5961 }
60- return null;
62+ return null
6163 }
62- function handleCommentPlugin(form) {
63- var namePrevious = '';
64- var nameKey = getNameKey(form);
64+ function handleCommentPlugin (form) {
65+ var namePrevious = ''
66+ var nameKey = getNameKey(form)
6567 if (typeof localStorage !== 'undefined') {
66- namePrevious = localStorage[nameKey];
68+ namePrevious = localStorage[nameKey]
6769 }
6870 var onFocusForm = function () {
6971 if (form.name && !form.name.value && namePrevious) {
70- form.name.value = namePrevious;
72+ form.name.value = namePrevious
7173 }
72- };
73- var addOnForcusForm = function(eNullable) {
74- if (!eNullable) return;
74+ }
75+ var addOnForcusForm = function (eNullable) {
76+ if (!eNullable) return
7577 if (eNullable.addEventListener) {
76- eNullable.addEventListener('focus', onFocusForm);
78+ eNullable.addEventListener('focus', onFocusForm)
7779 }
78- };
80+ }
7981 if (namePrevious) {
80- var textList = form.querySelectorAll('input[type=text],textarea');
82+ var textList = form.querySelectorAll('input[type=text],textarea')
8183 textList.forEach(function (v) {
82- addOnForcusForm(v);
83- });
84+ addOnForcusForm(v)
85+ })
8486 }
85- form.addEventListener('submit', function() {
87+ form.addEventListener('submit', function () {
8688 if (typeof localStorage !== 'undefined') {
87- localStorage[nameKey] = form.name.value;
89+ localStorage[nameKey] = form.name.value
8890 }
89- }, false);
91+ }, false)
9092 }
91- function setNameForComment() {
92- if (!document.querySelectorAll) return;
93+ function setNameForComment () {
94+ if (!document.querySelectorAll) return
9395 var elements = document.querySelectorAll(
9496 'input[type=hidden][name=plugin][value=comment],' +
9597 'input[type=hidden][name=plugin][value=pcomment],' +
9698 'input[type=hidden][name=plugin][value=article],' +
97- 'input[type=hidden][name=plugin][value=bugtrack]');
99+ 'input[type=hidden][name=plugin][value=bugtrack]')
98100 for (var i = 0; i < elements.length; i++) {
99- var form = getForm(elements[i]);
101+ var form = getForm(elements[i])
100102 if (form) {
101- handleCommentPlugin(form);
103+ handleCommentPlugin(form)
102104 }
103105 }
104106 }
105- setNameForComment();
107+ setNameForComment()
106108 }
107109 // AutoTicketLink
108- function autoTicketLink() {
109- var headReText = '([\\s\\b:\\[\\(,;]|^)';
110- var tailReText = '\\b';
110+ function autoTicketLink () {
111+ var headReText = '([\\s\\b:\\[\\(,;]|^)'
112+ var tailReText = '\\b'
111113 var ignoreTags = ['A', 'INPUT', 'TEXTAREA', 'BUTTON',
112- 'SCRIPT', 'FRAME', 'IFRAME'];
113- var ticketSiteList = [];
114- var jiraProjects = null;
115- var jiraDefaultInfo = null;
116- function regexEscape(key) {
114+ 'SCRIPT', 'FRAME', 'IFRAME']
115+ var ticketSiteList = []
116+ var jiraProjects = null
117+ var jiraDefaultInfo = null
118+ function regexEscape (key) {
117119 return key.replace(/[-.]/g, function (m) {
118- return '\\' + m;
119- });
120+ return '\\' + m
121+ })
120122 }
121- function setupSites(siteList) {
123+ function setupSites (siteList) {
122124 for (var i = 0, length = siteList.length; i < length; i++) {
123- var site = siteList[i];
124- var reText = '';
125+ var site = siteList[i]
126+ var reText = ''
125127 switch (site.type) {
126128 case 'jira':
127129 reText = '(' + regexEscape(site.key) +
128- '):([A-Z][A-Z0-9]{1,20}(?:_[A-Z0-9]{1,10}){0,2}-\\d{1,10})';
129- break;
130+ '):([A-Z][A-Z0-9]{1,20}(?:_[A-Z0-9]{1,10}){0,2}-\\d{1,10})'
131+ break
130132 case 'redmine':
131- reText = '(' + regexEscape(site.key) + '):(\\d{1,10})';
132- break;
133+ reText = '(' + regexEscape(site.key) + '):(\\d{1,10})'
134+ break
133135 case 'git':
134- reText = '(' + regexEscape(site.key) + '):([0-9a-f]{7,40})';
135- break;
136+ reText = '(' + regexEscape(site.key) + '):([0-9a-f]{7,40})'
137+ break
136138 default:
137- continue;
139+ continue
138140 }
139- site.reText = reText;
140- site.re = new RegExp(headReText + reText + tailReText);
141+ site.reText = reText
142+ site.re = new RegExp(headReText + reText + tailReText)
141143 }
142144 }
143- function getJiraSite() {
144- var reText = '()([A-Z][A-Z0-9]{1,20}(?:_[A-Z0-9]{1,10}){0,2}-\\d{1,10})';
145+ function getJiraSite () {
146+ var reText = '()([A-Z][A-Z0-9]{1,20}(?:_[A-Z0-9]{1,10}){0,2}-\\d{1,10})'
145147 var site = {
146148 title: 'Builtin JIRA',
147149 type: '_jira_',
148150 key: '_jira_',
149151 reText: reText,
150152 re: new RegExp(headReText + reText + tailReText)
151- };
152- return site;
153+ }
154+ return site
153155 }
154- function getSiteListFromBody() {
155- var defRoot = document.querySelector('#pukiwiki-site-properties .ticketlink-def');
156+ function getSiteListFromBody () {
157+ var defRoot = document.querySelector('#pukiwiki-site-properties .ticketlink-def')
156158 if (defRoot && defRoot.value) {
157- var list = JSON.parse(defRoot.value);
158- setupSites(list);
159- return list;
159+ var list = JSON.parse(defRoot.value)
160+ setupSites(list)
161+ return list
160162 }
161- return [];
163+ return []
162164 }
163- function getJiraProjectsFromBody() {
164- var defRoot = document.querySelector('#pukiwiki-site-properties .ticketlink-jira-def');
165+ function getJiraProjectsFromBody () {
166+ var defRoot = document.querySelector('#pukiwiki-site-properties .ticketlink-jira-def')
165167 if (defRoot && defRoot.value) {
166168 try {
167- return JSON.parse(defRoot.value); // List
169+ return JSON.parse(defRoot.value) // List
168170 } catch (e) {
169- return null;
171+ return null
170172 }
171173 }
172- return null;
174+ return null
173175 }
174- function getJiraDefaultInfoFromBody() {
175- var defRoot = document.querySelector('#pukiwiki-site-properties .ticketlink-jira-default-def');
176+ function getJiraDefaultInfoFromBody () {
177+ var defRoot = document.querySelector('#pukiwiki-site-properties .ticketlink-jira-default-def')
176178 if (defRoot && defRoot.value) {
177179 try {
178- return JSON.parse(defRoot.value); // object
180+ return JSON.parse(defRoot.value) // object
179181 } catch (e) {
180- return null;
182+ return null
181183 }
182184 }
183- return null;
185+ return null
184186 }
185- function getSiteList() {
186- return ticketSiteList;
187+ function getSiteList () {
188+ return ticketSiteList
187189 }
188- function getJiraProjectList() {
189- return jiraProjects;
190+ function getJiraProjectList () {
191+ return jiraProjects
190192 }
191- function getDefaultJira() {
192- return jiraDefaultInfo;
193+ function getDefaultJira () {
194+ return jiraDefaultInfo
193195 }
194- function ticketToLink(keyText) {
195- var siteList = getSiteList();
196+ function ticketToLink (keyText) {
197+ var siteList = getSiteList()
196198 for (var i = 0; i < siteList.length; i++) {
197- var site = siteList[i];
198- var m = keyText.match(site.re);
199+ var site = siteList[i]
200+ var m = keyText.match(site.re)
199201 if (m) {
200- var ticketKey = m[3];
201- var title = ticketKey;
202- var ticketUrl;
202+ var ticketKey = m[3]
203+ var title = ticketKey
204+ var ticketUrl
203205 if (site.type === '_jira_') {
204206 // JIRA issue
205- var projects = getJiraProjectList();
206- var hyphen = keyText.indexOf('-');
207+ var projects = getJiraProjectList()
208+ var hyphen = keyText.indexOf('-')
207209 if (hyphen > 0) {
208- var projectKey = keyText.substr(0, hyphen);
210+ var projectKey = keyText.substr(0, hyphen)
209211 if (projects) {
210212 for (var j = 0; j < projects.length; j++) {
211- var p = projects[j];
213+ var p = projects[j]
212214 if (p.key === projectKey) {
213215 if (p.title) {
214- title = p.title.replace(/\$1/g, ticketKey);
216+ title = p.title.replace(/\$1/g, ticketKey)
215217 }
216- ticketUrl = p.base_url + ticketKey;
217- break;
218+ ticketUrl = p.base_url + ticketKey
219+ break
218220 }
219221 }
220222 }
221223 if (!ticketUrl) {
222- var defaultJira = getDefaultJira();
224+ var defaultJira = getDefaultJira()
223225 if (defaultJira) {
224226 if (defaultJira.title) {
225- title = defaultJira.title.replace(/\$1/g, ticketKey);
227+ title = defaultJira.title.replace(/\$1/g, ticketKey)
226228 }
227- ticketUrl = defaultJira.base_url + ticketKey;
229+ ticketUrl = defaultJira.base_url + ticketKey
228230 }
229231 }
230232 }
231233 if (!ticketUrl) {
232- return null;
234+ return null
233235 }
234236 } else {
235237 // Explicit TicketLink
236238 if (site.title) {
237- title = site.title.replace(/\$1/g, ticketKey);
239+ title = site.title.replace(/\$1/g, ticketKey)
238240 }
239- ticketUrl = site.base_url + ticketKey;
241+ ticketUrl = site.base_url + ticketKey
240242 }
241243 return {
242244 url: ticketUrl,
243245 title: title
244- };
246+ }
245247 }
246248 }
247- return null;
249+ return null
248250 }
249- function getRegex(list) {
250- var reText = '';
251+ function getRegex (list) {
252+ var reText = ''
251253 for (var i = 0, length = list.length; i < length; i++) {
252254 if (reText.length > 0) {
253- reText += '|';
255+ reText += '|'
254256 }
255- reText += list[i].reText;
257+ reText += list[i].reText
256258 }
257- return new RegExp(headReText + '(' + reText + ')' + tailReText);
259+ return new RegExp(headReText + '(' + reText + ')' + tailReText)
258260 }
259- function makeTicketLink(element) {
260- var siteList = getSiteList();
261+ function makeTicketLink (element) {
262+ var siteList = getSiteList()
261263 if (!siteList || siteList.length === 0) {
262- return;
264+ return
263265 }
264- var re = getRegex(siteList);
265- var f;
266- var m;
267- var text = element.nodeValue;
266+ var re = getRegex(siteList)
267+ var f
268+ var m
269+ var text = element.nodeValue
268270 while (m = text.match(re)) { // eslint-disable-line no-cond-assign
269271 // m[1]: head, m[2]: keyText
270272 if (!f) {
271- f = document.createDocumentFragment();
273+ f = document.createDocumentFragment()
272274 }
273275 if (m.index > 0 || m[1].length > 0) {
274- f.appendChild(document.createTextNode(text.substr(0, m.index) + m[1]));
276+ f.appendChild(document.createTextNode(text.substr(0, m.index) + m[1]))
275277 }
276- var linkKey = m[2];
277- var linkInfo = ticketToLink(linkKey);
278+ var linkKey = m[2]
279+ var linkInfo = ticketToLink(linkKey)
278280 if (linkInfo) {
279- var a = document.createElement('a');
280- a.textContent = linkKey;
281- a.href = linkInfo.url;
282- a.title = linkInfo.title;
283- f.appendChild(a);
281+ var a = document.createElement('a')
282+ a.textContent = linkKey
283+ a.href = linkInfo.url
284+ a.title = linkInfo.title
285+ f.appendChild(a)
284286 } else {
285- f.appendChild(document.createTextNode(m[2]));
287+ f.appendChild(document.createTextNode(m[2]))
286288 }
287- text = text.substr(m.index + m[0].length);
289+ text = text.substr(m.index + m[0].length)
288290 }
289291 if (f) {
290292 if (text.length > 0) {
291- f.appendChild(document.createTextNode(text));
293+ f.appendChild(document.createTextNode(text))
292294 }
293- element.parentNode.replaceChild(f, element);
295+ element.parentNode.replaceChild(f, element)
294296 }
295297 }
296- function walkElement(element) {
297- var e = element.firstChild;
298+ function walkElement (element) {
299+ var e = element.firstChild
298300 while (e) {
299301 if (e.nodeType === 3 && e.nodeValue &&
300302 e.nodeValue.length > 5 && /\S/.test(e.nodeValue)) {
301- var next = e.nextSibling;
302- makeTicketLink(e);
303- e = next;
303+ var next = e.nextSibling
304+ makeTicketLink(e)
305+ e = next
304306 } else {
305307 if (e.nodeType === 1 && ignoreTags.indexOf(e.tagName) === -1) {
306- walkElement(e);
308+ walkElement(e)
307309 }
308- e = e.nextSibling;
310+ e = e.nextSibling
309311 }
310312 }
311313 }
312314 if (!Array.prototype.indexOf || !document.createDocumentFragment) {
313- return;
315+ return
314316 }
315- ticketSiteList = getSiteListFromBody();
316- jiraProjects = getJiraProjectsFromBody();
317- jiraDefaultInfo = getJiraDefaultInfoFromBody();
317+ ticketSiteList = getSiteListFromBody()
318+ jiraProjects = getJiraProjectsFromBody()
319+ jiraDefaultInfo = getJiraDefaultInfoFromBody()
318320 if (jiraDefaultInfo || (jiraProjects && jiraProjects.length > 0)) {
319- ticketSiteList.push(getJiraSite());
321+ ticketSiteList.push(getJiraSite())
320322 }
321- var target = document.getElementById('body');
322- walkElement(target);
323+ var target = document.getElementById('body')
324+ walkElement(target)
323325 }
324- function confirmEditFormLeaving() {
325- function trim(s) {
326+ function confirmEditFormLeaving () {
327+ function trim (s) {
326328 if (typeof s !== 'string') {
327- return s;
328- }
329- return s.replace(/^\s+|\s+$/g, '');
330- }
331- if (!document.querySelector) return;
332- var canceled = false;
333- var pluginNameE = document.querySelector('#pukiwiki-site-properties .plugin-name');
334- if (!pluginNameE) return;
335- var originalText = null;
336- if (pluginNameE.value !== 'edit') return;
337- var editForm = document.querySelector('.edit_form form._plugin_edit_edit_form');
338- if (!editForm) return;
339- var cancelMsgE = editForm.querySelector('#_msg_edit_cancel_confirm');
340- var unloadBeforeMsgE = editForm.querySelector('#_msg_edit_unloadbefore_message');
341- var textArea = editForm.querySelector('textarea[name="msg"]');
342- if (!textArea) return;
343- originalText = textArea.value;
344- var isPreview = false;
345- var inEditE = document.querySelector('#pukiwiki-site-properties .page-in-edit');
329+ return s
330+ }
331+ return s.replace(/^\s+|\s+$/g, '')
332+ }
333+ if (!document.querySelector) return
334+ var canceled = false
335+ var pluginNameE = document.querySelector('#pukiwiki-site-properties .plugin-name')
336+ if (!pluginNameE) return
337+ var originalText = null
338+ if (pluginNameE.value !== 'edit') return
339+ var editForm = document.querySelector('.edit_form form._plugin_edit_edit_form')
340+ if (!editForm) return
341+ var cancelMsgE = editForm.querySelector('#_msg_edit_cancel_confirm')
342+ var unloadBeforeMsgE = editForm.querySelector('#_msg_edit_unloadbefore_message')
343+ var textArea = editForm.querySelector('textarea[name="msg"]')
344+ if (!textArea) return
345+ originalText = textArea.value
346+ var isPreview = false
347+ var inEditE = document.querySelector('#pukiwiki-site-properties .page-in-edit')
346348 if (inEditE && inEditE.value) {
347- isPreview = (inEditE.value === 'true');
348- }
349- var cancelForm = document.querySelector('.edit_form form._plugin_edit_cancel');
350- var submited = false;
351- editForm.addEventListener('submit', function() {
352- canceled = false;
353- submited = true;
354- });
355- cancelForm.addEventListener('submit', function(e) {
356- submited = false;
357- canceled = false;
349+ isPreview = (inEditE.value === 'true')
350+ }
351+ var cancelForm = document.querySelector('.edit_form form._plugin_edit_cancel')
352+ var submited = false
353+ editForm.addEventListener('submit', function () {
354+ canceled = false
355+ submited = true
356+ })
357+ cancelForm.addEventListener('submit', function (e) {
358+ submited = false
359+ canceled = false
358360 if (trim(textArea.value) === trim(originalText)) {
359- canceled = true;
360- return false;
361+ canceled = true
362+ return false
361363 }
362- var message = 'The text you have entered will be discarded. Is it OK?';
364+ var message = 'The text you have entered will be discarded. Is it OK?'
363365 if (cancelMsgE && cancelMsgE.value) {
364- message = cancelMsgE.value;
366+ message = cancelMsgE.value
365367 }
366368 if (window.confirm(message)) { // eslint-disable-line no-alert
367369 // Execute "Cancel"
368- canceled = true;
369- return true;
370- }
371- e.preventDefault();
372- return false;
373- });
374- window.addEventListener('beforeunload', function(e) {
375- if (canceled) return;
376- if (submited) return;
370+ canceled = true
371+ return true
372+ }
373+ e.preventDefault()
374+ return false
375+ })
376+ window.addEventListener('beforeunload', function (e) {
377+ if (canceled) return
378+ if (submited) return
377379 if (!isPreview) {
378- if (trim(textArea.value) === trim(originalText)) return;
380+ if (trim(textArea.value) === trim(originalText)) return
379381 }
380- var message = 'Data you have entered will not be saved.';
382+ var message = 'Data you have entered will not be saved.'
381383 if (unloadBeforeMsgE && unloadBeforeMsgE.value) {
382- message = unloadBeforeMsgE.value;
384+ message = unloadBeforeMsgE.value
383385 }
384- e.returnValue = message;
385- }, false);
386+ e.returnValue = message
387+ }, false)
386388 }
387- function showPagePassage() {
389+ function showPagePassage () {
388390 /**
389391 * @param {Date} now
390392 * @param {string} dateText
391393 */
392- function getSimplePassage(dateText, now) {
394+ function getSimplePassage (dateText, now) {
393395 if (!dateText) {
394- return '';
396+ return ''
395397 }
396- var units = [{u: 'm', max: 60}, {u: 'h', max: 24}, {u: 'd', max: 1}];
397- var d = new Date();
398- d.setTime(Date.parse(dateText));
399- var t = (now.getTime() - d.getTime()) / (1000 * 60); // minutes
400- var unit = units[0].u; var card = units[0].max;
398+ var units = [{ u: 'm', max: 60 }, { u: 'h', max: 24 }, { u: 'd', max: 1 }]
399+ var d = new Date()
400+ d.setTime(Date.parse(dateText))
401+ var t = (now.getTime() - d.getTime()) / (1000 * 60) // minutes
402+ var unit = units[0].u; var card = units[0].max
401403 for (var i = 0; i < units.length; i++) {
402- unit = units[i].u; card = units[i].max;
403- if (t < card) break;
404- t = t / card;
404+ unit = units[i].u; card = units[i].max
405+ if (t < card) break
406+ t = t / card
405407 }
406- return '' + Math.floor(t) + unit;
408+ return '' + Math.floor(t) + unit
407409 }
408410 /**
409411 * @param {Date} now
410412 * @param {string} dateText
411413 */
412- function getPassage(dateText, now) {
413- return '(' + getSimplePassage(dateText, now) + ')';
414+ function getPassage (dateText, now) {
415+ return '(' + getSimplePassage(dateText, now) + ')'
414416 }
415- var now = new Date();
416- var elements = document.getElementsByClassName('page_passage');
417- forEach(elements, function(e) {
418- var dt = e.getAttribute('data-mtime');
417+ var now = new Date()
418+ var elements = document.getElementsByClassName('page_passage')
419+ forEach(elements, function (e) {
420+ var dt = e.getAttribute('data-mtime')
419421 if (dt) {
420- var d = new Date(dt);
421- e.textContent = ' ' + getPassage(d, now);
422+ var d = new Date(dt)
423+ e.textContent = ' ' + getPassage(d, now)
422424 }
423- });
424- var links = document.getElementsByClassName('link_page_passage');
425- forEach(links, function(e) {
426- var dt = e.getAttribute('data-mtime');
425+ })
426+ var links = document.getElementsByClassName('link_page_passage')
427+ forEach(links, function (e) {
428+ var dt = e.getAttribute('data-mtime')
427429 if (dt) {
428- var d = new Date(dt);
430+ var d = new Date(dt)
429431 if (e.title) {
430- e.title = e.title + ' ' + getPassage(d, now);
432+ e.title = e.title + ' ' + getPassage(d, now)
431433 } else {
432- e.title = e.textContent + ' ' + getPassage(d, now);
434+ e.title = e.textContent + ' ' + getPassage(d, now)
433435 }
434436 }
435- });
436- var simplePassages = document.getElementsByClassName('simple_passage');
437- forEach(simplePassages, function(e) {
438- var dt = e.getAttribute('data-mtime');
437+ })
438+ var simplePassages = document.getElementsByClassName('simple_passage')
439+ forEach(simplePassages, function (e) {
440+ var dt = e.getAttribute('data-mtime')
439441 if (dt) {
440- var d = new Date(dt);
441- e.textContent = getSimplePassage(d, now);
442+ var d = new Date(dt)
443+ e.textContent = getSimplePassage(d, now)
442444 }
443- });
445+ })
444446 // new plugin
445- var newItems = document.getElementsByClassName('__plugin_new');
446- forEach(newItems, function(e) {
447- var dt = e.getAttribute('data-mtime');
447+ var newItems = document.getElementsByClassName('__plugin_new')
448+ forEach(newItems, function (e) {
449+ var dt = e.getAttribute('data-mtime')
448450 if (dt) {
449- var d = new Date(dt);
450- var diff = now.getTime() - d.getTime();
451- var daySpan = diff / 1000 / 60 / 60 / 24;
451+ var d = new Date(dt)
452+ var diff = now.getTime() - d.getTime()
453+ var daySpan = diff / 1000 / 60 / 60 / 24
452454 if (daySpan < 1) {
453- e.textContent = ' New!';
454- e.title = getPassage(d, now);
455+ e.textContent = ' New!'
456+ e.title = getPassage(d, now)
455457 if (e.classList && e.classList.add) {
456- e.classList.add('new1');
458+ e.classList.add('new1')
457459 }
458460 } else if (daySpan < 5) {
459- e.textContent = ' New';
460- e.title = getPassage(d, now);
461+ e.textContent = ' New'
462+ e.title = getPassage(d, now)
461463 if (e.classList && e.classList.add) {
462- e.classList.add('new5');
464+ e.classList.add('new5')
463465 }
464466 }
465467 }
466- });
468+ })
467469 }
468- function convertExternalLinkToCushionPageLink() {
469- function domainQuote(domain) {
470- return domain.replace(/\./g, '\\.');
470+ function convertExternalLinkToCushionPageLink () {
471+ function domainQuote (domain) {
472+ return domain.replace(/\./g, '\\.')
471473 }
472- function domainsToRegex(domains) {
473- var regexList = [];
474- domains.forEach(function(domain) {
474+ function domainsToRegex (domains) {
475+ var regexList = []
476+ domains.forEach(function (domain) {
475477 if (domain.substr(0, 2) === '*.') {
476478 // Wildcard domain
477- var apex = domain.substr(2);
478- var r = new RegExp('((^.*\\.)|^)' + domainQuote(apex) + '$', 'i');
479- regexList.push(r);
479+ var apex = domain.substr(2)
480+ var r = new RegExp('((^.*\\.)|^)' + domainQuote(apex) + '$', 'i')
481+ regexList.push(r)
480482 } else {
481483 // Normal domain
482- regexList.push(new RegExp('^' + domainQuote(domain) + '$', 'i'));
484+ regexList.push(new RegExp('^' + domainQuote(domain) + '$', 'i'))
483485 }
484- });
485- return regexList;
486+ })
487+ return regexList
486488 }
487- function domainMatch(domain, regexList) {
489+ function domainMatch (domain, regexList) {
488490 for (var i = 0, n = regexList.length; i < n; i++) {
489491 if (regexList[i].test(domain)) {
490- return true;
492+ return true
491493 }
492494 }
493- return false;
495+ return false
494496 }
495- function removeCushionPageLinks() {
496- var links = document.querySelectorAll('a.external-link');
497- forEach(links, function(link) {
498- var originalUrl = link.getAttribute('data-original-url');
497+ function removeCushionPageLinks () {
498+ var links = document.querySelectorAll('a.external-link')
499+ forEach(links, function (link) {
500+ var originalUrl = link.getAttribute('data-original-url')
499501 if (originalUrl) {
500- link.setAttribute('href', originalUrl);
502+ link.setAttribute('href', originalUrl)
501503 }
502- });
503- }
504- if (!document.querySelector || !JSON) return;
505- if (!Array || !Array.prototype || !Array.prototype.indexOf) return;
506- var extLinkDef = document.querySelector('#pukiwiki-site-properties .external-link-cushion');
507- if (!extLinkDef || !extLinkDef.value) return;
508- var extLinkInfo = JSON.parse(extLinkDef.value);
509- if (!extLinkInfo) return;
510- var refInternalDomains = extLinkInfo.internal_domains;
511- var silentExternalDomains = extLinkInfo.silent_external_domains;
504+ })
505+ }
506+ if (!document.querySelector || !JSON) return
507+ if (!Array || !Array.prototype || !Array.prototype.indexOf) return
508+ var extLinkDef = document.querySelector('#pukiwiki-site-properties .external-link-cushion')
509+ if (!extLinkDef || !extLinkDef.value) return
510+ var extLinkInfo = JSON.parse(extLinkDef.value)
511+ if (!extLinkInfo) return
512+ var refInternalDomains = extLinkInfo.internal_domains
513+ var silentExternalDomains = extLinkInfo.silent_external_domains
512514 if (!Array.isArray(refInternalDomains)) {
513- refInternalDomains = [];
515+ refInternalDomains = []
514516 }
515- var internalDomains = refInternalDomains.slice();
516- var location = document.location;
517+ var internalDomains = refInternalDomains.slice()
518+ var location = document.location
517519 if (location.protocol === 'file:') {
518- removeCushionPageLinks();
519- return;
520+ removeCushionPageLinks()
521+ return
520522 }
521- if (location.protocol !== 'http:' && location.protocol !== 'https:') return;
523+ if (location.protocol !== 'http:' && location.protocol !== 'https:') return
522524 if (internalDomains.indexOf(location.hostname) < 0) {
523- internalDomains.push(location.hostname);
525+ internalDomains.push(location.hostname)
524526 }
525527 if (!Array.isArray(silentExternalDomains)) {
526- silentExternalDomains = [];
527- }
528- var propsE = document.querySelector('#pukiwiki-site-properties .site-props');
529- if (!propsE || !propsE.value) return;
530- var siteProps = JSON.parse(propsE.value);
531- var sitePathname = siteProps && siteProps.base_uri_pathname;
532- if (!sitePathname) return;
533- var internalDomainsR = domainsToRegex(internalDomains);
534- var silentExternalDomainsR = domainsToRegex(silentExternalDomains);
535- var links = document.querySelectorAll('a:not(.external-link):not(.internal-link)');
536- var classListEnabled = null;
537- forEach(links, function(link) {
528+ silentExternalDomains = []
529+ }
530+ var propsE = document.querySelector('#pukiwiki-site-properties .site-props')
531+ if (!propsE || !propsE.value) return
532+ var siteProps = JSON.parse(propsE.value)
533+ var sitePathname = siteProps && siteProps.base_uri_pathname
534+ if (!sitePathname) return
535+ var internalDomainsR = domainsToRegex(internalDomains)
536+ var silentExternalDomainsR = domainsToRegex(silentExternalDomains)
537+ var links = document.querySelectorAll('a:not(.external-link):not(.internal-link)')
538+ var classListEnabled = null
539+ forEach(links, function (link) {
538540 if (classListEnabled === null) {
539- classListEnabled = link.classList && link.classList.add && true;
541+ classListEnabled = link.classList && link.classList.add && true
540542 }
541- if (!classListEnabled) return;
542- var href = link.getAttribute('href');
543- if (!href) return; // anchor without href attribute (a name)
544- var m = href.match(/^https?:\/\/([0-9a-zA-Z.-]+)(:\d+)?/);
543+ if (!classListEnabled) return
544+ var href = link.getAttribute('href')
545+ if (!href) return // anchor without href attribute (a name)
546+ var m = href.match(/^https?:\/\/([0-9a-zA-Z.-]+)(:\d+)?/)
545547 if (m) {
546- var host = m[1];
548+ var host = m[1]
547549 if (domainMatch(host, internalDomainsR)) {
548- link.classList.add('internal-link');
550+ link.classList.add('internal-link')
549551 } else {
550552 if (domainMatch(host, silentExternalDomainsR) ||
551553 link.textContent.replace(/\s+/g, '') === '') {
552554 // Don't show extenal link icons on these domains
553- link.classList.add('external-link-silent');
555+ link.classList.add('external-link-silent')
554556 }
555- link.classList.add('external-link');
556- link.setAttribute('title', href);
557- link.setAttribute('data-original-url', href);
558- link.setAttribute('href', sitePathname + '?cmd=external_link&url=' + encodeURIComponent(href));
557+ link.classList.add('external-link')
558+ link.setAttribute('title', href)
559+ link.setAttribute('data-original-url', href)
560+ link.setAttribute('href', sitePathname + '?cmd=external_link&url=' + encodeURIComponent(href))
559561 }
560562 } else {
561- link.classList.add('internal-link');
563+ link.classList.add('internal-link')
562564 }
563- });
565+ })
564566 }
565- function makeTopicpathTitle() {
566- if (!document.createDocumentFragment || !window.JSON) return;
567- var sitePropE = document.querySelector('#pukiwiki-site-properties');
568- if (!sitePropE) return;
569- var pageNameE = sitePropE.querySelector('.page-name');
570- if (!pageNameE || !pageNameE.value) return;
571- var pageName = pageNameE.value;
572- var topicpathE = sitePropE.querySelector('.topicpath-links');
573- if (!topicpathE || !topicpathE.value) return;
574- var topicpathLinks = JSON.parse(topicpathE.value);
575- if (!topicpathLinks) return;
576- var titleH1 = document.querySelector('h1.title');
577- if (!titleH1) return;
578- var aList = titleH1.querySelectorAll('a');
579- if (!aList || aList.length > 1) return;
580- var a = titleH1.querySelector('a');
581- if (!a) return;
582- if (a.textContent !== pageName) return;
583- var fragment = document.createDocumentFragment();
567+ function makeTopicpathTitle () {
568+ if (!document.createDocumentFragment || !window.JSON) return
569+ var sitePropE = document.querySelector('#pukiwiki-site-properties')
570+ if (!sitePropE) return
571+ var pageNameE = sitePropE.querySelector('.page-name')
572+ if (!pageNameE || !pageNameE.value) return
573+ var pageName = pageNameE.value
574+ var topicpathE = sitePropE.querySelector('.topicpath-links')
575+ if (!topicpathE || !topicpathE.value) return
576+ var topicpathLinks = JSON.parse(topicpathE.value)
577+ if (!topicpathLinks) return
578+ var titleH1 = document.querySelector('h1.title')
579+ if (!titleH1) return
580+ var aList = titleH1.querySelectorAll('a')
581+ if (!aList || aList.length > 1) return
582+ var a = titleH1.querySelector('a')
583+ if (!a) return
584+ if (a.textContent !== pageName) return
585+ var fragment = document.createDocumentFragment()
584586 for (var i = 0, n = topicpathLinks.length; i < n; i++) {
585- var path = topicpathLinks[i];
587+ var path = topicpathLinks[i]
586588 if (path.uri) {
587- var a1 = document.createElement('a');
588- a1.setAttribute('href', path.uri);
589- a1.setAttribute('title', path.page);
590- a1.textContent = path.leaf;
591- fragment.appendChild(a1);
589+ var a1 = document.createElement('a')
590+ a1.setAttribute('href', path.uri)
591+ a1.setAttribute('title', path.page)
592+ a1.textContent = path.leaf
593+ fragment.appendChild(a1)
592594 } else {
593- var s1 = document.createElement('span');
594- s1.textContent = path.leaf;
595- fragment.appendChild(s1);
596- }
597- var span = document.createElement('span');
598- span.className = 'topicpath-slash';
599- span.textContent = '/';
600- fragment.appendChild(span);
601- }
602- var a2 = document.createElement('a');
603- a2.setAttribute('href', a.getAttribute('href'));
604- a2.setAttribute('title', 'Backlinks');
605- a2.textContent = a.textContent.replace(/^.+\//, '');
606- fragment.appendChild(a2);
607- a.parentNode.replaceChild(fragment, a);
595+ var s1 = document.createElement('span')
596+ s1.textContent = path.leaf
597+ fragment.appendChild(s1)
598+ }
599+ var span = document.createElement('span')
600+ span.className = 'topicpath-slash'
601+ span.textContent = '/'
602+ fragment.appendChild(span)
603+ }
604+ var a2 = document.createElement('a')
605+ a2.setAttribute('href', a.getAttribute('href'))
606+ a2.setAttribute('title', 'Backlinks')
607+ a2.textContent = a.textContent.replace(/^.+\//, '')
608+ fragment.appendChild(a2)
609+ a.parentNode.replaceChild(fragment, a)
608610 }
609- setYourName();
610- autoTicketLink();
611- confirmEditFormLeaving();
612- showPagePassage();
613- convertExternalLinkToCushionPageLink();
614- makeTopicpathTitle();
615-});
611+ setYourName()
612+ autoTicketLink()
613+ confirmEditFormLeaving()
614+ showPagePassage()
615+ convertExternalLinkToCushionPageLink()
616+ makeTopicpathTitle()
617+})
--- a/skin/search2.js
+++ b/skin/search2.js
@@ -1,116 +1,118 @@
11 // PukiWiki - Yet another WikiWikiWeb clone.
22 // search2.js
33 // Copyright
4-// 2017 PukiWiki Development Team
4+// 2017-2020 PukiWiki Development Team
55 // License: GPL v2 or (at your option) any later version
66 //
77 // PukiWiki search2 pluign - JavaScript client script
8-window.addEventListener && window.addEventListener('DOMContentLoaded', function() { // eslint-disable-line no-unused-expressions
9- 'use strict';
10- function enableSearch2() {
11- var aroundLines = 2;
12- var maxResultLines = 20;
13- var defaultSearchWaitMilliseconds = 100;
14- var defaultMaxResults = 1000;
15- var kanaMap = null;
16- var searchProps = {};
8+/* eslint-env browser */
9+// eslint-disable-next-line no-unused-expressions
10+window.addEventListener && window.addEventListener('DOMContentLoaded', function () {
11+ 'use strict'
12+ function enableSearch2 () {
13+ var aroundLines = 2
14+ var maxResultLines = 20
15+ var defaultSearchWaitMilliseconds = 100
16+ var defaultMaxResults = 1000
17+ var kanaMap = null
18+ var searchProps = {}
1719 /**
1820 * Escape HTML special charactors
1921 *
2022 * @param {string} s
2123 */
22- function escapeHTML(s) {
24+ function escapeHTML (s) {
2325 if (typeof s !== 'string') {
24- return '' + s;
26+ return '' + s
2527 }
26- return s.replace(/[&"<>]/g, function(m) {
28+ return s.replace(/[&"<>]/g, function (m) {
2729 return {
2830 '&': '&amp;',
2931 '"': '&quot;',
3032 '<': '&lt;',
3133 '>': '&gt;'
32- }[m];
33- });
34+ }[m]
35+ })
3436 }
3537 /**
3638 * @param {string} idText
3739 * @param {number} defaultValue
3840 * @type number
3941 */
40- function getIntById(idText, defaultValue) {
41- var value = defaultValue;
42+ function getIntById (idText, defaultValue) {
43+ var value = defaultValue
4244 try {
43- var element = document.getElementById(idText);
45+ var element = document.getElementById(idText)
4446 if (element) {
45- value = parseInt(element.value, 10);
47+ value = parseInt(element.value, 10)
4648 if (isNaN(value)) { // eslint-disable-line no-restricted-globals
47- value = defaultValue;
49+ value = defaultValue
4850 }
4951 }
5052 } catch (e) {
51- value = defaultValue;
53+ value = defaultValue
5254 }
53- return value;
55+ return value
5456 }
5557 /**
5658 * @param {string} idText
5759 * @param {string} defaultValue
5860 * @type string
5961 */
60- function getTextById(idText, defaultValue) {
61- var value = defaultValue;
62+ function getTextById (idText, defaultValue) {
63+ var value = defaultValue
6264 try {
63- var element = document.getElementById(idText);
65+ var element = document.getElementById(idText)
6466 if (element.value) {
65- value = element.value;
67+ value = element.value
6668 }
6769 } catch (e) {
68- value = defaultValue;
70+ value = defaultValue
6971 }
70- return value;
72+ return value
7173 }
72- function prepareSearchProps() {
73- var p = {};
74+ function prepareSearchProps () {
75+ var p = {}
7476 p.errorMsg = getTextById('_plugin_search2_msg_error',
75- 'An error occurred while processing.');
77+ 'An error occurred while processing.')
7678 p.searchingMsg = getTextById('_plugin_search2_msg_searching',
77- 'Searching...');
79+ 'Searching...')
7880 p.showingResultMsg = getTextById('_plugin_search2_msg_showing_result',
79- 'Showing search results');
80- p.prevOffset = getTextById('_plugin_search2_prev_offset', '');
81- var baseUrlDefault = document.location.pathname + document.location.search;
82- baseUrlDefault = baseUrlDefault.replace(/&offset=\d+/, '');
83- p.baseUrl = getTextById('_plugin_search2_base_url', baseUrlDefault);
84- p.msgPrevResultsTemplate = getTextById('_plugin_search2_msg_prev_results', 'Previous $1 pages');
85- p.msgMoreResultsTemplate = getTextById('_plugin_search2_msg_more_results', 'Next $1 pages');
86- p.user = getTextById('_plugin_search2_auth_user', '');
87- p.showingResultMsg = getTextById('_plugin_search2_msg_showing_result', 'Showing search results');
81+ 'Showing search results')
82+ p.prevOffset = getTextById('_plugin_search2_prev_offset', '')
83+ var baseUrlDefault = document.location.pathname + document.location.search
84+ baseUrlDefault = baseUrlDefault.replace(/&offset=\d+/, '')
85+ p.baseUrl = getTextById('_plugin_search2_base_url', baseUrlDefault)
86+ p.msgPrevResultsTemplate = getTextById('_plugin_search2_msg_prev_results', 'Previous $1 pages')
87+ p.msgMoreResultsTemplate = getTextById('_plugin_search2_msg_more_results', 'Next $1 pages')
88+ p.user = getTextById('_plugin_search2_auth_user', '')
89+ p.showingResultMsg = getTextById('_plugin_search2_msg_showing_result', 'Showing search results')
8890 p.notFoundMessageTemplate = getTextById('_plugin_search2_msg_result_notfound',
89- 'No page which contains $1 has been found.');
91+ 'No page which contains $1 has been found.')
9092 p.foundMessageTemplate = getTextById('_plugin_search2_msg_result_found',
91- 'In the page <strong>$2</strong>, <strong>$3</strong> pages that contain all the terms $1 were found.');
92- p.maxResults = getIntById('_plugin_search2_max_results', defaultMaxResults);
93- p.searchInterval = getIntById('_plugin_search2_search_wait_milliseconds', defaultSearchWaitMilliseconds);
94- p.offset = getIntById('_plugin_search2_offset', 0);
95- searchProps = p;
93+ 'In the page <strong>$2</strong>, <strong>$3</strong> pages that contain all the terms $1 were found.')
94+ p.maxResults = getIntById('_plugin_search2_max_results', defaultMaxResults)
95+ p.searchInterval = getIntById('_plugin_search2_search_wait_milliseconds', defaultSearchWaitMilliseconds)
96+ p.offset = getIntById('_plugin_search2_offset', 0)
97+ searchProps = p
9698 }
97- function getSiteProps() {
98- var empty = {};
99- var propsE = document.querySelector('#pukiwiki-site-properties .site-props');
100- if (!propsE) return empty;
101- var props = JSON.parse(propsE.value);
102- return props || empty;
99+ function getSiteProps () {
100+ var empty = {}
101+ var propsE = document.querySelector('#pukiwiki-site-properties .site-props')
102+ if (!propsE) return empty
103+ var props = JSON.parse(propsE.value)
104+ return props || empty
103105 }
104106 /**
105107 * @param {NodeList} nodeList
106108 * @param {function(Node, number): void} func
107109 */
108- function forEach(nodeList, func) {
110+ function forEach (nodeList, func) {
109111 if (nodeList.forEach) {
110- nodeList.forEach(func);
112+ nodeList.forEach(func)
111113 } else {
112114 for (var i = 0, n = nodeList.length; i < n; i++) {
113- func(nodeList[i], i);
115+ func(nodeList[i], i)
114116 }
115117 }
116118 }
@@ -118,34 +120,34 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
118120 * @param {string} text
119121 * @param {RegExp} searchRegex
120122 */
121- function findAndDecorateText(text, searchRegex) {
122- var isReplaced = false;
123- var lastIndex = 0;
124- var m;
125- var decorated = '';
126- if (!searchRegex) return null;
127- searchRegex.lastIndex = 0;
123+ function findAndDecorateText (text, searchRegex) {
124+ var isReplaced = false
125+ var lastIndex = 0
126+ var m
127+ var decorated = ''
128+ if (!searchRegex) return null
129+ searchRegex.lastIndex = 0
128130 while ((m = searchRegex.exec(text)) !== null) {
129131 if (m[0] === '') {
130132 // Fail-safe
131- console.log('Invalid searchRegex ' + searchRegex);
132- return null;
133+ console.log('Invalid searchRegex ' + searchRegex)
134+ return null
133135 }
134- isReplaced = true;
135- var pre = text.substring(lastIndex, m.index);
136- decorated += escapeHTML(pre);
136+ isReplaced = true
137+ var pre = text.substring(lastIndex, m.index)
138+ decorated += escapeHTML(pre)
137139 for (var i = 1; i < m.length; i++) {
138140 if (m[i]) {
139- decorated += '<strong class="word' + (i - 1) + '">' + escapeHTML(m[i]) + '</strong>';
141+ decorated += '<strong class="word' + (i - 1) + '">' + escapeHTML(m[i]) + '</strong>'
140142 }
141143 }
142- lastIndex = searchRegex.lastIndex;
144+ lastIndex = searchRegex.lastIndex
143145 }
144146 if (isReplaced) {
145- decorated += escapeHTML(text.substr(lastIndex));
146- return decorated;
147+ decorated += escapeHTML(text.substr(lastIndex))
148+ return decorated
147149 }
148- return null;
150+ return null
149151 }
150152 /**
151153 * @param {Object} session
@@ -153,200 +155,200 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
153155 * @param {RegExp} searchRegex
154156 * @param {boolean} nowSearching
155157 */
156- function getSearchResultMessage(session, searchText, searchRegex, nowSearching) {
157- var searchTextDecorated = findAndDecorateText(searchText, searchRegex);
158- if (searchTextDecorated === null) searchTextDecorated = escapeHTML(searchText);
159- var messageTemplate = searchProps.foundMessageTemplate;
158+ function getSearchResultMessage (session, searchText, searchRegex, nowSearching) {
159+ var searchTextDecorated = findAndDecorateText(searchText, searchRegex)
160+ if (searchTextDecorated === null) searchTextDecorated = escapeHTML(searchText)
161+ var messageTemplate = searchProps.foundMessageTemplate
160162 if (!nowSearching && session.hitPageCount === 0) {
161- messageTemplate = searchProps.notFoundMessageTemplate;
163+ messageTemplate = searchProps.notFoundMessageTemplate
162164 }
163- var msg = messageTemplate.replace(/\$1|\$2|\$3/g, function(m) {
165+ var msg = messageTemplate.replace(/\$1|\$2|\$3/g, function (m) {
164166 return {
165167 $1: searchTextDecorated,
166168 $2: session.hitPageCount,
167169 $3: session.readPageCount
168- }[m];
169- });
170- return msg;
170+ }[m]
171+ })
172+ return msg
171173 }
172174 /**
173175 * @param {Object} session
174176 */
175- function getSearchProgress(session) {
177+ function getSearchProgress (session) {
176178 var progress = '(read:' + session.readPageCount + ', scan:' +
177- session.scanPageCount + ', all:' + session.pageCount;
179+ session.scanPageCount + ', all:' + session.pageCount
178180 if (session.offset) {
179- progress += ', offset: ' + session.offset;
181+ progress += ', offset: ' + session.offset
180182 }
181- progress += ')';
182- return progress;
183+ progress += ')'
184+ return progress
183185 }
184186 /**
185187 * @param {Object} session
186188 * @param {number} maxResults
187189 */
188- function getOffsetLinks(session, maxResults) {
189- var baseUrl = searchProps.baseUrl;
190- var links = [];
190+ function getOffsetLinks (session, maxResults) {
191+ var baseUrl = searchProps.baseUrl
192+ var links = []
191193 if ('prevOffset' in session) {
192- var prevResultUrl = baseUrl;
194+ var prevResultUrl = baseUrl
193195 if (session.prevOffset > 0) {
194- prevResultUrl += '&offset=' + session.prevOffset;
196+ prevResultUrl += '&offset=' + session.prevOffset
195197 }
196- var msgPrev = searchProps.msgPrevResultsTemplate.replace(/\$1/, maxResults);
197- var prevResultHtml = '<a href="' + prevResultUrl + '">' + msgPrev + '</a>';
198- links.push(prevResultHtml);
198+ var msgPrev = searchProps.msgPrevResultsTemplate.replace(/\$1/, maxResults)
199+ var prevResultHtml = '<a href="' + prevResultUrl + '">' + msgPrev + '</a>'
200+ links.push(prevResultHtml)
199201 }
200202 if ('nextOffset' in session) {
201203 var nextResultUrl = baseUrl + '&offset=' + session.nextOffset +
202- '&prev_offset=' + session.offset;
203- var msgMore = searchProps.msgMoreResultsTemplate.replace(/\$1/, maxResults);
204- var moreResultHtml = '<a href="' + nextResultUrl + '">' + msgMore + '</a>';
205- links.push(moreResultHtml);
204+ '&prev_offset=' + session.offset
205+ var msgMore = searchProps.msgMoreResultsTemplate.replace(/\$1/, maxResults)
206+ var moreResultHtml = '<a href="' + nextResultUrl + '">' + msgMore + '</a>'
207+ links.push(moreResultHtml)
206208 }
207209 if (links.length > 0) {
208- return links.join(' ');
210+ return links.join(' ')
209211 }
210- return '';
212+ return ''
211213 }
212- function prepareKanaMap() {
213- if (kanaMap !== null) return;
214+ function prepareKanaMap () {
215+ if (kanaMap !== null) return
214216 if (!String.prototype.normalize) {
215- kanaMap = {};
216- return;
217+ kanaMap = {}
218+ return
217219 }
218- var dakuten = '\uFF9E';
219- var maru = '\uFF9F';
220- var map = {};
220+ var dakuten = '\uFF9E'
221+ var maru = '\uFF9F'
222+ var map = {}
221223 for (var c = 0xFF61; c <= 0xFF9F; c++) {
222- var han = String.fromCharCode(c);
223- var zen = han.normalize('NFKC');
224- map[zen] = han;
225- var hanDaku = han + dakuten;
226- var zenDaku = hanDaku.normalize('NFKC');
224+ var han = String.fromCharCode(c)
225+ var zen = han.normalize('NFKC')
226+ map[zen] = han
227+ var hanDaku = han + dakuten
228+ var zenDaku = hanDaku.normalize('NFKC')
227229 if (zenDaku.length === 1) { // +Handaku-ten OK
228- map[zenDaku] = hanDaku;
230+ map[zenDaku] = hanDaku
229231 }
230- var hanMaru = han + maru;
231- var zenMaru = hanMaru.normalize('NFKC');
232+ var hanMaru = han + maru
233+ var zenMaru = hanMaru.normalize('NFKC')
232234 if (zenMaru.length === 1) { // +Maru OK
233- map[zenMaru] = hanMaru;
235+ map[zenMaru] = hanMaru
234236 }
235237 }
236- kanaMap = map;
238+ kanaMap = map
237239 }
238240 /**
239241 * @param {searchText} searchText
240242 * @type RegExp
241243 */
242- function textToRegex(searchText) {
243- if (!searchText) return null;
244+ function textToRegex (searchText) {
245+ if (!searchText) return null
244246 // 1:Symbol 2:Katakana 3:Hiragana
245- var regRep = /([\\^$.*+?()[\]{}|])|([\u30a1-\u30f6])|([\u3041-\u3096])/g;
246- var replacementFunc = function(m, m1, m2, m3) {
247+ var regRep = /([\\^$.*+?()[\]{}|])|([\u30a1-\u30f6])|([\u3041-\u3096])/g
248+ var replacementFunc = function (m, m1, m2, m3) {
247249 if (m1) {
248250 // Symbol - escape with prior backslach
249- return '\\' + m1;
251+ return '\\' + m1
250252 } else if (m2) {
251253 // Katakana
252254 var r = '(?:' + String.fromCharCode(m2.charCodeAt(0) - 0x60) +
253- '|' + m2;
255+ '|' + m2
254256 if (kanaMap[m2]) {
255- r += '|' + kanaMap[m2];
257+ r += '|' + kanaMap[m2]
256258 }
257- r += ')';
258- return r;
259+ r += ')'
260+ return r
259261 } else if (m3) {
260262 // Hiragana
261- var katakana = String.fromCharCode(m3.charCodeAt(0) + 0x60);
262- var r2 = '(?:' + m3 + '|' + katakana;
263+ var katakana = String.fromCharCode(m3.charCodeAt(0) + 0x60)
264+ var r2 = '(?:' + m3 + '|' + katakana
263265 if (kanaMap[katakana]) {
264- r2 += '|' + kanaMap[katakana];
266+ r2 += '|' + kanaMap[katakana]
265267 }
266- r2 += ')';
267- return r2;
268+ r2 += ')'
269+ return r2
268270 }
269- return m;
270- };
271- var s1 = searchText.replace(/^\s+|\s+$/g, '');
272- if (!s1) return null;
273- var sp = s1.split(/\s+/);
274- var rText = '';
275- prepareKanaMap();
271+ return m
272+ }
273+ var s1 = searchText.replace(/^\s+|\s+$/g, '')
274+ if (!s1) return null
275+ var sp = s1.split(/\s+/)
276+ var rText = ''
277+ prepareKanaMap()
276278 for (var i = 0; i < sp.length; i++) {
277279 if (rText !== '') {
278- rText += '|';
280+ rText += '|'
279281 }
280- var s = sp[i];
282+ var s = sp[i]
281283 if (s.normalize) {
282- s = s.normalize('NFKC');
284+ s = s.normalize('NFKC')
283285 }
284- var s2 = s.replace(regRep, replacementFunc);
285- rText += '(' + s2 + ')';
286+ var s2 = s.replace(regRep, replacementFunc)
287+ rText += '(' + s2 + ')'
286288 }
287- return new RegExp(rText, 'ig');
289+ return new RegExp(rText, 'ig')
288290 }
289291 /**
290292 * @param {string} statusText
291293 */
292- function setSearchStatus(statusText, statusText2) {
293- var statusList = document.querySelectorAll('._plugin_search2_search_status');
294- forEach(statusList, function(statusObj) {
295- var textObj1 = statusObj.querySelector('._plugin_search2_search_status_text1');
296- var textObj2 = statusObj.querySelector('._plugin_search2_search_status_text2');
294+ function setSearchStatus (statusText, statusText2) {
295+ var statusList = document.querySelectorAll('._plugin_search2_search_status')
296+ forEach(statusList, function (statusObj) {
297+ var textObj1 = statusObj.querySelector('._plugin_search2_search_status_text1')
298+ var textObj2 = statusObj.querySelector('._plugin_search2_search_status_text2')
297299 if (textObj1) {
298- var prevText = textObj1.getAttribute('data-text');
300+ var prevText = textObj1.getAttribute('data-text')
299301 if (prevText !== statusText) {
300- textObj1.setAttribute('data-text', statusText);
302+ textObj1.setAttribute('data-text', statusText)
301303 if (statusText.substr(statusText.length - 3) === '...') {
302- var firstHalf = statusText.substr(0, statusText.length - 3);
303- textObj1.textContent = firstHalf;
304- var span = document.createElement('span');
305- span.innerHTML = '<span class="plugin-search2-progress plugin-search2-progress1">.</span>'
306- + '<span class="plugin-search2-progress plugin-search2-progress2">.</span>'
307- + '<span class="plugin-search2-progress plugin-search2-progress3">.</span>';
308- textObj1.appendChild(span);
304+ var firstHalf = statusText.substr(0, statusText.length - 3)
305+ textObj1.textContent = firstHalf
306+ var span = document.createElement('span')
307+ span.innerHTML = '<span class="plugin-search2-progress plugin-search2-progress1">.</span>' +
308+ '<span class="plugin-search2-progress plugin-search2-progress2">.</span>' +
309+ '<span class="plugin-search2-progress plugin-search2-progress3">.</span>'
310+ textObj1.appendChild(span)
309311 } else {
310- textObj1.textContent = statusText;
312+ textObj1.textContent = statusText
311313 }
312314 }
313315 }
314316 if (textObj2) {
315317 if (statusText2) {
316- textObj2.textContent = ' ' + statusText2;
318+ textObj2.textContent = ' ' + statusText2
317319 } else {
318- textObj2.textContent = '';
320+ textObj2.textContent = ''
319321 }
320322 }
321- });
323+ })
322324 }
323325 /**
324326 * @param {string} msgHTML
325327 */
326- function setSearchMessage(msgHTML) {
327- var objList = document.querySelectorAll('._plugin_search2_message');
328- forEach(objList, function(obj) {
329- obj.innerHTML = msgHTML;
330- });
328+ function setSearchMessage (msgHTML) {
329+ var objList = document.querySelectorAll('._plugin_search2_message')
330+ forEach(objList, function (obj) {
331+ obj.innerHTML = msgHTML
332+ })
331333 }
332- function showSecondSearchForm() {
334+ function showSecondSearchForm () {
333335 // Show second search form
334- var div = document.querySelector('._plugin_search2_second_form');
336+ var div = document.querySelector('._plugin_search2_second_form')
335337 if (div) {
336- div.style.display = 'block';
338+ div.style.display = 'block'
337339 }
338340 }
339341 /**
340342 * @param {Element} form
341343 * @type string
342344 */
343- function getSearchBase(form) {
344- var f = form || document.querySelector('._plugin_search2_form');
345- var base = '';
346- forEach(f.querySelectorAll('input[name="base"]'), function(radio) {
347- if (radio.checked) base = radio.value;
348- });
349- return base;
345+ function getSearchBase (form) {
346+ var f = form || document.querySelector('._plugin_search2_form')
347+ var base = ''
348+ forEach(f.querySelectorAll('input[name="base"]'), function (radio) {
349+ if (radio.checked) base = radio.value
350+ })
351+ return base
350352 }
351353 /**
352354 * Decorate found block (for pre innerHTML)
@@ -354,301 +356,301 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
354356 * @param {Object} block
355357 * @param {RegExp} searchRegex
356358 */
357- function decorateFoundBlock(block, searchRegex) {
358- var lines = [];
359+ function decorateFoundBlock (block, searchRegex) {
360+ var lines = []
359361 for (var j = 0; j < block.lines.length; j++) {
360- var line = block.lines[j];
361- var decorated = findAndDecorateText(line, searchRegex);
362+ var line = block.lines[j]
363+ var decorated = findAndDecorateText(line, searchRegex)
362364 if (decorated === null) {
363- lines.push('' + (block.startIndex + j + 1) + ':\t' + escapeHTML(line));
365+ lines.push('' + (block.startIndex + j + 1) + ':\t' + escapeHTML(line))
364366 } else {
365- lines.push('' + (block.startIndex + j + 1) + ':\t' + decorated);
367+ lines.push('' + (block.startIndex + j + 1) + ':\t' + decorated)
366368 }
367369 }
368370 if (block.beyondLimit) {
369- lines.push('...');
371+ lines.push('...')
370372 }
371- return lines.join('\n');
373+ return lines.join('\n')
372374 }
373375 /**
374376 * @param {string} body
375377 * @param {RegExp} searchRegex
376378 */
377- function getSummaryInfo(body, searchRegex) {
378- var lines = body.split('\n');
379- var foundLines = [];
380- var isInAuthorHeader = true;
381- var lastFoundLineIndex = -1 - aroundLines;
382- var lastAddedLineIndex = lastFoundLineIndex;
383- var blocks = [];
384- var lineCount = 0;
385- var currentBlock = null;
379+ function getSummaryInfo (body, searchRegex) {
380+ var lines = body.split('\n')
381+ var foundLines = []
382+ var isInAuthorHeader = true
383+ var lastFoundLineIndex = -1 - aroundLines
384+ var lastAddedLineIndex = lastFoundLineIndex
385+ var blocks = []
386+ var lineCount = 0
387+ var currentBlock = null
386388 for (var index = 0, length = lines.length; index < length; index++) {
387- var line = lines[index];
389+ var line = lines[index]
388390 if (isInAuthorHeader) {
389391 // '#author line is not search target'
390392 if (line.match(/^#author\(/)) {
391393 // Remove this line from search target
392- continue;
394+ continue
393395 } else if (line.match(/^#freeze(\W|$)/)) {
394396 // Still in header
395397 } else {
396398 // Already in body
397- isInAuthorHeader = false;
399+ isInAuthorHeader = false
398400 }
399401 }
400- var match = line.match(searchRegex);
402+ var match = line.match(searchRegex)
401403 if (!match) {
402404 if (index < lastFoundLineIndex + aroundLines + 1) {
403- foundLines.push(lines[index]);
404- lineCount++;
405- lastAddedLineIndex = index;
405+ foundLines.push(lines[index])
406+ lineCount++
407+ lastAddedLineIndex = index
406408 }
407409 } else {
408- var startIndex = Math.max(Math.max(lastAddedLineIndex + 1, index - aroundLines), 0);
410+ var startIndex = Math.max(Math.max(lastAddedLineIndex + 1, index - aroundLines), 0)
409411 if (lastAddedLineIndex + 1 < startIndex) {
410412 // Newly found!
411413 var block = {
412414 startIndex: startIndex,
413415 foundLineIndex: index,
414416 lines: []
415- };
416- currentBlock = block;
417- foundLines = block.lines;
418- blocks.push(block);
417+ }
418+ currentBlock = block
419+ foundLines = block.lines
420+ blocks.push(block)
419421 }
420422 if (lineCount >= maxResultLines) {
421- currentBlock.beyondLimit = true;
422- return blocks;
423+ currentBlock.beyondLimit = true
424+ return blocks
423425 }
424426 for (var i = startIndex; i < index; i++) {
425- foundLines.push(lines[i]);
426- lineCount++;
427+ foundLines.push(lines[i])
428+ lineCount++
427429 }
428- foundLines.push(line);
429- lineCount++;
430- lastFoundLineIndex = lastAddedLineIndex = index;
430+ foundLines.push(line)
431+ lineCount++
432+ lastFoundLineIndex = lastAddedLineIndex = index
431433 }
432434 }
433- return blocks;
435+ return blocks
434436 }
435437 /**
436438 * @param {Date} now
437439 * @param {string} dateText
438440 */
439- function getPassage(now, dateText) {
441+ function getPassage (now, dateText) {
440442 if (!dateText) {
441- return '';
443+ return ''
442444 }
443- var units = [{u: 'm', max: 60}, {u: 'h', max: 24}, {u: 'd', max: 1}];
444- var d = new Date();
445- d.setTime(Date.parse(dateText));
446- var t = (now.getTime() - d.getTime()) / (1000 * 60); // minutes
447- var unit = units[0].u; var card = units[0].max;
445+ var units = [{ u: 'm', max: 60 }, { u: 'h', max: 24 }, { u: 'd', max: 1 }]
446+ var d = new Date()
447+ d.setTime(Date.parse(dateText))
448+ var t = (now.getTime() - d.getTime()) / (1000 * 60) // minutes
449+ var unit = units[0].u; var card = units[0].max
448450 for (var i = 0; i < units.length; i++) {
449- unit = units[i].u; card = units[i].max;
450- if (t < card) break;
451- t = t / card;
451+ unit = units[i].u; card = units[i].max
452+ if (t < card) break
453+ t = t / card
452454 }
453- return '(' + Math.floor(t) + unit + ')';
455+ return '(' + Math.floor(t) + unit + ')'
454456 }
455457 /**
456458 * @param {string} searchText
457459 */
458- function removeSearchOperators(searchText) {
459- var sp = searchText.split(/\s+/);
460+ function removeSearchOperators (searchText) {
461+ var sp = searchText.split(/\s+/)
460462 if (sp.length <= 1) {
461- return searchText;
463+ return searchText
462464 }
463465 for (var i = sp.length - 2; i >= 1; i--) {
464466 if (sp[i] === 'OR') {
465- sp.splice(i, 1);
467+ sp.splice(i, 1)
466468 }
467469 }
468- return sp.join(' ');
470+ return sp.join(' ')
469471 }
470472 /**
471473 * @param {string} pathname
472474 */
473- function getSearchCacheKeyBase(pathname) {
474- return 'path.' + pathname + '.search2.';
475+ function getSearchCacheKeyBase (pathname) {
476+ return 'path.' + pathname + '.search2.'
475477 }
476478 /**
477479 * @param {string} pathname
478480 */
479- function getSearchCacheKeyDateBase(pathname) {
480- var now = new Date();
481- var dateKey = now.getFullYear() + '_0' + (now.getMonth() + 1) + '_0' + now.getDate();
482- dateKey = dateKey.replace(/_\d?(\d\d)/g, '$1');
483- return getSearchCacheKeyBase(pathname) + dateKey + '.';
481+ function getSearchCacheKeyDateBase (pathname) {
482+ var now = new Date()
483+ var dateKey = now.getFullYear() + '_0' + (now.getMonth() + 1) + '_0' + now.getDate()
484+ dateKey = dateKey.replace(/_\d?(\d\d)/g, '$1')
485+ return getSearchCacheKeyBase(pathname) + dateKey + '.'
484486 }
485487 /**
486488 * @param {string} pathname
487489 * @param {string} searchText
488490 * @param {number} offset
489491 */
490- function getSearchCacheKey(pathname, searchText, offset) {
492+ function getSearchCacheKey (pathname, searchText, offset) {
491493 return getSearchCacheKeyDateBase(pathname) + 'offset=' + offset +
492- '.' + searchText;
494+ '.' + searchText
493495 }
494496 /**
495497 * @param {string} pathname
496498 * @param {string} searchText
497499 */
498- function clearSingleCache(pathname, searchText) {
499- if (!window.localStorage) return;
500- var removeTargets = [];
501- var keyBase = getSearchCacheKeyDateBase(pathname);
500+ function clearSingleCache (pathname, searchText) {
501+ if (!window.localStorage) return
502+ var removeTargets = []
503+ var keyBase = getSearchCacheKeyDateBase(pathname)
502504 for (var i = 0, n = localStorage.length; i < n; i++) {
503- var key = localStorage.key(i);
505+ var key = localStorage.key(i)
504506 if (key.substr(0, keyBase.length) === keyBase) {
505507 // Search result Cache
506- var subKey = key.substr(keyBase.length);
507- var m = subKey.match(/^offset=\d+\.(.+)$/);
508+ var subKey = key.substr(keyBase.length)
509+ var m = subKey.match(/^offset=\d+\.(.+)$/)
508510 if (m && m[1] === searchText) {
509- removeTargets.push(key);
511+ removeTargets.push(key)
510512 }
511513 }
512514 }
513- removeTargets.forEach(function(target) {
514- localStorage.removeItem(target);
515- });
515+ removeTargets.forEach(function (target) {
516+ localStorage.removeItem(target)
517+ })
516518 }
517519 /**
518520 * @param {string} body
519521 */
520- function getBodySummary(body) {
521- var lines = body.split('\n');
522- var isInAuthorHeader = true;
523- var summary = [];
522+ function getBodySummary (body) {
523+ var lines = body.split('\n')
524+ var isInAuthorHeader = true
525+ var summary = []
524526 for (var index = 0, length = lines.length; index < length; index++) {
525- var line = lines[index];
527+ var line = lines[index]
526528 if (isInAuthorHeader) {
527529 // '#author line is not search target'
528530 if (line.match(/^#author\(/)) {
529531 // Remove this line from search target
530- continue;
532+ continue
531533 } else if (line.match(/^#freeze(\W|$)/)) {
532- continue;
534+ continue
533535 // Still in header
534536 } else {
535537 // Already in body
536- isInAuthorHeader = false;
538+ isInAuthorHeader = false
537539 }
538540 }
539- line = line.replace(/^\s+|\s+$/g, '');
540- if (line.length === 0) continue; // Empty line
541- if (line.match(/^#\w+/)) continue; // Block-type plugin
542- if (line.match(/^\/\//)) continue; // Comment
541+ line = line.replace(/^\s+|\s+$/g, '')
542+ if (line.length === 0) continue // Empty line
543+ if (line.match(/^#\w+/)) continue // Block-type plugin
544+ if (line.match(/^\/\//)) continue // Comment
543545 if (line.substr(0, 1) === '*') {
544- line = line.replace(/\s*\[#\w+\]$/, ''); // Remove anchor
546+ line = line.replace(/\s*\[#\w+\]$/, '') // Remove anchor
545547 }
546- summary.push(line);
548+ summary.push(line)
547549 if (summary.length >= 10) {
548- continue;
550+ continue
549551 }
550552 }
551- return summary.join(' ').substring(0, 150);
553+ return summary.join(' ').substring(0, 150)
552554 }
553555 /**
554556 * @param {string} q searchText
555557 */
556- function encodeSearchText(q) {
557- var sp = q.split(/\s+/);
558+ function encodeSearchText (q) {
559+ var sp = q.split(/\s+/)
558560 for (var i = 0; i < sp.length; i++) {
559- sp[i] = encodeURIComponent(sp[i]);
561+ sp[i] = encodeURIComponent(sp[i])
560562 }
561- return sp.join('+');
563+ return sp.join('+')
562564 }
563565 /**
564566 * @param {string} q searchText
565567 */
566- function encodeSearchTextForHash(q) {
567- var sp = q.split(/\s+/);
568- return sp.join('+');
568+ function encodeSearchTextForHash (q) {
569+ var sp = q.split(/\s+/)
570+ return sp.join('+')
569571 }
570- function getSearchTextInLocationHash() {
571- var hash = document.location.hash;
572- if (!hash) return '';
573- var q = '';
572+ function getSearchTextInLocationHash () {
573+ var hash = document.location.hash
574+ if (!hash) return ''
575+ var q = ''
574576 if (hash.substr(0, 3) === '#q=') {
575- q = hash.substr(3).replace(/\+/g, ' ');
577+ q = hash.substr(3).replace(/\+/g, ' ')
576578 } else {
577- return '';
579+ return ''
578580 }
579- var decodedQ = decodeURIComponent(q);
581+ var decodedQ = decodeURIComponent(q)
580582 if (q !== decodedQ) {
581- q = decodedQ + ' OR ' + q;
583+ q = decodedQ + ' OR ' + q
582584 }
583- return q;
585+ return q
584586 }
585- function colorSearchTextInBody() {
586- var searchText = getSearchTextInLocationHash();
587- if (!searchText) return;
588- var searchRegex = textToRegex(removeSearchOperators(searchText));
589- if (!searchRegex) return;
587+ function colorSearchTextInBody () {
588+ var searchText = getSearchTextInLocationHash()
589+ if (!searchText) return
590+ var searchRegex = textToRegex(removeSearchOperators(searchText))
591+ if (!searchRegex) return
590592 var ignoreTags = ['INPUT', 'TEXTAREA', 'BUTTON',
591- 'SCRIPT', 'FRAME', 'IFRAME'];
593+ 'SCRIPT', 'FRAME', 'IFRAME']
592594 /**
593595 * @param {Element} element
594596 */
595- function colorSearchText(element) {
596- var decorated = findAndDecorateText(element.nodeValue, searchRegex);
597+ function colorSearchText (element) {
598+ var decorated = findAndDecorateText(element.nodeValue, searchRegex)
597599 if (decorated) {
598- var span = document.createElement('span');
599- span.innerHTML = decorated;
600- element.parentNode.replaceChild(span, element);
600+ var span = document.createElement('span')
601+ span.innerHTML = decorated
602+ element.parentNode.replaceChild(span, element)
601603 }
602604 }
603605 /**
604606 * @param {Element} element
605607 */
606- function walkElement(element) {
607- var e = element.firstChild;
608+ function walkElement (element) {
609+ var e = element.firstChild
608610 while (e) {
609611 if (e.nodeType === 3 && e.nodeValue &&
610612 e.nodeValue.length >= 2 && /\S/.test(e.nodeValue)) {
611- var next = e.nextSibling;
612- colorSearchText(e, searchRegex);
613- e = next;
613+ var next = e.nextSibling
614+ colorSearchText(e, searchRegex)
615+ e = next
614616 } else {
615617 if (e.nodeType === 1 && ignoreTags.indexOf(e.tagName) === -1) {
616- walkElement(e);
618+ walkElement(e)
617619 }
618- e = e.nextSibling;
620+ e = e.nextSibling
619621 }
620622 }
621623 }
622- var target = document.getElementById('body');
623- walkElement(target);
624+ var target = document.getElementById('body')
625+ walkElement(target)
624626 }
625627 /**
626628 * @param {Array<Object>} newResults
627629 * @param {Element} ul
628630 */
629- function removePastResults(newResults, ul) {
630- var removedCount = 0;
631- var nodes = ul.childNodes;
631+ function removePastResults (newResults, ul) {
632+ var removedCount = 0
633+ var nodes = ul.childNodes
632634 for (var i = nodes.length - 1; i >= 0; i--) {
633- var node = nodes[i];
634- if (node.tagName !== 'LI' && node.tagName !== 'DIV') continue;
635- var nodePagename = node.getAttribute('data-pagename');
636- var isRemoveTarget = false;
635+ var node = nodes[i]
636+ if (node.tagName !== 'LI' && node.tagName !== 'DIV') continue
637+ var nodePagename = node.getAttribute('data-pagename')
638+ var isRemoveTarget = false
637639 for (var j = 0, n = newResults.length; j < n; j++) {
638- var r = newResults[j];
640+ var r = newResults[j]
639641 if (r.name === nodePagename) {
640- isRemoveTarget = true;
641- break;
642+ isRemoveTarget = true
643+ break
642644 }
643645 }
644646 if (isRemoveTarget) {
645647 if (node.tagName === 'LI') {
646- removedCount++;
648+ removedCount++
647649 }
648- ul.removeChild(node);
650+ ul.removeChild(node)
649651 }
650652 }
651- return removedCount;
653+ return removedCount
652654 }
653655 /**
654656 * @param {Array<Object>} results
@@ -657,79 +659,79 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
657659 * @param {Element} parentUlElement
658660 * @param {boolean} insertTop
659661 */
660- function addSearchResult(results, searchText, searchRegex, parentUlElement, insertTop) {
661- var props = getSiteProps();
662- var now = new Date();
663- var parentFragment = document.createDocumentFragment();
664- results.forEach(function(val) {
665- var li = document.createElement('li');
666- var hash = '#q=' + encodeSearchTextForHash(searchText);
667- var href = val.url + hash;
668- var decoratedName = findAndDecorateText(val.name, searchRegex);
662+ function addSearchResult (results, searchText, searchRegex, parentUlElement, insertTop) {
663+ var props = getSiteProps()
664+ var now = new Date()
665+ var parentFragment = document.createDocumentFragment()
666+ results.forEach(function (val) {
667+ var li = document.createElement('li')
668+ var hash = '#q=' + encodeSearchTextForHash(searchText)
669+ var href = val.url + hash
670+ var decoratedName = findAndDecorateText(val.name, searchRegex)
669671 if (!decoratedName) {
670- decoratedName = escapeHTML(val.name);
672+ decoratedName = escapeHTML(val.name)
671673 }
672- var updatedAt = val.updatedAt;
673- var passageHtml = '';
674+ var updatedAt = val.updatedAt
675+ var passageHtml = ''
674676 if (props.show_passage) {
675- passageHtml = ' ' + getPassage(now, updatedAt);
677+ passageHtml = ' ' + getPassage(now, updatedAt)
676678 }
677679 var liHtml = '<a href="' + escapeHTML(href) + '">' +
678- decoratedName + '</a>' + passageHtml;
679- li.innerHTML = liHtml;
680- li.setAttribute('data-pagename', val.name);
680+ decoratedName + '</a>' + passageHtml
681+ li.innerHTML = liHtml
682+ li.setAttribute('data-pagename', val.name)
681683 // Page detail div
682- var div = document.createElement('div');
683- div.classList.add('search-result-detail');
684- var head = document.createElement('div');
685- head.classList.add('search-result-page-summary');
686- head.innerHTML = escapeHTML(val.bodySummary);
687- div.appendChild(head);
688- var summaryInfo = val.hitSummary;
684+ var div = document.createElement('div')
685+ div.classList.add('search-result-detail')
686+ var head = document.createElement('div')
687+ head.classList.add('search-result-page-summary')
688+ head.innerHTML = escapeHTML(val.bodySummary)
689+ div.appendChild(head)
690+ var summaryInfo = val.hitSummary
689691 for (var i = 0; i < summaryInfo.length; i++) {
690- var pre = document.createElement('pre');
691- pre.innerHTML = decorateFoundBlock(summaryInfo[i], searchRegex);
692- div.appendChild(pre);
692+ var pre = document.createElement('pre')
693+ pre.innerHTML = decorateFoundBlock(summaryInfo[i], searchRegex)
694+ div.appendChild(pre)
693695 }
694- div.setAttribute('data-pagename', val.name);
696+ div.setAttribute('data-pagename', val.name)
695697 // Add li to ul (parentUlElement)
696- li.appendChild(div);
697- parentFragment.appendChild(li);
698- });
698+ li.appendChild(div)
699+ parentFragment.appendChild(li)
700+ })
699701 if (insertTop && parentUlElement.firstChild) {
700- parentUlElement.insertBefore(parentFragment, parentUlElement.firstChild);
702+ parentUlElement.insertBefore(parentFragment, parentUlElement.firstChild)
701703 } else {
702- parentUlElement.appendChild(parentFragment);
704+ parentUlElement.appendChild(parentFragment)
703705 }
704706 }
705- function removeCachedResultsBase(keepTodayCache) {
706- var props = getSiteProps();
707- if (!props || !props.base_uri_pathname) return;
708- var keyPrefix = getSearchCacheKeyDateBase(props.base_uri_pathname);
709- var keyBase = getSearchCacheKeyBase(props.base_uri_pathname);
710- var removeTargets = [];
707+ function removeCachedResultsBase (keepTodayCache) {
708+ var props = getSiteProps()
709+ if (!props || !props.base_uri_pathname) return
710+ var keyPrefix = getSearchCacheKeyDateBase(props.base_uri_pathname)
711+ var keyBase = getSearchCacheKeyBase(props.base_uri_pathname)
712+ var removeTargets = []
711713 for (var i = 0, n = localStorage.length; i < n; i++) {
712- var key = localStorage.key(i);
714+ var key = localStorage.key(i)
713715 if (key.substr(0, keyBase.length) === keyBase) {
714716 // Search result Cache
715717 if (keepTodayCache) {
716718 if (key.substr(0, keyPrefix.length) !== keyPrefix) {
717- removeTargets.push(key);
719+ removeTargets.push(key)
718720 }
719721 } else {
720- removeTargets.push(key);
722+ removeTargets.push(key)
721723 }
722724 }
723725 }
724- removeTargets.forEach(function(target) {
725- localStorage.removeItem(target);
726- });
726+ removeTargets.forEach(function (target) {
727+ localStorage.removeItem(target)
728+ })
727729 }
728- function removeCachedResults() {
729- removeCachedResultsBase(true);
730+ function removeCachedResults () {
731+ removeCachedResultsBase(true)
730732 }
731- function removeAllCachedResults() {
732- removeCachedResultsBase(false);
733+ function removeAllCachedResults () {
734+ removeCachedResultsBase(false)
733735 }
734736 /**
735737 * @param {Object} obj
@@ -737,119 +739,119 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
737739 * @param {string} searchText
738740 * @param {number} prevTimestamp
739741 */
740- function showResult(obj, session, searchText, prevTimestamp) {
741- var props = getSiteProps();
742- var searchRegex = textToRegex(removeSearchOperators(searchText));
743- var ul = document.querySelector('#_plugin_search2_result-list');
744- if (!ul) return;
742+ function showResult (obj, session, searchText, prevTimestamp) {
743+ var props = getSiteProps()
744+ var searchRegex = textToRegex(removeSearchOperators(searchText))
745+ var ul = document.querySelector('#_plugin_search2_result-list')
746+ if (!ul) return
745747 if (obj.start_index === 0 && !prevTimestamp) {
746- ul.innerHTML = '';
748+ ul.innerHTML = ''
747749 }
748- var searchDone = obj.search_done;
749- if (!session.scanPageCount) session.scanPageCount = 0;
750- if (!session.readPageCount) session.readPageCount = 0;
751- if (!session.hitPageCount) session.hitPageCount = 0;
752- var prevHitPageCount = session.hitPageCount;
753- session.hitPageCount += obj.results.length;
750+ var searchDone = obj.search_done
751+ if (!session.scanPageCount) session.scanPageCount = 0
752+ if (!session.readPageCount) session.readPageCount = 0
753+ if (!session.hitPageCount) session.hitPageCount = 0
754+ var prevHitPageCount = session.hitPageCount
755+ session.hitPageCount += obj.results.length
754756 if (!prevTimestamp) {
755- session.scanPageCount += obj.scan_page_count;
756- session.readPageCount += obj.read_page_count;
757- session.pageCount = obj.page_count;
757+ session.scanPageCount += obj.scan_page_count
758+ session.readPageCount += obj.read_page_count
759+ session.pageCount = obj.page_count
758760 }
759- session.searchStartTime = obj.search_start_time;
760- session.authUser = obj.auth_user;
761+ session.searchStartTime = obj.search_start_time
762+ session.authUser = obj.auth_user
761763 if (prevHitPageCount === 0 && session.hitPageCount > 0) {
762- showSecondSearchForm();
764+ showSecondSearchForm()
763765 }
764- var results = obj.results;
765- var cachedResults = [];
766- results.forEach(function(val) {
767- var cache = {};
768- cache.name = val.name;
769- cache.url = val.url;
770- cache.updatedAt = val.updated_at;
771- cache.updatedTime = val.updated_time;
772- cache.bodySummary = getBodySummary(val.body);
773- cache.hitSummary = getSummaryInfo(val.body, searchRegex);
774- cachedResults.push(cache);
775- });
766+ var results = obj.results
767+ var cachedResults = []
768+ results.forEach(function (val) {
769+ var cache = {}
770+ cache.name = val.name
771+ cache.url = val.url
772+ cache.updatedAt = val.updated_at
773+ cache.updatedTime = val.updated_time
774+ cache.bodySummary = getBodySummary(val.body)
775+ cache.hitSummary = getSummaryInfo(val.body, searchRegex)
776+ cachedResults.push(cache)
777+ })
776778 if (prevTimestamp) {
777- var removedCount = removePastResults(cachedResults, ul);
778- session.hitPageCount -= removedCount;
779+ var removedCount = removePastResults(cachedResults, ul)
780+ session.hitPageCount -= removedCount
779781 }
780- var msg = getSearchResultMessage(session, searchText, searchRegex, !searchDone);
781- setSearchMessage(msg);
782+ var msg = getSearchResultMessage(session, searchText, searchRegex, !searchDone)
783+ setSearchMessage(msg)
782784 if (prevTimestamp) {
783- setSearchStatus(searchProps.searchingMsg);
785+ setSearchStatus(searchProps.searchingMsg)
784786 } else {
785787 setSearchStatus(searchProps.searchingMsg,
786- getSearchProgress(session));
788+ getSearchProgress(session))
787789 }
788790 if (searchDone) {
789- var singlePageResult = session.offset === 0 && !session.nextOffset;
790- var progress = getSearchProgress(session);
791- setTimeout(function() {
791+ var singlePageResult = session.offset === 0 && !session.nextOffset
792+ var progress = getSearchProgress(session)
793+ setTimeout(function () {
792794 if (singlePageResult) {
793- setSearchStatus('');
795+ setSearchStatus('')
794796 } else {
795- setSearchStatus(searchProps.showingResultMsg, progress);
797+ setSearchStatus(searchProps.showingResultMsg, progress)
796798 }
797- }, 2000);
799+ }, 2000)
798800 }
799801 if (session.results) {
800802 if (prevTimestamp) {
801- var newResult = [].concat(cachedResults);
802- Array.prototype.push.apply(newResult, session.results);
803- session.results = newResult;
803+ var newResult = [].concat(cachedResults)
804+ Array.prototype.push.apply(newResult, session.results)
805+ session.results = newResult
804806 } else {
805- Array.prototype.push.apply(session.results, cachedResults);
807+ Array.prototype.push.apply(session.results, cachedResults)
806808 }
807809 } else {
808- session.results = cachedResults;
810+ session.results = cachedResults
809811 }
810- addSearchResult(cachedResults, searchText, searchRegex, ul, prevTimestamp);
811- var maxResults = searchProps.maxResults;
812+ addSearchResult(cachedResults, searchText, searchRegex, ul, prevTimestamp)
813+ var maxResults = searchProps.maxResults
812814 if (searchDone) {
813- session.searchText = searchText;
814- var prevOffset = searchProps.prevOffset;
815+ session.searchText = searchText
816+ var prevOffset = searchProps.prevOffset
815817 if (prevOffset) {
816- session.prevOffset = parseInt(prevOffset, 10);
818+ session.prevOffset = parseInt(prevOffset, 10)
817819 }
818- var json = JSON.stringify(session);
819- var cacheKey = getSearchCacheKey(props.base_uri_pathname, searchText, session.offset);
820+ var json = JSON.stringify(session)
821+ var cacheKey = getSearchCacheKey(props.base_uri_pathname, searchText, session.offset)
820822 if (window.localStorage) {
821823 try {
822- localStorage[cacheKey] = json;
824+ localStorage[cacheKey] = json
823825 } catch (e) {
824826 // QuotaExceededError "exceeded the quota."
825- console.log(e);
826- removeAllCachedResults();
827+ console.log(e)
828+ removeAllCachedResults()
827829 }
828830 }
829831 if ('prevOffset' in session || 'nextOffset' in session) {
830- setSearchMessage(msg + ' ' + getOffsetLinks(session, maxResults));
832+ setSearchMessage(msg + ' ' + getOffsetLinks(session, maxResults))
831833 }
832834 }
833835 if (!searchDone && obj.next_start_index) {
834836 if (session.results.length >= maxResults) {
835837 // Save results
836- session.nextOffset = obj.next_start_index;
837- var prevOffset2 = searchProps.prevOffset;
838+ session.nextOffset = obj.next_start_index
839+ var prevOffset2 = searchProps.prevOffset
838840 if (prevOffset2) {
839- session.prevOffset = parseInt(prevOffset2, 10);
841+ session.prevOffset = parseInt(prevOffset2, 10)
840842 }
841- var key = getSearchCacheKey(props.base_uri_pathname, searchText, session.offset);
842- localStorage[key] = JSON.stringify(session);
843+ var key = getSearchCacheKey(props.base_uri_pathname, searchText, session.offset)
844+ localStorage[key] = JSON.stringify(session)
843845 // Stop API calling
844- setSearchMessage(msg + ' ' + getOffsetLinks(session, maxResults));
846+ setSearchMessage(msg + ' ' + getOffsetLinks(session, maxResults))
845847 setSearchStatus(searchProps.showingResultMsg,
846- getSearchProgress(session));
848+ getSearchProgress(session))
847849 } else {
848- setTimeout(function() {
850+ setTimeout(function () {
849851 doSearch(searchText, // eslint-disable-line no-use-before-define
850852 session, obj.next_start_index,
851- obj.search_start_time);
852- }, searchProps.searchInterval);
853+ obj.search_start_time)
854+ }, searchProps.searchInterval)
853855 }
854856 }
855857 }
@@ -858,41 +860,41 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
858860 * @param {string} base
859861 * @param {number} offset
860862 */
861- function showCachedResult(searchText, base, offset) {
862- var props = getSiteProps();
863- var searchRegex = textToRegex(removeSearchOperators(searchText));
864- var ul = document.querySelector('#_plugin_search2_result-list');
865- if (!ul) return null;
866- var searchCacheKey = getSearchCacheKey(props.base_uri_pathname, searchText, offset);
867- var cache1 = localStorage[searchCacheKey];
863+ function showCachedResult (searchText, base, offset) {
864+ var props = getSiteProps()
865+ var searchRegex = textToRegex(removeSearchOperators(searchText))
866+ var ul = document.querySelector('#_plugin_search2_result-list')
867+ if (!ul) return null
868+ var searchCacheKey = getSearchCacheKey(props.base_uri_pathname, searchText, offset)
869+ var cache1 = localStorage[searchCacheKey]
868870 if (!cache1) {
869- return null;
871+ return null
870872 }
871- var session = JSON.parse(cache1);
872- if (!session) return null;
873+ var session = JSON.parse(cache1)
874+ if (!session) return null
873875 if (base !== session.base) {
874- return null;
876+ return null
875877 }
876- var user = searchProps.user;
878+ var user = searchProps.user
877879 if (user !== session.authUser) {
878- return null;
880+ return null
879881 }
880882 if (session.hitPageCount > 0) {
881- showSecondSearchForm();
883+ showSecondSearchForm()
882884 }
883- var msg = getSearchResultMessage(session, searchText, searchRegex, false);
884- setSearchMessage(msg);
885- addSearchResult(session.results, searchText, searchRegex, ul);
886- var maxResults = searchProps.maxResults;
885+ var msg = getSearchResultMessage(session, searchText, searchRegex, false)
886+ setSearchMessage(msg)
887+ addSearchResult(session.results, searchText, searchRegex, ul)
888+ var maxResults = searchProps.maxResults
887889 if ('prevOffset' in session || 'nextOffset' in session) {
888- var moreResultHtml = getOffsetLinks(session, maxResults);
889- setSearchMessage(msg + ' ' + moreResultHtml);
890- var progress = getSearchProgress(session);
891- setSearchStatus(searchProps.showingResultMsg, progress);
890+ var moreResultHtml = getOffsetLinks(session, maxResults)
891+ setSearchMessage(msg + ' ' + moreResultHtml)
892+ var progress = getSearchProgress(session)
893+ setSearchStatus(searchProps.showingResultMsg, progress)
892894 } else {
893- setSearchStatus('');
895+ setSearchStatus('')
894896 }
895- return session;
897+ return session
896898 }
897899 /**
898900 * @param {string} searchText
@@ -901,183 +903,183 @@ window.addEventListener && window.addEventListener('DOMContentLoaded', function(
901903 * @param {number} searchStartTime
902904 * @param {number} prevTimestamp
903905 */
904- function doSearch(searchText, session, startIndex, searchStartTime, prevTimestamp) {
905- var props = getSiteProps();
906- var baseUrl = './';
906+ function doSearch (searchText, session, startIndex, searchStartTime, prevTimestamp) {
907+ var props = getSiteProps()
908+ var baseUrl = './'
907909 if (props.base_uri_pathname) {
908- baseUrl = props.base_uri_pathname;
910+ baseUrl = props.base_uri_pathname
909911 }
910- var url = baseUrl + '?cmd=search2&action=query';
911- url += '&encode_hint=' + encodeURIComponent('\u3077');
912+ var url = baseUrl + '?cmd=search2&action=query'
913+ url += '&encode_hint=' + encodeURIComponent('\u3077')
912914 if (searchText) {
913- url += '&q=' + encodeURIComponent(searchText);
915+ url += '&q=' + encodeURIComponent(searchText)
914916 }
915917 if (session.base) {
916- url += '&base=' + encodeURIComponent(session.base);
918+ url += '&base=' + encodeURIComponent(session.base)
917919 }
918920 if (prevTimestamp) {
919- url += '&modified_since=' + prevTimestamp;
921+ url += '&modified_since=' + prevTimestamp
920922 } else {
921- url += '&start=' + startIndex;
923+ url += '&start=' + startIndex
922924 if (searchStartTime) {
923- url += '&search_start_time=' + encodeURIComponent(searchStartTime);
925+ url += '&search_start_time=' + encodeURIComponent(searchStartTime)
924926 }
925927 if (!('offset' in session)) {
926- session.offset = startIndex;
928+ session.offset = startIndex
927929 }
928930 }
929- fetch(url, {credentials: 'same-origin'}
930- ).then(function(response) {
931+ fetch(url, { credentials: 'same-origin' }
932+ ).then(function (response) {
931933 if (response.ok) {
932- return response.json();
934+ return response.json()
933935 }
934936 throw new Error(response.status + ': ' +
935- response.statusText + ' on ' + url);
936- }).then(function(obj) {
937- showResult(obj, session, searchText, prevTimestamp);
938- })['catch'](function(err) { // eslint-disable-line dot-notation
937+ response.statusText + ' on ' + url)
938+ }).then(function (obj) {
939+ showResult(obj, session, searchText, prevTimestamp)
940+ })['catch'](function (err) { // eslint-disable-line dot-notation
939941 if (window.console && console.log) {
940- console.log(err);
941- console.log('Error! Please check JavaScript console\n' + JSON.stringify(err) + '|' + err);
942+ console.log(err)
943+ console.log('Error! Please check JavaScript console\n' + JSON.stringify(err) + '|' + err)
942944 }
943- setSearchStatus(searchProps.errorMsg);
944- });
945+ setSearchStatus(searchProps.errorMsg)
946+ })
945947 }
946- function hookSearch2() {
947- var form = document.querySelector('form');
948+ function hookSearch2 () {
949+ var form = document.querySelector('form')
948950 if (form && form.q) {
949- var q = form.q;
951+ var q = form.q
950952 if (q.value === '') {
951- q.focus();
953+ q.focus()
952954 }
953955 }
954956 }
955- function removeEncodeHint() {
957+ function removeEncodeHint () {
956958 // Remove 'encode_hint' if site charset is UTF-8
957- var props = getSiteProps();
958- if (!props.is_utf8) return;
959- var forms = document.querySelectorAll('form');
960- forEach(forms, function(form) {
959+ var props = getSiteProps()
960+ if (!props.is_utf8) return
961+ var forms = document.querySelectorAll('form')
962+ forEach(forms, function (form) {
961963 if (form.cmd && form.cmd.value === 'search2') {
962964 if (form.encode_hint && (typeof form.encode_hint.removeAttribute === 'function')) {
963- form.encode_hint.removeAttribute('name');
965+ form.encode_hint.removeAttribute('name')
964966 }
965967 }
966- });
968+ })
967969 }
968- function kickFirstSearch() {
969- var form = document.querySelector('._plugin_search2_form');
970- var searchText = form && form.q;
971- if (!searchText) return;
970+ function kickFirstSearch () {
971+ var form = document.querySelector('._plugin_search2_form')
972+ var searchText = form && form.q
973+ if (!searchText) return
972974 if (searchText && searchText.value) {
973- var offset = searchProps.offset;
974- var base = getSearchBase(form);
975- var prevSession = showCachedResult(searchText.value, base, offset);
975+ var offset = searchProps.offset
976+ var base = getSearchBase(form)
977+ var prevSession = showCachedResult(searchText.value, base, offset)
976978 if (prevSession) {
977979 // Display Cache results, then search only modified pages
978980 if (!('offset' in prevSession) || prevSession.offset === 0) {
979981 doSearch(searchText.value, prevSession, offset, null,
980- prevSession.searchStartTime);
982+ prevSession.searchStartTime)
981983 } else {
982984 // Show search results
983985 }
984986 } else {
985- doSearch(searchText.value, {base: base, offset: offset}, offset, null);
987+ doSearch(searchText.value, { base: base, offset: offset }, offset, null)
986988 }
987- removeCachedResults();
989+ removeCachedResults()
988990 }
989991 }
990- function replaceSearchWithSearch2() {
991- forEach(document.querySelectorAll('form'), function(f) {
992- function onAndRadioClick() {
993- var sp = removeSearchOperators(f.word.value).split(/\s+/);
994- var newText = sp.join(' ');
992+ function replaceSearchWithSearch2 () {
993+ forEach(document.querySelectorAll('form'), function (f) {
994+ function onAndRadioClick () {
995+ var sp = removeSearchOperators(f.word.value).split(/\s+/)
996+ var newText = sp.join(' ')
995997 if (f.word.value !== newText) {
996- f.word.value = newText;
998+ f.word.value = newText
997999 }
9981000 }
999- function onOrRadioClick() {
1000- var sp = removeSearchOperators(f.word.value).split(/\s+/);
1001- var newText = sp.join(' OR ');
1001+ function onOrRadioClick () {
1002+ var sp = removeSearchOperators(f.word.value).split(/\s+/)
1003+ var newText = sp.join(' OR ')
10021004 if (f.word.value !== newText) {
1003- f.word.value = newText;
1005+ f.word.value = newText
10041006 }
10051007 }
10061008 if (f.action.match(/cmd=search$/)) {
1007- f.addEventListener('submit', function(e) {
1008- var q = e.target.word.value;
1009- var base = '';
1010- forEach(f.querySelectorAll('input[name="base"]'), function(radio) {
1011- if (radio.checked) base = radio.value;
1012- });
1013- var props = getSiteProps();
1014- var loc = document.location;
1015- var baseUri = loc.protocol + '//' + loc.host + loc.pathname;
1009+ f.addEventListener('submit', function (e) {
1010+ var q = e.target.word.value
1011+ var base = ''
1012+ forEach(f.querySelectorAll('input[name="base"]'), function (radio) {
1013+ if (radio.checked) base = radio.value
1014+ })
1015+ var props = getSiteProps()
1016+ var loc = document.location
1017+ var baseUri = loc.protocol + '//' + loc.host + loc.pathname
10161018 if (props.base_uri_pathname) {
1017- baseUri = props.base_uri_pathname;
1019+ baseUri = props.base_uri_pathname
10181020 }
10191021 var url = baseUri + '?' +
10201022 (props.is_utf8 ? '' : 'encode_hint=' +
10211023 encodeURIComponent('\u3077') + '&') +
10221024 'cmd=search2' +
10231025 '&q=' + encodeSearchText(q) +
1024- (base ? '&base=' + encodeURIComponent(base) : '');
1025- e.preventDefault();
1026- setTimeout(function() {
1027- window.location.href = url;
1028- }, 1);
1029- return false;
1030- });
1031- var radios = f.querySelectorAll('input[type="radio"][name="type"]');
1032- forEach(radios, function(radio) {
1026+ (base ? '&base=' + encodeURIComponent(base) : '')
1027+ e.preventDefault()
1028+ setTimeout(function () {
1029+ window.location.href = url
1030+ }, 1)
1031+ return false
1032+ })
1033+ var radios = f.querySelectorAll('input[type="radio"][name="type"]')
1034+ forEach(radios, function (radio) {
10331035 if (radio.value === 'AND') {
1034- radio.addEventListener('click', onAndRadioClick);
1036+ radio.addEventListener('click', onAndRadioClick)
10351037 } else if (radio.value === 'OR') {
1036- radio.addEventListener('click', onOrRadioClick);
1038+ radio.addEventListener('click', onOrRadioClick)
10371039 }
1038- });
1040+ })
10391041 } else if (f.cmd && f.cmd.value === 'search2') {
1040- f.addEventListener('submit', function() {
1041- var newSearchText = f.q.value;
1042- var prevSearchText = f.q.getAttribute('data-original-q');
1042+ f.addEventListener('submit', function () {
1043+ var newSearchText = f.q.value
1044+ var prevSearchText = f.q.getAttribute('data-original-q')
10431045 if (newSearchText === prevSearchText) {
10441046 // Clear resultCache to search same text again
1045- var props = getSiteProps();
1046- clearSingleCache(props.base_uri_pathname, prevSearchText);
1047+ var props = getSiteProps()
1048+ clearSingleCache(props.base_uri_pathname, prevSearchText)
10471049 }
1048- });
1050+ })
10491051 }
1050- });
1052+ })
10511053 }
1052- function showNoSupportMessage() {
1053- var pList = document.getElementsByClassName('_plugin_search2_nosupport_message');
1054+ function showNoSupportMessage () {
1055+ var pList = document.getElementsByClassName('_plugin_search2_nosupport_message')
10541056 for (var i = 0; i < pList.length; i++) {
1055- var p = pList[i];
1056- p.style.display = 'block';
1057+ var p = pList[i]
1058+ p.style.display = 'block'
10571059 }
10581060 }
1059- function isEnabledFetchFunctions() {
1061+ function isEnabledFetchFunctions () {
10601062 if (window.fetch && document.querySelector && window.JSON) {
1061- return true;
1063+ return true
10621064 }
1063- return false;
1065+ return false
10641066 }
1065- function isEnableServerFunctions() {
1066- var props = getSiteProps();
1067- if (props.json_enabled) return true;
1068- return false;
1067+ function isEnableServerFunctions () {
1068+ var props = getSiteProps()
1069+ if (props.json_enabled) return true
1070+ return false
10691071 }
1070- prepareSearchProps();
1071- colorSearchTextInBody();
1072+ prepareSearchProps()
1073+ colorSearchTextInBody()
10721074 if (!isEnabledFetchFunctions()) {
1073- showNoSupportMessage();
1074- return;
1075+ showNoSupportMessage()
1076+ return
10751077 }
1076- if (!isEnableServerFunctions()) return;
1077- replaceSearchWithSearch2();
1078- hookSearch2();
1079- removeEncodeHint();
1080- kickFirstSearch();
1078+ if (!isEnableServerFunctions()) return
1079+ replaceSearchWithSearch2()
1080+ hookSearch2()
1081+ removeEncodeHint()
1082+ kickFirstSearch()
10811083 }
1082- enableSearch2();
1083-});
1084+ enableSearch2()
1085+})
Show on old repository browser