update USO style install counter

the USO site reports style installation unconditionally even if you uninstall it in 5 seconds, but we do it only if the style isn't uninstalled during 60 seconds while the popup is open - thus we exclude previewing of styles, which is a very popular use case
This commit is contained in:
tophf 2017-12-14 01:46:32 +03:00
parent f048649e58
commit 1283e85a8e

View File

@ -36,6 +36,10 @@ window.addEventListener('showStyles:done', function _() {
// Millisecs to wait before fetching .JSON for next search result.
const DELAY_BEFORE_SEARCHING_STYLES = 0;
// update USO style install counter
// if the style isn't uninstalled in the popup
const PINGBACK_DELAY = 60e3;
const BLANK_PIXEL_DATA = 'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAA' +
'C1HAwCAAAAC0lEQVR42mOcXQ8AAbsBHLLDr5MAAAAASUVORK5CYII=';
@ -131,6 +135,7 @@ window.addEventListener('showStyles:done', function _() {
if (result) {
result.installed = false;
result.installedStyleId = -1;
BG.clearTimeout(result.pingbackTimer);
renderActionButtons($('#' + RESULT_ID_PREFIX + result.id));
}
});
@ -558,6 +563,7 @@ window.addEventListener('showStyles:done', function _() {
fetchStyleSettings(result),
])
.then(([style, settings]) => {
pingback(result);
// show a 'config-on-homepage' icon in the popup
style.updateUrl += settings.length ? '?' : '';
// show a 'style installed' tooltip in the manager
@ -585,6 +591,11 @@ window.addEventListener('showStyles:done', function _() {
}
}
function pingback(result) {
result.pingbackTimer = BG.setTimeout(BG.download, PINGBACK_DELAY,
BASE_URL + '/styles/install/' + result.id + '?source=stylish-ch');
}
function saveScrollPosition(entry) {
dom.scrollPosition = entry.getBoundingClientRect().top;
dom.scrollPositionElement = entry;