Hi,
I add .done and .fail, but with .fail was error in script. So I only add .done. I check on consol, no errors.
manifest.json
{
“name”: “My Bookmarks”,
“version”: “1.1”,
“description”: “A browser action with a popup dump of all bookmarks, including search, add, edit and delete.”,
“permissions”: [
“bookmarks”,
“://.twitch.tv/*”
],
“browser_action”: {
“default_title”: “My Bookmarks”,
“default_icon”: “icon.png”,
“default_popup”: “background.html”
},
“manifest_version”: 2,
“content_scripts”: [
{
“js”: [“jquery-3.2.1.min.js”, “background.js”]
}
],
“content_security_policy”: “script-src ‘self’ https://ajax.googleapis.com; object-src ‘self’”
}
When I create like this base on Chrome api
{
“name”: “My Bookmarks”,
“version”: “1.1”,
“description”: “A browser action with a popup dump of all bookmarks, including search, add, edit and delete.”,
“permissions”: [
“bookmarks”,
“://.twitch.tv/*”
],
“browser_action”: {
“default_title”: “My Bookmarks”,
“default_icon”: “icon.png”,
“default_popup”: “background.html”
},
“manifest_version”: 2,
“background”: [
{
“scripts”: [“jquery-3.2.1.min.js”, “background.js”]
}
],
“content_security_policy”: “script-src ‘self’ https://ajax.googleapis.com; object-src ‘self’”
}
Effect is the same as above.
background.js
var clientID = ‘key-API’;
var baseKraken = ‘https://api.twitch.tv/kraken/’;
function getKrakenAPI(endpoint, data, method) {
return $.ajax({
url: baseKraken + endpoint,
method: method,
data: data,
dataType: ‘json’,
headers: {
‘Client-ID’: clientID,
Accept: ‘application/vnd.twitchtv.v5+json’
}
});
}
getKrakenAPI(
‘streams’,
{
channel: [ ‘ivelios_christopher’, ‘esl_sc2’]
}
)
.done(function(data) {
if(data._total > 0) {
chrome.browserAction.setBadgeText( { text: “On” } );
}
else {
chrome.browserAction.setBadgeText( { text: “Off” } );
}
});
Effect is, that “On” not display, but “Off” display when you click on icon in browser even if some streamers are online.