|
|
@ -5,6 +5,7 @@ |
|
|
|
// NOTE: window.find is not standard API
|
|
|
|
// NOTE: window.find is not standard API
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/find
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/find
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import messages from 'shared/messages'; |
|
|
|
import actions from 'content/actions'; |
|
|
|
import actions from 'content/actions'; |
|
|
|
import * as consoleFrames from '../console-frames'; |
|
|
|
import * as consoleFrames from '../console-frames'; |
|
|
|
|
|
|
|
|
|
|
@ -14,6 +15,13 @@ const postPatternNotFound = (pattern) => { |
|
|
|
'Pattern not found: ' + pattern); |
|
|
|
'Pattern not found: ' + pattern); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const postPatternFound = (pattern) => { |
|
|
|
|
|
|
|
return consoleFrames.postInfo( |
|
|
|
|
|
|
|
window.document, |
|
|
|
|
|
|
|
'Pattern found: ' + pattern, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const find = (string, backwards) => { |
|
|
|
const find = (string, backwards) => { |
|
|
|
let caseSensitive = false; |
|
|
|
let caseSensitive = false; |
|
|
|
let wrapScan = true; |
|
|
|
let wrapScan = true; |
|
|
@ -24,32 +32,49 @@ const find = (string, backwards) => { |
|
|
|
return window.find(string, caseSensitive, backwards, wrapScan); |
|
|
|
return window.find(string, caseSensitive, backwards, wrapScan); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const findNext = (keyword, reset, backwards) => { |
|
|
|
const findNext = (currentKeyword, reset, backwards) => { |
|
|
|
if (reset) { |
|
|
|
if (reset) { |
|
|
|
window.getSelection().removeAllRanges(); |
|
|
|
window.getSelection().removeAllRanges(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let found = find(keyword, backwards); |
|
|
|
let promise = Promise.resolve(currentKeyword); |
|
|
|
if (!found) { |
|
|
|
if (currentKeyword) { |
|
|
|
window.getSelection().removeAllRanges(); |
|
|
|
browser.runtime.sendMessage({ |
|
|
|
found = find(keyword, backwards); |
|
|
|
type: messages.FIND_SET_KEYWORD, |
|
|
|
|
|
|
|
keyword: currentKeyword, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
promise = browser.runtime.sendMessage({ |
|
|
|
|
|
|
|
type: messages.FIND_GET_KEYWORD, |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!found) { |
|
|
|
|
|
|
|
postPatternNotFound(keyword); |
|
|
|
return promise.then((keyword) => { |
|
|
|
} |
|
|
|
let found = find(keyword, backwards); |
|
|
|
return { |
|
|
|
if (!found) { |
|
|
|
type: actions.FIND_SET_KEYWORD, |
|
|
|
window.getSelection().removeAllRanges(); |
|
|
|
keyword, |
|
|
|
found = find(keyword, backwards); |
|
|
|
found, |
|
|
|
} |
|
|
|
}; |
|
|
|
if (found) { |
|
|
|
|
|
|
|
postPatternFound(keyword); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
postPatternNotFound(keyword); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
type: actions.FIND_SET_KEYWORD, |
|
|
|
|
|
|
|
keyword, |
|
|
|
|
|
|
|
found, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const next = (keyword, reset) => { |
|
|
|
const next = (currentKeyword, reset) => { |
|
|
|
return findNext(keyword, reset, false); |
|
|
|
return findNext(currentKeyword, reset, false); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const prev = (keyword, reset) => { |
|
|
|
const prev = (currentKeyword, reset) => { |
|
|
|
return findNext(keyword, reset, true); |
|
|
|
return findNext(currentKeyword, reset, true); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export { next, prev }; |
|
|
|
export { next, prev }; |
|
|
|