1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-05-25 09:13:27 +02:00

Added search field to browser page popup

Fixes #268
This commit is contained in:
kkapsner 2018-10-09 12:59:53 +02:00
parent f5699a1bf3
commit eff86ce4ed
6 changed files with 40 additions and 7 deletions

View File

@ -47,3 +47,9 @@ div {
mask-size: 100%; mask-size: 100%;
display: inline-block; display: inline-block;
} }
.search {
box-sizing: border-box;
padding-left: calc(0.5em + 19px + 0.25em);
cursor: initial;
}

View File

@ -79,5 +79,21 @@
actionButton.addEventListener("click", action.action); actionButton.addEventListener("click", action.action);
actions.appendChild(actionButton); actions.appendChild(actionButton);
}); });
var search = document.createElement("input");
search.placeholder = browser.i18n.getMessage("search");
search.className = "search action";
actions.appendChild(search);
search.focus();
search.addEventListener("keyup", function(event){
if ([10, 13].indexOf(event.keyCode) !== -1){
window.open(browser.extension.getURL(
"options/options.html" +
"?search=" +
encodeURIComponent(this.value)
));
}
});
}); });
}()); }());

View File

@ -148,7 +148,7 @@
!browser.pageAction.openPopup !browser.pageAction.openPopup
){ ){
browser.tabs.create({ browser.tabs.create({
url: browser.extension.getURL("options/options.html?" + reason) url: browser.extension.getURL("options/options.html?notice=" + reason)
}); });
} }
} }

View File

@ -57,13 +57,16 @@
window.setTimeout(() => node.focus(), 1); window.setTimeout(() => node.focus(), 1);
let lastResults = []; let lastResults = [];
node.addEventListener("input", function(){ node.addEventListener("input", function(){
this.search();
});
node.search = function(){
const search = this.value; const search = this.value;
const results = search? scope.search(search): []; const results = search? scope.search(search): [];
searchListeners.forEach(function(callback){ searchListeners.forEach(function(callback){
callback({search, results, lastResults}); callback({search, results, lastResults});
}); });
lastResults = results; lastResults = results;
}); };
return node; return node;
}; };
scope.on = function(callback){ scope.on = function(callback){

View File

@ -12,6 +12,7 @@
const settingsDisplay = require("./settingsDisplay"); const settingsDisplay = require("./settingsDisplay");
const search = require("./search"); const search = require("./search");
const settingStrings = require("./settingStrings"); const settingStrings = require("./settingStrings");
const searchParameters = new URLSearchParams(window.location.search);
var callbacks = { var callbacks = {
showReleaseNotes: function(){ showReleaseNotes: function(){
@ -118,8 +119,8 @@
introduction.textContent = browser.i18n.getMessage("optionsIntroduction"); introduction.textContent = browser.i18n.getMessage("optionsIntroduction");
head.appendChild(introduction); head.appendChild(introduction);
if (window.location.search){ if (searchParameters.has("notice")){
let noticeName = window.location.search.substr(1).trim() + "Notice"; let noticeName = searchParameters.get("notice") + "Notice";
let notice = browser.i18n.getMessage(noticeName); let notice = browser.i18n.getMessage(noticeName);
if (notice){ if (notice){
let bookmarkingNotice = document.createElement("div"); let bookmarkingNotice = document.createElement("div");
@ -174,16 +175,20 @@
document.body.appendChild(table); document.body.appendChild(table);
const displayHidden = settings.getDefinition(settingsDisplay.displayHidden); const displayHidden = settings.getDefinition(settingsDisplay.displayHidden);
const searchInput = search.init();
table.appendChild( table.appendChild(
optionsGui.createThead( optionsGui.createThead(
displayHidden, displayHidden,
search.init() searchInput
) )
); );
const searchOnly = window.location.search === "?searchOnly"; const searchOnly = searchParameters.has("searchOnly");
if (searchOnly){ if (searchOnly){
document.body.classList.add("searching"); document.body.classList.add("searching");
} }
if (searchParameters.has("search")){
searchInput.value = searchParameters.get("search");
}
search.on(function({search, results, lastResults}){ search.on(function({search, results, lastResults}){
lastResults.forEach(function(node){ lastResults.forEach(function(node){
node.classList.remove("found"); node.classList.remove("found");
@ -412,4 +417,6 @@
} }
}); });
}); });
searchInput.search();
}()); }());

View File

@ -4,6 +4,7 @@ Version 0.5.5:
new features: new features:
- added settings sanitation page - added settings sanitation page
- added search field to browser action popup
fixes: fixes:
- Google images did not work for some users - Google images did not work for some users