mirror of
https://github.com/writeas/paste-chrome
synced 2018-07-20 11:45:21 +00:00
Add ability to delete posts after syncing
T117
This commit is contained in:
parent
92d640d176
commit
b64a5d9517
18
context.js
18
context.js
@ -69,6 +69,24 @@ chrome.runtime.onMessageExternal.addListener(function(req, sender, callback) {
|
|||||||
callback("pong");
|
callback("pong");
|
||||||
} else if (req.msg == "posts") {
|
} else if (req.msg == "posts") {
|
||||||
callback(JSON.parse(H.get('posts', '[]')));
|
callback(JSON.parse(H.get('posts', '[]')));
|
||||||
|
} else if (req.msg == "deletePosts" && req.data && req.data.length > 0) {
|
||||||
|
// Delete all posts listed in req.data, an array of post IDs.
|
||||||
|
var postsModified = false;
|
||||||
|
var posts = JSON.parse(H.get('posts', '[]'));
|
||||||
|
|
||||||
|
for (var i=0; i<req.data.length; i++) {
|
||||||
|
for (var j=0; j<posts.length; j++) {
|
||||||
|
if (posts[j].id === req.data[i]) {
|
||||||
|
console.log("Removing post " + req.data[i]);
|
||||||
|
posts.splice(j, 1);
|
||||||
|
postsModified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (postsModified) {
|
||||||
|
H.set('posts', JSON.stringify(posts));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user