mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-12-22 21:00:23 +01:00
parent
feff447409
commit
e3861e67b4
@ -37,6 +37,10 @@
|
|||||||
"message": "Bitte warten...",
|
"message": "Bitte warten...",
|
||||||
"description": ""
|
"description": ""
|
||||||
},
|
},
|
||||||
|
"search": {
|
||||||
|
"message": "Suchen",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
|
||||||
"input": {
|
"input": {
|
||||||
"message": "Eingabe",
|
"message": "Eingabe",
|
||||||
|
@ -37,6 +37,10 @@
|
|||||||
"message": "Please wait...",
|
"message": "Please wait...",
|
||||||
"description": ""
|
"description": ""
|
||||||
},
|
},
|
||||||
|
"search": {
|
||||||
|
"message": "Search",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
|
||||||
"input": {
|
"input": {
|
||||||
"message": "input",
|
"message": "input",
|
||||||
|
51
lib/search.js
Normal file
51
lib/search.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
(function(){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var scope;
|
||||||
|
if ((typeof exports) !== "undefined"){
|
||||||
|
scope = exports;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.scope.search = {};
|
||||||
|
scope = window.scope.search;
|
||||||
|
}
|
||||||
|
|
||||||
|
const texts = [];
|
||||||
|
|
||||||
|
scope.register = function(text, content){
|
||||||
|
texts.push({text: text.toLowerCase(), content});
|
||||||
|
};
|
||||||
|
scope.search = function(search){
|
||||||
|
search = search.toLowerCase();
|
||||||
|
const result = [];
|
||||||
|
texts.forEach(function(text){
|
||||||
|
if (text.text.indexOf(search) !== -1){
|
||||||
|
result.push(text.content);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
const searchListeners = [];
|
||||||
|
scope.init = function(){
|
||||||
|
const node = document.createElement("input");
|
||||||
|
node.id = "search";
|
||||||
|
node.placeholder = browser.i18n.getMessage("search");
|
||||||
|
window.setTimeout(() => node.focus(), 1);
|
||||||
|
let lastResults = [];
|
||||||
|
node.addEventListener("input", function(){
|
||||||
|
const search = this.value;
|
||||||
|
const results = search? scope.search(search): [];
|
||||||
|
searchListeners.forEach(function(callback){
|
||||||
|
callback({search, results, lastResults});
|
||||||
|
});
|
||||||
|
lastResults = results;
|
||||||
|
});
|
||||||
|
return node;
|
||||||
|
};
|
||||||
|
scope.on = function(callback){
|
||||||
|
searchListeners.push(callback);
|
||||||
|
};
|
||||||
|
}());
|
53
lib/settingStrings.js
Normal file
53
lib/settingStrings.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
(function(){
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var scope;
|
||||||
|
if ((typeof exports) !== "undefined"){
|
||||||
|
scope = exports;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
scope = {};
|
||||||
|
window.scope.settingStrings = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
scope.getMessages = function(settingDefinition){
|
||||||
|
const messages = [
|
||||||
|
settingDefinition.name + "_title",
|
||||||
|
settingDefinition.name + "_description",
|
||||||
|
];
|
||||||
|
if (settingDefinition.urlSpecific){
|
||||||
|
messages.push(settingDefinition.name + "_urlSpecific");
|
||||||
|
}
|
||||||
|
if (settingDefinition.options){
|
||||||
|
settingDefinition.options.forEach(function(option){
|
||||||
|
messages.push(settingDefinition.name + "_option." + option);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return messages;
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.getStrings = function(settingDefinition){
|
||||||
|
const strings = [];
|
||||||
|
function addString(string){
|
||||||
|
if ((typeof string) === "string" && string.trim()){
|
||||||
|
strings.push(string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addString(settingDefinition.name);
|
||||||
|
if (settingDefinition.options){
|
||||||
|
settingDefinition.options.forEach(function(option){
|
||||||
|
addString(option);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
scope.getMessages(settingDefinition).forEach(function(message){
|
||||||
|
addString(browser.i18n.getMessage(message));
|
||||||
|
});
|
||||||
|
|
||||||
|
return strings;
|
||||||
|
};
|
||||||
|
}());
|
@ -28,7 +28,7 @@ header .bookmarkNotice .dontShowOptionsOnUpdate input {
|
|||||||
border-spacing: 0;
|
border-spacing: 0;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
.settings.displayDescriptions {
|
.settings {
|
||||||
table-layout: fixed;
|
table-layout: fixed;
|
||||||
}
|
}
|
||||||
.settings * {
|
.settings * {
|
||||||
@ -214,4 +214,18 @@ td.hideColumn {
|
|||||||
text-align: right;
|
text-align: right;
|
||||||
color: gray;
|
color: gray;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#search {
|
||||||
|
box-sizing: border-box;
|
||||||
|
width: 100%;
|
||||||
|
border: none;
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
.searching .settingRow {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.searching .settingRow.found {
|
||||||
|
display: table-row;
|
||||||
}
|
}
|
@ -10,7 +10,9 @@
|
|||||||
<script src="../lib/logging.js"></script>
|
<script src="../lib/logging.js"></script>
|
||||||
<script src="../lib/settingDefinitions.js"></script>
|
<script src="../lib/settingDefinitions.js"></script>
|
||||||
<script src="../lib/settingContainers.js"></script>
|
<script src="../lib/settingContainers.js"></script>
|
||||||
|
<script src="../lib/settingStrings.js"></script>
|
||||||
<script src="../lib/settings.js"></script>
|
<script src="../lib/settings.js"></script>
|
||||||
|
<script src="../lib/search.js"></script>
|
||||||
<script src="optionsGui.js"></script>
|
<script src="optionsGui.js"></script>
|
||||||
<script src="settingsDisplay.js"></script>
|
<script src="settingsDisplay.js"></script>
|
||||||
<script src="options.js"></script>
|
<script src="options.js"></script>
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
const optionsGui = require("./optionsGui");
|
const optionsGui = require("./optionsGui");
|
||||||
const settings = require("./settings");
|
const settings = require("./settings");
|
||||||
const settingsDisplay = require("./settingsDisplay");
|
const settingsDisplay = require("./settingsDisplay");
|
||||||
|
const search = require("./search");
|
||||||
|
const settingStrings = require("./settingStrings");
|
||||||
|
|
||||||
var callbacks = {
|
var callbacks = {
|
||||||
showReleaseNotes: function(){
|
showReleaseNotes: function(){
|
||||||
@ -168,7 +170,26 @@
|
|||||||
document.body.appendChild(table);
|
document.body.appendChild(table);
|
||||||
|
|
||||||
const displayHidden = settings.getDefinition(settingsDisplay.displayHidden);
|
const displayHidden = settings.getDefinition(settingsDisplay.displayHidden);
|
||||||
table.appendChild(optionsGui.createThead(displayHidden));
|
table.appendChild(
|
||||||
|
optionsGui.createThead(
|
||||||
|
displayHidden,
|
||||||
|
search.init()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
search.on(function({search, results, lastResults}){
|
||||||
|
lastResults.forEach(function(node){
|
||||||
|
node.classList.remove("found");
|
||||||
|
});
|
||||||
|
if (search){
|
||||||
|
document.body.classList.add("searching");
|
||||||
|
results.forEach(function(node){
|
||||||
|
node.classList.add("found");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.body.classList.remove("searching");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let lastSection = null;
|
let lastSection = null;
|
||||||
let addSection = function addSection(name){
|
let addSection = function addSection(name){
|
||||||
@ -192,10 +213,16 @@
|
|||||||
body.appendChild(row);
|
body.appendChild(row);
|
||||||
},
|
},
|
||||||
updateDisplay: function(){
|
updateDisplay: function(){
|
||||||
|
const searchMode = document.body.classList.contains("searching");
|
||||||
var anyVisible = false;
|
var anyVisible = false;
|
||||||
rows.forEach(function(row){
|
rows.forEach(function(row){
|
||||||
var isHidden = row.classList.contains("hidden");
|
var isHidden = row.classList.contains("hidden");
|
||||||
if (!isHidden){
|
if (!isHidden){
|
||||||
|
if (searchMode){
|
||||||
|
if (!row.classList.contains("found")){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (anyVisible){
|
if (anyVisible){
|
||||||
row.classList.remove("firstVisible");
|
row.classList.remove("firstVisible");
|
||||||
}
|
}
|
||||||
@ -208,6 +235,8 @@
|
|||||||
body.classList[anyVisible? "remove": "add"]("hidden");
|
body.classList[anyVisible? "remove": "add"]("hidden");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
search.on(function(){section.updateDisplay();});
|
||||||
lastSection = section;
|
lastSection = section;
|
||||||
};
|
};
|
||||||
addSection();
|
addSection();
|
||||||
@ -306,6 +335,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var row = optionsGui.createSettingRow(setting);
|
var row = optionsGui.createSettingRow(setting);
|
||||||
|
settingStrings.getStrings(setting).forEach(function(string){
|
||||||
|
search.register(string, row);
|
||||||
|
});
|
||||||
let section = lastSection;
|
let section = lastSection;
|
||||||
section.addRow(row);
|
section.addRow(row);
|
||||||
if (!display.displayDependencies){
|
if (!display.displayDependencies){
|
||||||
|
@ -375,7 +375,7 @@
|
|||||||
|
|
||||||
scope.createSettingRow = createSettingRow;
|
scope.createSettingRow = createSettingRow;
|
||||||
|
|
||||||
function createThead(displayHidden){
|
function createThead(displayHidden, restContent){
|
||||||
const tHead = document.createElement("thead");
|
const tHead = document.createElement("thead");
|
||||||
const headRow = document.createElement("tr");
|
const headRow = document.createElement("tr");
|
||||||
const hideHeadCell = document.createElement("td");
|
const hideHeadCell = document.createElement("td");
|
||||||
@ -393,6 +393,9 @@
|
|||||||
|
|
||||||
const restHeadCell = document.createElement("td");
|
const restHeadCell = document.createElement("td");
|
||||||
restHeadCell.colSpan = 2;
|
restHeadCell.colSpan = 2;
|
||||||
|
if (restContent){
|
||||||
|
restHeadCell.appendChild(restContent);
|
||||||
|
}
|
||||||
headRow.appendChild(restHeadCell);
|
headRow.appendChild(restHeadCell);
|
||||||
tHead.appendChild(headRow);
|
tHead.appendChild(headRow);
|
||||||
return tHead;
|
return tHead;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user