Load emoticons through public API.
This commit is contained in:
parent
4aa2b4cb1a
commit
3dff2e250f
4 changed files with 328 additions and 214 deletions
498
package-lock.json
generated
498
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -22,6 +22,21 @@ var FutamiCommon = function(vars) {
|
|||
xhr.setRequestHeader('Cache-Control', 'no-cache');
|
||||
xhr.send();
|
||||
},
|
||||
getApiJson: function(path, onload, onerror, noCache) {
|
||||
if(typeof onload !== 'function')
|
||||
throw 'onload must be specified';
|
||||
|
||||
var xhr = new XMLHttpRequest;
|
||||
xhr.onload = function() {
|
||||
onload(JSON.parse(xhr.responseText));
|
||||
};
|
||||
if(typeof onerror === 'function')
|
||||
xhr.onerror = function() { onerror(); };
|
||||
xhr.open('GET', get('api') + path);
|
||||
if(noCache)
|
||||
xhr.setRequestHeader('Cache-Control', 'no-cache');
|
||||
xhr.send();
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -188,9 +188,9 @@ var AmiContext = function(title, auth, loading) {
|
|||
return;
|
||||
}
|
||||
|
||||
futami.getJson('emotes', function(emotes) {
|
||||
futami.getApiJson('/v1/emotes', function(emotes) {
|
||||
if(Array.isArray(emotes))
|
||||
emoticons.loadLegacy(emotes);
|
||||
emoticons.load(emotes);
|
||||
chat.emoticonList.render(emoticons);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -49,44 +49,31 @@ var AmiEmoticons = function() {
|
|||
};
|
||||
|
||||
var add = function(emote) {
|
||||
emotes.push(emote);
|
||||
};
|
||||
if(emote.url.substring(0, 6) === 'https:')
|
||||
emote.url = emote.url.substring(6);
|
||||
|
||||
var addLegacy = function(emoteOld) {
|
||||
var emote = {
|
||||
url: emoteOld.Image.replace('https:', ''),
|
||||
minRank: emoteOld.Hierarchy,
|
||||
strings: [],
|
||||
};
|
||||
for(var i = 0; i < emoteOld.Text.length; ++i)
|
||||
emote.strings.push(emoteOld.Text[i].slice(1, -1));
|
||||
add(emote);
|
||||
emotes.push(emote);
|
||||
};
|
||||
|
||||
return {
|
||||
clear: clear,
|
||||
add: add,
|
||||
addLegacy: addLegacy,
|
||||
load: function(batch) {
|
||||
for(var i in batch)
|
||||
add(batch[i]);
|
||||
},
|
||||
loadLegacy: function(batch) {
|
||||
for(var i in batch)
|
||||
addLegacy(batch[i]);
|
||||
},
|
||||
forEach: function(minRank, callback) {
|
||||
if(minRank === undefined) minRank = 0;
|
||||
for(var i in emotes) {
|
||||
var emote = emotes[i];
|
||||
if(emote.minRank <= minRank)
|
||||
if(!emote.min_rank || emote.min_rank <= minRank)
|
||||
callback(emote);
|
||||
}
|
||||
},
|
||||
any: function(minRank) {
|
||||
if(minRank === undefined) minRank = 0;
|
||||
for(var i in emotes)
|
||||
if(emotes[i].minRank <= minRank)
|
||||
if(!emotes[i].min_rank || emotes[i].min_rank <= minRank)
|
||||
return true;
|
||||
return false;
|
||||
},
|
||||
|
@ -94,7 +81,7 @@ var AmiEmoticons = function() {
|
|||
var found = [];
|
||||
for(var i in emotes) {
|
||||
var emote = emotes[i];
|
||||
if(emote.minRank <= minRank) {
|
||||
if(!emote.min_rank || emote.min_rank <= minRank) {
|
||||
for(var j in emote.strings) {
|
||||
var string = emote.strings[j];
|
||||
if(string.indexOf(name) === 0) {
|
||||
|
|
Loading…
Reference in a new issue