peertubeify-estensione-fire.../background.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-08-10 11:22:42 +02:00
/* This file is part of PeerTubeify.
2018-08-10 01:56:04 +02:00
*
2018-08-10 11:22:42 +02:00
* PeerTubeify is free software: you can redistribute it and/or modify
2018-08-10 01:56:04 +02:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
2018-08-10 11:22:42 +02:00
* PeerTubeify is distributed in the hope that it will be useful,
2018-08-10 01:56:04 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2018-08-10 11:22:42 +02:00
* along with PeerTubeify. If not, see <https://www.gnu.org/licenses/>.
2018-08-10 01:56:04 +02:00
*/
function search(query) {
return new Promise((resolve, reject) => {
fetch(`https://peertube.video/api/v1/videos/search?search=${encodeURIComponent(query)}`)
.then(res => res.json())
.then(function(data) {
if (data.total > 0) {
resolve(data.data[0]);
} else {
reject(new Error('No results.'))
}
})
});
};
browser.runtime.onMessage.addListener(function(message, sender) {
return search(message.query)
});