Created
January 22, 2015 17:08
-
-
Save garrus/196f4b5c49c86e943310 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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