mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-12-12 12:57:56 +03:00
caa622ffec
Adds matching for URIs to the search bar, using the format <scheme>://<host>/<path> Searching by URI scheme is also supported: "http://" (returns all bridges with 'http' scheme) "https://" (returns all bridges with 'https' scheme) The following examples are equivalent and will return both of the Facebook bridges (FacebookBridge and FB2Bridge): "https://www.facebook.com/facebook" "https://www.facebook.com/facebook?..." "https://www.facebook.com" "http://www.facebook.com" "https://facebook.com" "http://facebook.com" "facebook.com" "facebook" Notice: When the URI scheme is omitted, the search algorithm falls back to regex matching. Searching for "www.facebook.com" doesn't work, as it is missing the schema and doesn't match via regex! Omitting the 'www.', however, does work. This was a design decision for some bridges specify their URI with and others without 'www.' A search term can still be specified in the browser URL using parameter 'q' => '?q=searchterm'. References #743
60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
function search() {
|
|
|
|
var searchTerm = document.getElementById('searchfield').value;
|
|
var searchableElements = document.getElementsByTagName('section');
|
|
|
|
var regexMatch = new RegExp(searchTerm, 'i');
|
|
|
|
// Attempt to create anchor from search term (will default to 'localhost' on failure)
|
|
var searchTermUri = document.createElement('a');
|
|
searchTermUri.href = searchTerm;
|
|
|
|
if(searchTermUri.hostname == 'localhost') {
|
|
searchTermUri = null;
|
|
} else {
|
|
|
|
// Ignore "www."
|
|
if(searchTermUri.hostname.indexOf('www.') === 0) {
|
|
searchTermUri.hostname = searchTermUri.hostname.substr(4);
|
|
}
|
|
|
|
}
|
|
|
|
for(var i = 0; i < searchableElements.length; i++) {
|
|
|
|
var textValue = searchableElements[i].getAttribute('data-ref');
|
|
var anchors = searchableElements[i].getElementsByTagName('a');
|
|
|
|
if(anchors != null && anchors.length > 0) {
|
|
|
|
var uriValue = anchors[0]; // First anchor is bridge URI
|
|
|
|
// Ignore "www."
|
|
if(uriValue.hostname.indexOf('www.') === 0) {
|
|
uriValue.hostname = uriValue.hostname.substr(4);
|
|
}
|
|
|
|
}
|
|
|
|
if(textValue != null || uriValue != null) {
|
|
|
|
if(textValue.match(regexMatch) != null ||
|
|
uriValue.hostname.match(regexMatch) ||
|
|
searchTermUri != null &&
|
|
uriValue.hostname != 'localhost' && (
|
|
uriValue.href.match(regexMatch) != null ||
|
|
uriValue.hostname == searchTermUri.hostname)) {
|
|
|
|
searchableElements[i].style.display = 'block';
|
|
|
|
} else {
|
|
|
|
searchableElements[i].style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|