Skip to content

Instantly share code, notes, and snippets.

@garrus
Created January 22, 2015 17:08
Show Gist options
  • Save garrus/196f4b5c49c86e943310 to your computer and use it in GitHub Desktop.
Save garrus/196f4b5c49c86e943310 to your computer and use it in GitHub Desktop.
(function(){
var fetchSectionDataApi = "http://news.oppomobile.com/api/news/index/focus";
var updateTitleApi = "http://news.oppomobile.com/M/News/entry/updateTitle/id/__ID__";
var clearSectionCacheApi = "http://news.oppomobile.com/M/News/apiData/rebuildCacheBySection/id/3";
var safeCheckCounter = 0;
checkWrongTitle();
function checkWrongTitle(){
$.get(fetchSectionDataApi + "?_t=" + Date.now(), function(json){
if (json.ret == 0) {
var news = json.data.article[0];
var hasImage = [];
news.subNews.map(function(subNews){
console.debug(subNews.title);
if (/<img (.+?)>/.test(subNews.title)) {
hasImage.push({
id: subNews.id,
title: subNews.title.replace(/<img (.+?)>/, '')
});
}
});
if (hasImage.length) {
hasImage.map(function(info){
$.post(updateTitleApi.replace("__ID__", info.id), {title: info.title}, function(json){
if (json.ret == 0) {
log("Title cleaned for news#" + info.id + ", title=" + info.title);
} else {
console.error(json.msg);
}
}, "json");
});
setTimeout(function(){
$.post(clearSectionCacheApi);
}, 3000);
safeCheckCounter = 0;
setTimeout(checkWrongTitle, 9.5 * 60000);
} else {
safeCheckCounter++;
if (safeCheckCounter > 6) safeCheckCounter = 6;
setTimeout(checkWrongTitle, 20000 * safeCheckCounter);
log("Checking is safe. Schedule check in " + (20 * safeCheckCounter) + " seconds.");
}
}
}, "json");
}
function log(message){
var date = new Date();
var time = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
var content = "[" + time + "] " + message;
console.log(content);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment