Skip to content

Commit

Permalink
避免將無效的網址傳進圖庫造成崩潰
Browse files Browse the repository at this point in the history
  • Loading branch information
lackneets committed Jun 19, 2016
1 parent 68076c8 commit 91fc7d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 7 additions & 2 deletions background.js
Expand Up @@ -45,7 +45,7 @@
if(request.loadEmotions){

loadEmotions(function(emotions){
console.log('sendResponse(emotions)', emotions);
console.log('sendResponse(emotions)');
sendResponse(emotions);
});
}
Expand All @@ -69,7 +69,12 @@
});

function saveEmotion(url, keyword, callback){
var urlMatch = url.match(/plurk\.com\/([0-9a-zA-Z]+)/);
loadEmotions(function(emotions){
if(!(urlMatch && urlMatch[1])){
console.warn('Emoticon not saved, invalid url', url);
return callback && callback(emotions);
}
var hash_id = url.match(/plurk\.com\/([0-9a-zA-Z]+)/)[1];
emotion = {keyword: keyword, url: url, hash_id: hash_id};
emotions.push(emotion);
Expand Down Expand Up @@ -210,7 +215,7 @@
//相同名稱衝突
if(emotions[e].keyword == stored_emotions[s].keyword){ //conflict
exist = true;
console.log('remove conflict: ', emotions[e].keyword, emotions[e].hash_id, stored_emotions[s].keyword, stored_emotions[s].hash_id);
// console.log('remove conflict: ', emotions[e].keyword, emotions[e].hash_id, stored_emotions[s].keyword, stored_emotions[s].hash_id);
if(emotions[e].hash_id == stored_emotions[s].hash_id){ // 完全符合
stored_emotions[s] = emotions[e];
//if(type == "onlineMerge") stored_emotions[s].alive = true; // 標記為在線上
Expand Down
11 changes: 6 additions & 5 deletions extension/uploadHandler.js
Expand Up @@ -5,9 +5,12 @@
$(document).on('click', '#emo-panel-add', function(){
newEmoticonKeyword = $('#emo-panel-kw-editor').val() || __("表情");
if(newEmoticonKeyword && newEmoticonKeyword.replace(/\s*/, '') != ""){
gallery.storage.saveEmotion($('#emo-panel-emo').attr('src'), newEmoticonKeyword, function(emotions){
console.info('「'+newEmoticonKeyword+'」已儲存到噗浪卡卡圖庫');
});
var src = $('#emo-panel-emo').attr('src');
if(String(src).match(/plurk\.com\/([0-9a-zA-Z]+)/)){
gallery.storage.saveEmotion($('#emo-panel-emo').attr('src'), newEmoticonKeyword, function(emotions){
console.info('「'+newEmoticonKeyword+'」已儲存到噗浪卡卡圖庫');
});
}
}
});

Expand All @@ -21,6 +24,4 @@
}, 1500);
});



})();

0 comments on commit 91fc7d3

Please sign in to comment.